BookStack/app/Users/Queries/UserContentCounts.php

34 lines
907 B
PHP
Raw Normal View History

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\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
{
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 [
'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
];
}
}