mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-16 16:23:36 +08:00
ed21a6d798
- Updated name to align, and differentate from new 'XQueries' clases. - Removed old sketchy base class with app resolving workarounds, to a proper injection-based approach. - Also fixed wrong translation text used in PageQueries.
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Queries;
|
|
|
|
use BookStack\Activity\Models\View;
|
|
use BookStack\Entities\Tools\MixedEntityListLoader;
|
|
use BookStack\Permissions\PermissionApplicator;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class QueryRecentlyViewed
|
|
{
|
|
public function __construct(
|
|
protected PermissionApplicator $permissions,
|
|
protected MixedEntityListLoader $listLoader,
|
|
) {
|
|
}
|
|
|
|
public function run(int $count, int $page): Collection
|
|
{
|
|
$user = user();
|
|
if ($user->isGuest()) {
|
|
return collect();
|
|
}
|
|
|
|
$query = $this->permissions->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->listLoader->loadIntoRelations($views->all(), 'viewable', false);
|
|
|
|
return $views->pluck('viewable')->filter();
|
|
}
|
|
}
|