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
|
|
|
|
|
|
|
use BookStack\Entities\Models\Book;
|
|
|
|
use BookStack\Entities\Models\Bookshelf;
|
|
|
|
use BookStack\Entities\Models\Chapter;
|
|
|
|
use BookStack\Entities\Models\Page;
|
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
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return array{pages: int, chapters: int, books: int, shelves: int}
|
|
|
|
*/
|
|
|
|
public function run(User $user): array
|
|
|
|
{
|
|
|
|
$createdBy = ['created_by' => $user->id];
|
|
|
|
|
|
|
|
return [
|
|
|
|
'pages' => Page::visible()->where($createdBy)->count(),
|
|
|
|
'chapters' => Chapter::visible()->where($createdBy)->count(),
|
|
|
|
'books' => Book::visible()->where($createdBy)->count(),
|
|
|
|
'shelves' => Bookshelf::visible()->where($createdBy)->count(),
|
|
|
|
];
|
|
|
|
}
|
2022-02-13 21:16:43 +08:00
|
|
|
}
|