protected function reparentChildren() { $children = PageFacade::findByParentId($this->page->getId()); $newParent = PageFacade::find($this->options['reparentChildrenTo']); foreach ($children as $child) { $child->setParent($newParent); PageFacade::save($child); } }
public function handle() { $attrs = ['visible_from' => time(), 'created_by' => $this->createdBy->getId()]; if ($this->parent) { $attrs = ['visible_from' => time(), 'parent_id' => $this->parent->getId(), 'visible_in_nav' => $this->parent->childrenAreVisibleInNav(), 'visible_in_nav_cms' => $this->parent->childrenAreVisibleInCmsNav(), 'children_visible_in_nav' => $this->parent->childrenAreVisibleInNav(), 'children_visible_in_nav_cms' => $this->parent->childrenAreVisibleInCmsNav()]; } $page = PageFacade::create($attrs); $page->addVersion(['edited_by' => $this->createdBy->getId(), 'page_id' => $page->getId(), 'template_id' => $this->parent ? $this->parent->getDefaultChildTemplateId() : null, 'title' => 'Untitled', 'published' => true, 'embargoed_until' => time()]); return $page; }
public function postAdd() { $location = $this->request->input('location'); $this->url = URL::findByLocation($location); if ($this->url && !$this->url->isForPage($this->page)) { // Url is being used for a different page. // Notify that the url is already in use so that the JS can load a prompt to move the url. return ['existing_url_id' => $this->url->getId()]; } elseif (!$this->url) { URL::create($location, $this->page->getId()); } }
public function build(Builder $query) { list($column, $direction) = $this->currentPage->getParent()->getChildOrderingPolicy(); if ($this->direction === 'before' && $direction === 'asc' || $this->direction === 'after' && $direction === 'desc') { $operator = '<'; $direction = 'desc'; } else { $operator = '>'; $direction = 'asc'; } return $query->where($column, $operator . '=', $this->getValue($column))->where('pages.id', $operator, $this->currentPage->getId())->limit(1)->orderBy($column, $direction); }
protected function deleteChildren() { if (!$this->childrenShouldBeMoved()) { Bus::dispatch(new DeletePageChildren($this->page)); } else { $children = PageFacade::findByParentId($this->page->getId()); $newParent = PageFacade::find($this->options['reparentChildrenTo']); foreach ($children as $child) { $child->setParent($newParent); PageFacade::save($child); } } }
protected function doDelete(Page $page) { $children = PageFacade::findByParentId($page->getId()); foreach ($children as $child) { $this->doDelete($child); Bus::dispatch(new DeletePage($child)); } }
public function create(Page $page, $attrs) { $version = $page->addVersion(); $attrs['page_vid'] = $version->getId(); $attrs['page_id'] = $page->getId(); $type = $attrs['type']; unset($attrs['type']); $modelName = 'BoomCMS\\Database\\Models\\Chunk\\' . ucfirst($type); $model = $modelName::create($attrs); $className = 'BoomCMS\\Core\\Chunk\\' . ucfirst($type); $attrs['id'] = $model->id; return new $className($page, $attrs, $attrs['slotname'], true); }
public function create(Page $page, $attrs) { $version = $page->addVersion(); $attrs['page_vid'] = $version->getId(); $attrs['page_id'] = $page->getId(); $type = $attrs['type']; unset($attrs['type']); $modelName = $this->getModelName($type); $model = $modelName::create($attrs); $this->saveToCache($type, $attrs['slotname'], $version, $model); $className = $this->getClassName($type); $attrs['id'] = $model->id; $version->{VersionModel::ATTR_CHUNK_TYPE} = $type; $version->{VersionModel::ATTR_CHUNK_ID} = $model->id; $version->save(); return new $className($page, $attrs, $attrs['slotname'], true); }
public function lookupPagePermission(Person $person, $role, Page $page) { // Page permissions are prefixed with p_ so add the prefix if it's not present. if (substr($role, 0, 2) !== 'p_') { $role = 'p_' . $role; } do { $result = $this->doLookup($person, $role, $page->getId()); if ($page->getParentId() === null) { break; } if ($result === null) { $page = $page->getParent(); } } while ($result === null && $page !== null); return (bool) $result; }
/** * Returns an array of HTML attributes which are required to be make the chunk editable. * * To add other attributes see the attributes method. * * @return array */ public function getRequiredAttributes() { return [$this->attributePrefix . 'chunk' => $this->getType(), $this->attributePrefix . 'slot-name' => $this->slotname, $this->attributePrefix . 'slot-template' => $this->template, $this->attributePrefix . 'page' => $this->page->getId(), $this->attributePrefix . 'chunk-id' => isset($this->attrs['id']) ? $this->attrs['id'] : 0]; }
public function handle() { $this->url->setPageId($this->page->getId())->setIsPrimary(false); URLFacade::save($this->url); }
public function scopeForPage($query, PageInterface $page) { return $query->where(self::ATTR_PAGE, '=', $page->getId()); }
/** * @param PageModelInterface $page * @param callable $closure * * @return void */ public function recurse(PageModelInterface $page, callable $closure) { $children = $this->findByParentId($page->getId()); if (!empty($children)) { foreach ($children as $child) { $this->recurse($child, $closure); } } $closure($page); }
/** * @param PageInterface $parent * * @return $this */ public function setParent(PageInterface $parent) { if (!$parent->is($this) && $parent->getParentId() !== $this->getId()) { $this->{self::ATTR_PARENT} = $parent->getId(); } return $this; }
/** * @param Page $page * * @return bool */ public function isForPage(PageInterface $page) { return $this->getPageId() === $page->getId(); }
/** * Returns the primary URL for the given page. * * @param PageInterface $page * * @return URLInterface */ public function page(PageInterface $page) { return $this->model->where(Model::ATTR_PAGE_ID, '=', $page->getId())->where(Model::ATTR_IS_PRIMARY, '=', true)->first(); }
/** * TODO: This should probably be in a \Boom\Page\Tags class. */ protected function getTagIds() { return DB::table('pages_tags')->select('tag_id')->where('page_id', '=', $this->page->getId())->lists('tag_id'); }
/** * Find a version by page and version ID. * * @param PageModelInterface $page * @param type $versionId * * @return Model */ public function find(PageModelInterface $page, $versionId) { return $this->model->where(Model::ATTR_PAGE, $page->getId())->where(Model::ATTR_ID, $versionId)->first(); }