mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
b90033a730
- Moves guest user caching from User class to app container for simplicity. - Updates test to use simpler $this->users->guest() method for consistency. - Streamlined helpers to avoid function overlap for simplicity. - Extracted user profile dropdown while doing changes.
34 lines
820 B
PHP
34 lines
820 B
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Queries;
|
|
|
|
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 === null || $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);
|
|
|
|
return $query->with('viewable')
|
|
->skip(($page - 1) * $count)
|
|
->take($count)
|
|
->get()
|
|
->pluck('viewable')
|
|
->filter();
|
|
}
|
|
}
|