<?php namespace BookStack\Actions;
use BookStack\Auth\Permissions\PermissionService;
+use BookStack\Entities\Book;
use BookStack\Entities\Entity;
use BookStack\Entities\EntityProvider;
+use DB;
use Illuminate\Support\Collection;
class ViewService
/**
* ViewService constructor.
- * @param \BookStack\Actions\View $view
- * @param \BookStack\Auth\Permissions\PermissionService $permissionService
+ * @param View $view
+ * @param PermissionService $permissionService
* @param EntityProvider $entityProvider
*/
public function __construct(View $view, PermissionService $permissionService, EntityProvider $entityProvider)
/**
* Add a view to the given entity.
- * @param Entity $entity
+ * @param \BookStack\Entities\Entity $entity
* @return int
*/
public function add(Entity $entity)
}
// Otherwise create new view count
- $entity->views()->save($this->view->create([
+ $entity->views()->save($this->view->newInstance([
'user_id' => $user->id,
'views' => 1
]));
* @param string $action - used for permission checking
* @return Collection
*/
- public function getPopular(int $count = 10, int $page = 0, $filterModels = null, string $action = 'view')
+ public function getPopular(int $count = 10, int $page = 0, array $filterModels = null, string $action = 'view')
{
$skipCount = $count * $page;
$query = $this->permissionService
->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type', $action)
- ->select('*', 'viewable_id', 'viewable_type', \DB::raw('SUM(views) as view_count'))
+ ->select('*', 'viewable_id', 'viewable_type', DB::raw('SUM(views) as view_count'))
->groupBy('viewable_id', 'viewable_type')
->orderBy('view_count', 'desc');