]> BookStack Code Mirror - bookstack/blob - app/Users/Queries/UserContentCounts.php
Tests: Updated comment test to account for new editor usage
[bookstack] / app / Users / Queries / UserContentCounts.php
1 <?php
2
3 namespace BookStack\Users\Queries;
4
5 use BookStack\Entities\Queries\EntityQueries;
6 use BookStack\Users\Models\User;
7
8 /**
9  * Get asset created counts for the given user.
10  */
11 class UserContentCounts
12 {
13     public function __construct(
14         protected EntityQueries $queries,
15     ) {
16     }
17
18
19     /**
20      * @return array{pages: int, chapters: int, books: int, shelves: int}
21      */
22     public function run(User $user): array
23     {
24         $createdBy = ['created_by' => $user->id];
25
26         return [
27             'pages'    => $this->queries->pages->visibleForList()->where($createdBy)->count(),
28             'chapters' => $this->queries->chapters->visibleForList()->where($createdBy)->count(),
29             'books'    => $this->queries->books->visibleForList()->where($createdBy)->count(),
30             'shelves'  => $this->queries->shelves->visibleForList()->where($createdBy)->count(),
31         ];
32     }
33 }