/** * Check if an entity has restrictions set on itself or its * parent tree. * @param Entity $entity * @param $action * @return bool|mixed */ public function checkIfRestrictionsSet(Entity $entity, $action) { $this->currentAction = $action; if ($entity->isA('page')) { return $entity->restricted || $entity->chapter && $entity->chapter->restricted || $entity->book->restricted; } elseif ($entity->isA('chapter')) { return $entity->restricted || $entity->book->restricted; } elseif ($entity->isA('book')) { return $entity->restricted; } }
/** * Gets the latest activity for an entity, Filtering out similar * items to prevent a message activity list. * @param Entity $entity * @param int $count * @param int $page * @return array */ public function entityActivity($entity, $count = 20, $page = 0) { if ($entity->isA('book')) { $query = $this->activity->where('book_id', '=', $entity->id); } else { $query = $this->activity->where('entity_type', '=', get_class($entity))->where('entity_id', '=', $entity->id); } $activity = $this->permissionService->filterRestrictedEntityRelations($query, 'activities', 'entity_id', 'entity_type')->orderBy('created_at', 'desc')->skip($count * $page)->take($count)->get(); return $this->filterSimilar($activity); }
/** * Change the page's parent to the given entity. * @param Page $page * @param Entity $parent */ public function changePageParent(Page $page, Entity $parent) { $book = $parent->isA('book') ? $parent : $parent->book; $page->chapter_id = $parent->isA('chapter') ? $parent->id : 0; $page->save(); $page = $this->changeBook($book->id, $page); $page->load('book'); $this->permissionService->buildJointPermissionsForEntity($book); }