/** * @param EditPage $command * * @return \Sijad\Pages\Page * * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(EditPage $command) { $actor = $command->actor; $data = $command->data; $page = $this->pages->findOrFail($command->pageId, $actor); $this->assertAdmin($actor); $attributes = array_get($data, 'attributes', []); if (isset($attributes['title'])) { $page->title = $attributes['title']; } if (isset($attributes['slug'])) { $page->slug = $attributes['slug']; } if (isset($attributes['content'])) { $page->content = $attributes['content']; } if (isset($attributes['isHidden'])) { $page->is_hidden = (bool) $attributes['isHidden']; } if (isset($attributes['isHtml'])) { $page->is_html = (bool) $attributes['isHtml']; } $page->edit_time = time(); $this->validator->assertValid($page->getDirty()); $page->save(); return $page; }
/** * @param DeletePage $command * * @return \Sijad\Pages\Page * * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(DeletePage $command) { $actor = $command->actor; $page = $this->pages->findOrFail($command->pageId, $actor); $this->assertAdmin($actor); $page->delete(); return $page; }
/** * @param SearchCriteria $criteria * @param int|null $limit * @param int $offset * * @return SearchResults */ public function search(SearchCriteria $criteria, $limit = null, $offset = 0) { $actor = $criteria->actor; $query = $this->pages->query(); if ($actor !== null && !$actor->isAdmin()) { $query->whereIsHidden(0); } $search = new PageSearch($query->getQuery(), $actor); $this->gambits->apply($search, $criteria->query); $this->applySort($search, $criteria->sort); $this->applyOffset($search, $offset); $this->applyLimit($search, $limit + 1); $pages = $query->get(); if ($areMoreResults = $limit > 0 && $pages->count() > $limit) { $pages->pop(); } return new SearchResults($pages, $areMoreResults); }
/** * {@inheritdoc} */ protected function data(ServerRequestInterface $request, Document $document) { $id = array_get($request->getQueryParams(), 'id'); $actor = $request->getAttribute('actor'); return $this->pages->findOrFail($id, $actor); }