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
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the recently created content for the provided user.
|
|
|
|
*/
|
|
|
|
class UserRecentlyCreatedContent
|
|
|
|
{
|
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: Collection, chapters: Collection, books: Collection, shelves: Collection}
|
|
|
|
*/
|
|
|
|
public function run(User $user, int $count): array
|
|
|
|
{
|
|
|
|
$query = function (Builder $query) use ($user, $count) {
|
|
|
|
return $query->orderBy('created_at', 'desc')
|
|
|
|
->where('created_by', '=', $user->id)
|
|
|
|
->take($count)
|
|
|
|
->get();
|
|
|
|
};
|
|
|
|
|
|
|
|
return [
|
2024-02-08 00:37:36 +08:00
|
|
|
'pages' => $query($this->queries->pages->visibleForList()->where('draft', '=', false)),
|
|
|
|
'chapters' => $query($this->queries->chapters->visibleForList()),
|
|
|
|
'books' => $query($this->queries->books->visibleForList()),
|
|
|
|
'shelves' => $query($this->queries->shelves->visibleForList()),
|
2022-02-13 20:56:26 +08:00
|
|
|
];
|
|
|
|
}
|
2022-02-13 21:16:43 +08:00
|
|
|
}
|