Example #1
0
 /**
  * Computes the URL of a page according to a scheme.
  *
  * @param array         $scheme  The scheme to apply
  * @param Page          $page    The page
  * @param  AbstractClassContent $content The optionnal main content of the page
  * @return string        The generated URL
  */
 private function doGenerate($scheme, Page $page, AbstractClassContent $content = null)
 {
     $replacement = ['$parent' => $page->isRoot() ? '' : $page->getParent()->getUrl(false), '$title' => StringUtils::urlize($page->getTitle()), '$datetime' => $page->getCreated()->format('ymdHis'), '$date' => $page->getCreated()->format('ymd'), '$time' => $page->getCreated()->format('His')];
     $matches = [];
     if (preg_match_all('/(\\$content->[a-z]+)/i', $scheme, $matches)) {
         foreach ($matches[1] as $pattern) {
             $property = explode('->', $pattern);
             $property = array_pop($property);
             try {
                 $replacement[$pattern] = StringUtils::urlize($content->{$property});
             } catch (\Exception $e) {
                 $replacement[$pattern] = '';
             }
         }
     }
     $matches = [];
     if (preg_match_all('/(\\$ancestor\\[([0-9]+)\\])/i', $scheme, $matches)) {
         foreach ($matches[2] as $level) {
             $ancestor = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getAncestor($page, $level);
             if (null !== $ancestor && $page->getLevel() > $level) {
                 $replacement['$ancestor[' . $level . ']'] = $ancestor->getUrl(false);
             } else {
                 $replacement['$ancestor[' . $level . ']'] = '';
             }
         }
     }
     $url = preg_replace('/\\/+/', '/', str_replace(array_keys($replacement), array_values($replacement), $scheme));
     return $this->getUniqueness($page, $url);
 }
Example #2
0
 /**
  * @covers BackBee\NestedNode\Page::__clone
  */
 public function test__clone()
 {
     $child = new Page('child', array('title' => 'child', 'url' => 'url'));
     $revision = new PageRevision();
     $child->setSection($this->page->getSection())->setState(Page::STATE_ONLINE)->getRevisions()->add($revision);
     $clone = clone $child;
     $this->assertNotEquals($child->getContentSet(), $clone->getContentSet());
     $this->assertNotEquals($child->getUid(), $clone->getUid());
     $this->assertEquals(1, $clone->getPosition());
     $this->assertEquals(1, $clone->getLevel());
     $this->assertGreaterThanOrEqual($clone->getCreated()->getTimestamp(), $child->getCreated()->getTimestamp());
     $this->assertGreaterThanOrEqual($clone->getModified()->getTimestamp(), $child->getModified()->getTimestamp());
     $this->assertNull($clone->getMainSection());
     $this->assertEquals(Page::STATE_HIDDEN, $clone->getState());
     $this->assertFalse($clone->isStatic());
     $this->assertEquals($child->getTitle(), $clone->getTitle());
     $this->assertEquals(null, $clone->getUrl());
     $this->assertTrue(is_array($clone->cloningData));
     $this->assertTrue(isset($clone->cloningData['pages']));
     $this->assertTrue(isset($clone->cloningData['pages'][$child->getUid()]));
     $this->assertEquals($clone, $clone->cloningData['pages'][$child->getUid()]);
     $this->assertEquals(0, $clone->getRevisions()->count());
     $clone2 = clone $this->page;
     $this->assertNotEquals($this->page->getMainSection(), $clone2->getMainSection());
     $this->assertEquals($clone2->getSection(), $clone2->getMainSection());
     $this->assertEquals(0, $clone2->getPosition());
     $this->assertEquals(0, $clone2->getLevel());
 }