X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/f413fc528a8136c2ad8d33a57b3615fa22e55e93..refs/pull/2393/head:/app/Actions/ViewService.php diff --git a/app/Actions/ViewService.php b/app/Actions/ViewService.php index 324bfaa4e..ec57cdb76 100644 --- a/app/Actions/ViewService.php +++ b/app/Actions/ViewService.php @@ -1,8 +1,8 @@ isDefault()) { return collect(); } - $query = $this->permissionService - ->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type'); - - if ($filterModel) { - $query = $query->where('viewable_type', '=', $filterModel->getMorphClass()); + $all = collect(); + /** @var Entity $instance */ + foreach ($this->entityProvider->all() as $name => $instance) { + $items = $instance::visible()->withLastView() + ->orderBy('last_viewed_at', 'desc') + ->skip($count * ($page - 1)) + ->take($count) + ->get(); + $all = $all->concat($items); } - $query = $query->where('user_id', '=', $user->id); - $viewables = $query->with('viewable')->orderBy('updated_at', 'desc') - ->skip($count * $page)->take($count)->get()->pluck('viewable'); - return $viewables; + return $all->sortByDesc('last_viewed_at')->slice(0, $count); } /**