Esempio n. 1
0
 /**
  * Updates the associated definition of the set of metadata.
  *
  * @param array                    $definitions
  * @param \BackBee\CoreDomain\NestedNode\Page $page
  */
 public function update(array $definitions = null, Page $page = null)
 {
     $content = null === $page ? null : $page->getContentSet();
     if (null !== $definitions) {
         foreach ($definitions as $name => $definition) {
             if (false === is_array($definition)) {
                 continue;
             }
             if (null === ($metadata = $this->get($name))) {
                 $metadata = new MetaData($name);
                 $this->add($metadata);
             }
             foreach ($definition as $attrname => $attrvalue) {
                 if (false === is_array($attrvalue)) {
                     $attrvalue = '' === $metadata->getAttribute($attrname) ? $attrvalue : $metadata->getAttribute($attrname);
                     $metadata->setAttribute($attrname, $attrvalue, $content);
                     continue;
                 }
                 if (true === $metadata->hasAttribute($attrname)) {
                     if (null !== $page && true === array_key_exists('layout', $attrvalue)) {
                         $layout_uid = $page->getLayout()->getUid();
                         if (true === array_key_exists($layout_uid, $attrvalue['layout'])) {
                             $scheme = is_array($attrvalue['layout'][$layout_uid]) ? reset($attrvalue['layout'][$layout_uid]) : $attrvalue['layout'][$layout_uid];
                             $metadata->updateAttributeScheme($attrname, $scheme, $content);
                         }
                     }
                     continue;
                 }
                 if (true === array_key_exists('default', $attrvalue)) {
                     $value = is_array($attrvalue['default']) ? reset($attrvalue['default']) : $attrvalue['default'];
                     $metadata->setAttribute($attrname, $value, $content);
                 }
                 if (null !== $page && true === array_key_exists('layout', $attrvalue)) {
                     $layout_uid = $page->getLayout()->getUid();
                     if (true === array_key_exists($layout_uid, $attrvalue['layout'])) {
                         $value = is_array($attrvalue['layout'][$layout_uid]) ? reset($attrvalue['layout'][$layout_uid]) : $attrvalue['layout'][$layout_uid];
                         $metadata->setAttribute($attrname, $value, $content);
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
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;
 }
 /**
  * Replace page-content indexes for the provided page
  * Then replace site_content indexes.
  *
  * @param  Page                 $page
  * @param  AbstractClassContent $content
  *
  * @return IndexationRepository
  */
 public function updateIdxPage(Page $page = null, AbstractClassContent $content = null)
 {
     if (null === $page) {
         return $this;
     }
     if (null === $content) {
         $content = $page->getContentSet();
     }
     $query = 'INSERT INTO idx_page_content (page_uid, content_uid) ' . '(SELECT :page, subcontent_uid FROM idx_content_content WHERE content_uid = :content) ' . 'UNION DISTINCT (SELECT :page, content_uid FROM idx_content_content WHERE subcontent_uid = :content)';
     $params = array('page' => $page->getUid(), 'content' => $content->getUid());
     return $this->removeIdxContentPage($content, $page)->_executeQuery($query, $params)->_replaceIdxSite($page);
 }
Esempio n. 4
0
 public function deletePage(Page $page)
 {
     if ($page->hasMainSection()) {
         $this->getEntityManager()->getRepository('BackBee\\CoreDomain\\NestedNode\\Section')->deleteSection($page->getSection());
     }
     if ($page->getContentSet() !== null) {
         $this->getEntityManager()->getRepository('BackBee\\CoreDomain\\ClassContent\\AbstractClassContent')->deleteContent($page->getContentSet());
     }
     $this->getEntityManager()->remove($page);
 }