mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-14 23:23:37 +08:00
afe1a04239
Also removed lesser used function, that was mostly a duplicate of an existing function, and only used for search.
30 lines
899 B
PHP
30 lines
899 B
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Queries;
|
|
|
|
use BookStack\Actions\View;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class Popular extends EntityQuery
|
|
{
|
|
public function run(int $count, int $page, array $filterModels = null)
|
|
{
|
|
$query = $this->permissionService()
|
|
->restrictEntityRelationQuery(View::query(), 'views', 'viewable_id', 'viewable_type')
|
|
->select('*', 'viewable_id', 'viewable_type', DB::raw('SUM(views) as view_count'))
|
|
->groupBy('viewable_id', 'viewable_type')
|
|
->orderBy('view_count', 'desc');
|
|
|
|
if ($filterModels) {
|
|
$query->whereIn('viewable_type', $this->entityProvider()->getMorphClasses($filterModels));
|
|
}
|
|
|
|
return $query->with('viewable')
|
|
->skip($count * ($page - 1))
|
|
->take($count)
|
|
->get()
|
|
->pluck('viewable')
|
|
->filter();
|
|
}
|
|
}
|