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
|
|
|
|
2024-02-07 11:37:36 -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
|
|
|
|
{
|
2024-02-07 11:37:36 -05:00
|
|
|
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 [
|
2024-02-07 11:37:36 -05:00
|
|
|
'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
|
|
|
];
|
|
|
|
}
|
2022-02-13 08:16:43 -05:00
|
|
|
}
|