mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-28 13:12:05 +00:00
![Dan Brown](/assets/img/avatar_default.png)
Also removed lesser used function, that was mostly a duplicate of an existing function, and only used for search.
34 lines
814 B
PHP
34 lines
814 B
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Queries;
|
|
|
|
use BookStack\Actions\View;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class RecentlyViewed extends EntityQuery
|
|
{
|
|
public function run(int $count, int $page): Collection
|
|
{
|
|
$user = user();
|
|
if ($user === null || $user->isDefault()) {
|
|
return collect();
|
|
}
|
|
|
|
$query = $this->permissionService()->restrictEntityRelationQuery(
|
|
View::query(),
|
|
'views',
|
|
'viewable_id',
|
|
'viewable_type'
|
|
)
|
|
->orderBy('views.updated_at', 'desc')
|
|
->where('user_id', '=', user()->id);
|
|
|
|
return $query->with('viewable')
|
|
->skip(($page - 1) * $count)
|
|
->take($count)
|
|
->get()
|
|
->pluck('viewable')
|
|
->filter();
|
|
}
|
|
}
|