/** * Returns the built page instance. * * @return Page The built page. */ public function getPage() { if (null === $this->site || null === $this->layout || null === $this->title) { $this->reset(); throw new \Exception("Required data missing"); } $page = new Page($this->uid); $page->setTitle($this->title); $page->setSite($this->site); if (null !== $this->parent) { $page->setParent($this->insureParentIsSection($this->parent)); } $page->setLayout($this->layout, $this->itemToPushInMainZone); if (null !== $this->url) { $page->setUrl($this->url); } if (null !== $this->redirect) { $page->setRedirect($this->redirect); } if (null !== $this->target) { $page->setTarget($this->target); } if (null !== $this->altTitle) { $page->setAltTitle($this->altTitle); } if (null !== $this->state) { $page->setState($this->state); } if (null !== $this->publishedAt) { $page->setPublishing($this->publishedAt); } if (null !== $this->createdAt) { $page->setCreated($this->createdAt); } if (null !== $this->archiving) { $page->setArchiving($this->archiving); } $pageContentSet = $page->getContentSet(); $this->updateContentRevision($pageContentSet); while ($column = $pageContentSet->next()) { $this->updateContentRevision($column); } if (0 < count($this->elements)) { foreach ($this->elements as $e) { $column = $pageContentSet->item($e['content_set_position']); if ($e['set_main_node']) { $e['content']->setMainNode($page); } $column->push($e['content']); } $pageContentSet->rewind(); } $this->doPersistIfValid($page); $this->reset(); return $page; }
private function updatePageState(Page $page, $state) { if ($state === 'online') { if (!$page->isOnline(true)) { $page->setState($page->getState() + 1); } else { throw new NotModifiedException(); } } elseif ($state === 'offline') { if ($page->isOnline(true)) { $page->setState($page->getState() - 1); } else { throw new NotModifiedException(); } } elseif ($state === 'delete') { if ($page->getState() >= 4) { $this->hardDelete($page); } else { $page->setState(4); } } }
/** * Sets state of $page and is descendant to STATE_DELETED. * * @param Page $page The page to delete. * * @return integer The number of page having their state changed. */ public function toTrash(Page $page) { if (true === $page->isLeaf()) { $page->setState(Page::STATE_DELETED); $this->getEntityManager()->flush($page); return 1; } $subquery = $this->getEntityManager()->getRepository('BackBee\\CoreDomain\\NestedNode\\Section')->createQueryBuilder('n')->select('n._uid')->andIsDescendantOf($page->getSection()); return $this->createQueryBuilder('p')->update()->set('p._state', Page::STATE_DELETED)->andWhere('p._section IN (' . $subquery->getDQL() . ')')->setParameters($subquery->getParameters())->getQuery()->execute(); }