Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Inserts a page in a tree.
  *
  * @param  Page                 $page               The page to be inserted.
  * @param  Page                 $parent             The parent node.
  * @param  integer              $position           The position of the inserted page
  * @param  boolean              $section            If true, the page is inserted with a section (false by default).
  *
  * @return Page                                     The inserted page.
  *
  * @throws InvalidArgumentException                 Raises if parent page is not a section.
  */
 public function insertNode(Page $page, Page $parent, $position, $section = false)
 {
     if (!$parent->hasMainSection()) {
         throw new InvalidArgumentException('Parent page is not a section.');
     }
     $current_parent = $page->getSection();
     $page->setParent($parent)->setPosition($position)->setLevel($parent->getSection()->getLevel() + 1);
     if (true === $section) {
         $page = $this->saveWithSection($page, $current_parent);
     } else {
         $this->shiftPosition($page, 1, true);
     }
     $parent->getSection()->setHasChildren(true);
     return $page;
 }