BookStack/app/Users/Queries/UserContentCounts.php

34 lines
907 B
PHP
Raw Normal View History

2022-02-13 07:56:26 -05:00
<?php
2023-05-17 12:56:55 -04:00
namespace BookStack\Users\Queries;
2022-02-13 07:56:26 -05:00
use BookStack\Entities\Queries\EntityQueries;
2023-05-17 12:56:55 -04:00
use BookStack\Users\Models\User;
2022-02-13 07:56:26 -05:00
/**
* Get asset created counts for the given user.
*/
class UserContentCounts
{
public function __construct(
protected EntityQueries $queries,
) {
}
2022-02-13 07:56:26 -05:00
/**
* @return array{pages: int, chapters: int, books: int, shelves: int}
*/
public function run(User $user): array
{
$createdBy = ['created_by' => $user->id];
return [
'pages' => $this->queries->pages->visibleForList()->where($createdBy)->count(),
'chapters' => $this->queries->chapters->visibleForList()->where($createdBy)->count(),
'books' => $this->queries->books->visibleForList()->where($createdBy)->count(),
'shelves' => $this->queries->shelves->visibleForList()->where($createdBy)->count(),
2022-02-13 07:56:26 -05:00
];
}
}