2022-02-13 20:56:26 +08:00
|
|
|
<?php
|
|
|
|
|
2023-05-18 00:56:55 +08:00
|
|
|
namespace BookStack\Users\Queries;
|
2022-02-13 20:56:26 +08:00
|
|
|
|
2024-02-08 00:37:36 +08:00
|
|
|
use BookStack\Entities\Queries\EntityQueries;
|
2023-05-18 00:56:55 +08:00
|
|
|
use BookStack\Users\Models\User;
|
2022-02-13 20:56:26 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get asset created counts for the given user.
|
|
|
|
*/
|
|
|
|
class UserContentCounts
|
|
|
|
{
|
2024-02-08 00:37:36 +08:00
|
|
|
public function __construct(
|
|
|
|
protected EntityQueries $queries,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-13 20:56:26 +08: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-08 00:37:36 +08: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 20:56:26 +08:00
|
|
|
];
|
|
|
|
}
|
2022-02-13 21:16:43 +08:00
|
|
|
}
|