]> BookStack Code Mirror - bookstack/blob - app/Auth/Queries/UserContentCounts.php
b8d99be148be82d8d129bb011558d6f63f35c013
[bookstack] / app / Auth / Queries / UserContentCounts.php
1 <?php
2
3 namespace BookStack\Auth\Queries;
4
5 use BookStack\Auth\User;
6 use BookStack\Entities\Models\Book;
7 use BookStack\Entities\Models\Bookshelf;
8 use BookStack\Entities\Models\Chapter;
9 use BookStack\Entities\Models\Page;
10
11 /**
12  * Get asset created counts for the given user.
13  */
14 class UserContentCounts
15 {
16     /**
17      * @return array{pages: int, chapters: int, books: int, shelves: int}
18      */
19     public function run(User $user): array
20     {
21         $createdBy = ['created_by' => $user->id];
22
23         return [
24             'pages'    => Page::visible()->where($createdBy)->count(),
25             'chapters' => Chapter::visible()->where($createdBy)->count(),
26             'books'    => Book::visible()->where($createdBy)->count(),
27             'shelves'  => Bookshelf::visible()->where($createdBy)->count(),
28         ];
29     }
30 }