/**
  * @covers \BackBee\NestedNode\Repository\PageRepository::duplicate
  */
 public function testDuplicate()
 {
     // Duplicate a root not recursively to new a one
     $clone1 = $this->repository->duplicate($this->root, null, null, false);
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $clone1);
     $this->assertNull($clone1->getParent());
     $this->assertEquals('root', $clone1->getTitle());
     $this->assertTrue($clone1->hasMainSection());
     $this->assertEquals(1, $clone1->getLeftnode());
     $this->assertEquals(2, $clone1->getRightnode());
     $this->assertNotEquals($this->root->getContentSet(), $clone1->getContentSet());
     // Duplicate a root not recursively to one of its descendant
     $section1 = $this->repository->find('section1');
     $clone2 = $this->repository->duplicate($this->root, null, $section1, false);
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $clone2);
     $this->assertEquals($section1, $clone2->getParent());
     $this->assertTrue($clone2->hasMainSection());
     // Duplicate a section not recursively to another one
     $section2 = $this->repository->find('section2');
     $section3 = $this->repository->duplicate($section2, null, $section1, false);
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $section3);
     $this->assertEquals($section1, $section3->getParent());
     $this->assertTrue($section3->hasMainSection());
     // Duplicate a page in a section with a new title
     $page3 = $this->repository->find('page3');
     $page4 = $this->repository->duplicate($page3, 'page4', $section1, false);
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $page4);
     $this->assertEquals($section1, $page4->getParent());
     $this->assertFalse($page4->hasMainSection());
     $this->assertEquals('page4', $page4->getTitle());
 }
Example #2
0
 /**
  * Updates the associated definition of the set of metadata.
  *
  * @param array                    $definitions
  * @param \BackBee\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);
                     }
                 }
             }
         }
     }
 }
 /**
  * @covers \BackBee\NestedNode\Builder\PageBuilder::getPage
  */
 public function testGetPageNoPersist()
 {
     $yesterday = new \DateTime('yesterday');
     $tomorrow = new \DateTime('tomorrow');
     $now = new \DateTime();
     $page = self::$builder->setUid('uid')->setTitle('title')->setAltTitle('alttitle')->setRedirect('redirect')->setTarget('target')->setUrl('url')->setSite($this->site)->setRoot($this->root)->setParent($this->root)->setLayout($this->layout)->pushElement(new MockContent(), true, 0)->createdAt($yesterday)->publishedAt($now)->setArchiving($tomorrow)->setState(Page::STATE_ONLINE)->isSection(true)->setPersistMode(PageBuilder::NO_PERSIST)->getPage();
     $this->assertInstanceOf('BackBee\\NestedNode\\Page', $page);
     $this->assertEquals('uid', $page->getUid());
     $this->assertEquals('title', $page->getTitle());
     $this->assertEquals('alttitle', $page->getAltTitle());
     $this->assertEquals('redirect', $page->getRedirect());
     $this->assertEquals('target', $page->getTarget());
     $this->assertEquals('url', $page->getUrl(false));
     $this->assertEquals($this->site, $page->getSite());
     $this->assertEquals($this->root, $page->getRoot());
     $this->assertEquals($this->root, $page->getParent());
     $this->assertEquals($this->layout, $page->getLayout());
     $this->assertEquals($yesterday, $page->getCreated());
     $this->assertEquals($now, $page->getPublishing());
     $this->assertEquals($tomorrow, $page->getArchiving());
     $this->assertEquals(Page::STATE_ONLINE, $page->getState());
     $this->assertFalse($page->isRoot());
     // $page gets a main section only with persist
     $this->assertFalse($page->hasMainSection());
     // Test that main contentset and columns are "validated" - according to default layout
     $this->assertEquals(1, $page->getContentSet()->getRevision());
     $this->assertEquals(1, $page->getContentSet()->first()->getRevision());
     $this->assertEquals(1, $page->getContentSet()->last()->getRevision());
     $this->assertEquals(AbstractClassContent::STATE_NORMAL, $page->getContentSet()->getState());
     $this->assertEquals(AbstractClassContent::STATE_NORMAL, $page->getContentSet()->first()->getState());
     $this->assertEquals(AbstractClassContent::STATE_NORMAL, $page->getContentSet()->last()->getState());
     // Test that second column is inherited - according to default layout
     $this->assertEquals($this->root->getContentSet()->last(), $page->getContentSet()->last());
     // Test that first column get a ContentSet by default - according to default layout
     $this->assertInstanceOf('BackBee\\ClassContent\\ContentSet', $page->getContentSet()->first()->first());
     // Test that push content has main node set
     $content = $page->getContentSet()->first()->last();
     $this->assertInstanceOf('BackBee\\ClassContent\\Tests\\Mock\\MockContent', $content);
     $this->assertEquals($page, $content->getMainNode());
     // After getting the page, the builder is reset
     $this->testReset();
 }
Example #4
0
 /**
  * Remove a page from databse.
  *
  * @param Page $page
  */
 public function deletePage(Page $page)
 {
     if ($page->hasMainSection()) {
         $this->getEntityManager()->getRepository('BackBee\\NestedNode\\Section')->deleteSection($page->getSection());
     }
     if (null !== $page->getContentSet()) {
         $this->getEntityManager()->createQueryBuilder()->update('BackBee\\NestedNode\\Page', 'p')->set('p._contentset', ':null')->where('p._contentset = :uid')->setParameter('uid', $page->getContentSet()->getUid())->setParameter('null', null)->getQuery()->execute();
         $this->getEntityManager()->getRepository('BackBee\\ClassContent\\AbstractClassContent')->deleteContent($page->getContentSet());
     }
     $this->getEntityManager()->createQueryBuilder()->update('BackBee\\ClassContent\\AbstractClassContent', 'c')->set('c._mainnode', ':null')->where('c._mainnode = :uid')->setParameter('uid', $page->getUid())->setParameter('null', null)->getQuery()->execute();
     $this->getEntityManager()->remove($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);
 }
Example #6
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 #7
0
 /**
  * @covers BackBee\NestedNode\Page::replaceRootContentSet
  */
 public function testReplaceRootContentSet()
 {
     $oldContentSet = $this->page->getContentSet()->last();
     $newContentSet = new ContentSet();
     $this->assertEquals($newContentSet, $this->page->replaceRootContentSet($this->page->getContentSet()->last(), $newContentSet));
     $this->assertEquals($oldContentSet, $this->page->getContentSet()->last());
     $this->assertEquals($newContentSet, $this->page->replaceRootContentSet($this->page->getContentSet()->last(), $newContentSet, true));
     $this->assertEquals($oldContentSet, $this->page->getContentSet()->last());
     $this->assertEquals($newContentSet, $this->page->replaceRootContentSet($this->page->getContentSet()->last(), $newContentSet, false));
     $this->assertEquals($newContentSet, $this->page->getContentSet()->last());
     $this->page->replaceRootContentSet($this->page->getContentSet()->last(), $oldContentSet, false);
     $this->assertEquals($newContentSet, $this->page->replaceRootContentSet($this->page->getContentSet()->last(), $newContentSet, null));
     $this->assertEquals($newContentSet, $this->page->getContentSet()->last());
     $this->page->replaceRootContentSet($this->page->getContentSet()->last(), $oldContentSet, false);
     $this->assertEquals($newContentSet, $this->page->replaceRootContentSet($this->page->getContentSet()->last(), $newContentSet, 'fake'));
     $this->assertEquals($newContentSet, $this->page->getContentSet()->last());
     $child = new Page('child', array('title' => 'child', 'url' => 'url'));
     $child->setParent($this->page)->setLayout($this->page->getLayout());
     $this->assertEquals($newContentSet, $child->replaceRootContentSet($child->getContentSet()->last(), $newContentSet));
     $this->assertEquals($newContentSet, $child->getContentSet()->last());
 }
Example #8
0
 /**
  * Resolves $scheme against provided $content.
  *
  * @param  string $scheme
  * @param  Page   $page
  *
  * @return string
  */
 private function resolveScheme($scheme, Page $page)
 {
     $functions = explode('||', $scheme);
     $value = array_shift($functions);
     $content = $page->getContentSet();
     $matches = [];
     if (false !== preg_match_all(self::MATCH_PATTERN, $scheme, $matches, PREG_PATTERN_ORDER)) {
         $count = count($matches[0]);
         for ($i = 0; $i < $count; $i++) {
             $resolvedContent = $this->parseScheme($content, $matches[0][$i]);
             if ($resolvedContent instanceof AbstractClassContent && $resolvedContent->isElementContent()) {
                 $scheme = str_replace($matches[0][$i], $this->getElementValue($resolvedContent, $page), $scheme);
             } elseif (is_array($resolvedContent)) {
                 $scheme = str_replace($matches[0][$i], $this->getArrayValue($resolvedContent), $scheme);
             } else {
                 $resolvedContent = trim(str_replace(["\n", "\r"], '', strip_tags($resolvedContent)));
                 $scheme = str_replace($matches[0][$i], $resolvedContent, $scheme);
             }
         }
         $value = $scheme;
     }
     return $this->callback($value, $functions);
 }
 public function deletePage(Page $page)
 {
     if ($page->hasMainSection()) {
         $this->getEntityManager()->getRepository('BackBee\\NestedNode\\Section')->deleteSection($page->getSection());
     }
     if ($page->getContentSet() !== null) {
         $this->getEntityManager()->getRepository('BackBee\\ClassContent\\AbstractClassContent')->deleteContent($page->getContentSet());
     }
     $this->getEntityManager()->remove($page);
 }