BookStack/app/Entities/Queries/RecentlyViewed.php

36 lines
878 B
PHP
Raw Normal View History

2021-06-26 23:23:15 +08:00
<?php
namespace BookStack\Entities\Queries;
2023-05-18 00:56:55 +08:00
use BookStack\Activity\Models\View;
use Illuminate\Support\Collection;
class RecentlyViewed extends EntityQuery
{
public function run(int $count, int $page): Collection
{
$user = user();
if ($user->isGuest()) {
return collect();
}
$query = $this->permissionService()->restrictEntityRelationQuery(
View::query(),
'views',
'viewable_id',
'viewable_type'
)
->orderBy('views.updated_at', 'desc')
->where('user_id', '=', user()->id);
$views = $query
->skip(($page - 1) * $count)
->take($count)
->get();
$this->mixedEntityListLoader()->loadIntoRelations($views->all(), 'viewable', false);
return $views->pluck('viewable')->filter();
}
}