2022-02-13 13:56:26 +01:00
|
|
|
<?php
|
|
|
|
|
2023-05-17 18:56:55 +02:00
|
|
|
namespace BookStack\Users\Queries;
|
2022-02-13 13:56:26 +01:00
|
|
|
|
|
|
|
use BookStack\Entities\Models\Book;
|
|
|
|
use BookStack\Entities\Models\Bookshelf;
|
|
|
|
use BookStack\Entities\Models\Chapter;
|
|
|
|
use BookStack\Entities\Models\Page;
|
2023-05-17 18:56:55 +02:00
|
|
|
use BookStack\Users\Models\User;
|
2022-02-13 13:56:26 +01:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the recently created content for the provided user.
|
|
|
|
*/
|
|
|
|
class UserRecentlyCreatedContent
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @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 [
|
|
|
|
'pages' => $query(Page::visible()->where('draft', '=', false)),
|
|
|
|
'chapters' => $query(Chapter::visible()),
|
|
|
|
'books' => $query(Book::visible()),
|
|
|
|
'shelves' => $query(Bookshelf::visible()),
|
|
|
|
];
|
|
|
|
}
|
2022-02-13 14:16:43 +01:00
|
|
|
}
|