Ejemplo n.º 1
0
 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);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Generates and returns url for the provided page.
  *
  * @param Page                 $page    The page to generate its url
  * @param AbstractClassContent $content The optional main content of the page
  * @return string
  */
 public function generate(Page $page, AbstractClassContent $content = null, $force = false, $exceptionOnMissingScheme = true)
 {
     if (!is_bool($force)) {
         throw new \InvalidArgumentException(sprintf('%s method expect `force parameter` to be type of boolean, %s given', __METHOD__, gettype($force)));
     }
     if (null !== $page->getUrl(false) && $page->getState() & Page::STATE_ONLINE && (!$force && $this->preserveOnline)) {
         return $page->getUrl(false);
     }
     if ($page->isRoot() && array_key_exists('_root_', $this->schemes)) {
         return $this->doGenerate($this->schemes['_root_'], $page, $content);
     }
     if (isset($this->schemes['_layout_']) && is_array($this->schemes['_layout_'])) {
         if (array_key_exists($page->getLayout()->getUid(), $this->schemes['_layout_'])) {
             return $this->doGenerate($this->schemes['_layout_'][$page->getLayout()->getUid()], $page);
         }
     }
     if (null !== $content && array_key_exists('_content_', $this->schemes)) {
         $shortClassname = str_replace(AbstractContent::CLASSCONTENT_BASE_NAMESPACE, '', get_class($content));
         if (array_key_exists($shortClassname, $this->schemes['_content_'])) {
             return $this->doGenerate($this->schemes['_content_'][$shortClassname], $page, $content);
         }
     }
     if (array_key_exists('_default_', $this->schemes)) {
         return $this->doGenerate($this->schemes['_default_'], $page, $content);
     }
     $url = $page->getUrl(false);
     if (!empty($url)) {
         return $url;
     }
     if (true === $exceptionOnMissingScheme) {
         throw new RewritingException(sprintf('No rewriting scheme found for Page (#%s)', $page->getUid()), RewritingException::MISSING_SCHEME);
     }
     return '/' . $page->getUid();
 }
Ejemplo n.º 3
0
 /**
  * Copy a page to a new one.
  *
  * @param  Page                 $page               The page to be copied.
  * @param  string|null          $title              Optional, the title of the copy, if null (default) the title of the copied page.
  * @param  Page|null            $parent             Optional, the parent of the copy, if null (default) the parent of the copied page.
  *
  * @return Page                                     The copy of the page.
  *
  * @throws InvalidArgumentException                 Raises if the page is deleted.
  */
 private function copy(Page $page, $title = null, Page $parent = null)
 {
     if (Page::STATE_DELETED & $page->getState()) {
         throw new InvalidArgumentException('Cannot duplicate a deleted page.');
     }
     // Cloning the page
     $new_page = clone $page;
     $new_page->setTitle(null === $title ? $page->getTitle() : $title)->setLayout($page->getLayout());
     // Setting the clone as first child of the parent
     if (null !== $parent) {
         $new_page = $this->insertNodeAsFirstChildOf($new_page, $parent, $new_page->hasMainSection());
     }
     // Persisting entities
     $this->_em->persist($new_page);
     return $new_page;
 }
Ejemplo n.º 4
0
 /**
  * @covers BackBee\NestedNode\Page::isDeleted
  */
 public function testIsDeleted()
 {
     $page = new Page();
     $page->setParent($this->page);
     $this->assertFalse($page->isDeleted());
     $page->setState($page->getState() + Page::STATE_DELETED);
     $this->assertTrue($page->isDeleted());
 }