2021-06-26 17:23:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Entities\Queries;
|
2021-05-22 15:05:28 +02:00
|
|
|
|
|
|
|
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()->filterRestrictedEntityRelations(
|
|
|
|
View::query(),
|
|
|
|
'views',
|
|
|
|
'viewable_id',
|
2022-07-16 14:17:08 +02:00
|
|
|
'viewable_type'
|
2021-05-22 15:05:28 +02:00
|
|
|
)
|
|
|
|
->orderBy('views.updated_at', 'desc')
|
|
|
|
->where('user_id', '=', user()->id);
|
|
|
|
|
|
|
|
return $query->with('viewable')
|
|
|
|
->skip(($page - 1) * $count)
|
|
|
|
->take($count)
|
|
|
|
->get()
|
|
|
|
->pluck('viewable')
|
|
|
|
->filter();
|
|
|
|
}
|
|
|
|
}
|