Esempio n. 1
0
 /**
  *
  */
 public function testNodesSources()
 {
     $n = new Node();
     $t = new Translation();
     // Arrange
     $a = new NodesSources($n, $t);
     $a->setTitle('Test node');
     // Assert
     $this->assertNotNull($a);
 }
 /**
  * @param NodesSources $nodeSource
  * @param string $themeName
  * @param array $assignation
  *
  * @return string
  */
 public function blockRender(NodesSources $nodeSource, $themeName = "DefaultTheme", $assignation = [])
 {
     if (null !== $nodeSource) {
         if (!empty($themeName)) {
             $class = '\\Themes\\' . $themeName . '\\Controllers\\Blocks\\' . $nodeSource->getNode()->getNodeType()->getName() . 'Controller';
             if (class_exists($class) && method_exists($class, 'blockAction')) {
                 $ctrl = new $class();
                 $ctrl->setContainer($this->container);
                 $ctrl->__init();
                 $response = $ctrl->blockAction($this->container['request'], $nodeSource, $assignation);
                 return $response->getContent();
             } else {
                 throw new \Exception($class . "::blockAction() action does not exist.", 1);
             }
         } else {
             throw new \Exception("Invalid name formatting for your theme.", 1);
         }
     }
 }
Esempio n. 3
0
 public function getCacheKey(NodesSources $ns, $absolute = false)
 {
     return $ns->getId() . "_" . (int) $absolute;
 }
Esempio n. 4
0
 /**
  * Get node-source parent according to its translation.
  *
  * @param  NodesSources $nodeSource
  * @return NodesSources|null
  */
 public function findParent(NodesSources $nodeSource)
 {
     if (null !== $nodeSource->getNode()->getParent()) {
         try {
             $query = $this->_em->createQuery('
                 SELECT ns FROM RZ\\Roadiz\\Core\\Entities\\NodesSources ns
                 WHERE ns.node = :node
                 AND ns.translation = :translation')->setParameter('node', $nodeSource->getNode()->getParent())->setParameter('translation', $nodeSource->getTranslation());
             return $query->getSingleResult();
         } catch (NoResultException $e) {
             return null;
         }
     } else {
         return null;
     }
 }
Esempio n. 5
0
 /**
  * Fill node-source content according to field type.
  *
  * @param mixed         $dataValue
  * @param NodesSources  $nodeSource
  * @param NodeTypeField $field
  *
  * @return void
  */
 public function setValueFromFieldType($dataValue, NodesSources $nodeSource, NodeTypeField $field)
 {
     switch ($field->getType()) {
         case NodeTypeField::DOCUMENTS_T:
             $hdlr = $nodeSource->getHandler();
             $hdlr->cleanDocumentsFromField($field);
             if (is_array($dataValue)) {
                 foreach ($dataValue as $documentId) {
                     $tempDoc = Kernel::getService('em')->find('RZ\\Roadiz\\Core\\Entities\\Document', (int) $documentId);
                     if ($tempDoc !== null) {
                         $hdlr->addDocumentForField($tempDoc, $field);
                     }
                 }
             }
             break;
         case NodeTypeField::CUSTOM_FORMS_T:
             $hdlr = $nodeSource->getNode()->getHandler();
             $hdlr->cleanCustomFormsFromField($field);
             if (is_array($dataValue)) {
                 foreach ($dataValue as $customFormId) {
                     $tempCForm = Kernel::getService('em')->find('RZ\\Roadiz\\Core\\Entities\\CustomForm', (int) $customFormId);
                     if ($tempCForm !== null) {
                         $hdlr->addCustomFormForField($tempCForm, $field);
                     }
                 }
             }
             break;
         case NodeTypeField::NODES_T:
             $hdlr = $nodeSource->getNode()->getHandler();
             $hdlr->cleanNodesFromField($field);
             if (is_array($dataValue)) {
                 foreach ($dataValue as $nodeId) {
                     $tempNode = Kernel::getService('em')->find('RZ\\Roadiz\\Core\\Entities\\Node', (int) $nodeId);
                     if ($tempNode !== null) {
                         $hdlr->addNodeForField($tempNode, $field);
                     }
                 }
             }
             break;
         case NodeTypeField::CHILDREN_T:
             break;
         default:
             $setter = $field->getSetterName();
             $nodeSource->{$setter}($dataValue);
             break;
     }
 }
 public static function getUrlProvider()
 {
     $sources = array();
     /*
      * Test 1 - regular node
      */
     $n1 = new Node();
     $n1->setNodeName('page');
     $t1 = new Translation();
     $t1->setLocale('fr');
     $t1->setDefaultTranslation(true);
     $t1->setAvailable(true);
     $ns1 = new NodesSources($n1, $t1);
     $sources[] = array($ns1, '/page');
     /*
      * Test 2  - regular node
      */
     $n2 = new Node();
     $n2->setNodeName('page');
     $t2 = new Translation();
     $t2->setLocale('en');
     $t2->setDefaultTranslation(false);
     $t2->setAvailable(true);
     $ns2 = new NodesSources($n2, $t2);
     $sources[] = array($ns2, '/en/page');
     /*
      * Test 3 - home node
      */
     $n3 = new Node();
     $n3->setNodeName('page');
     $n3->setHome(true);
     $t3 = new Translation();
     $t3->setLocale('fr');
     $t3->setDefaultTranslation(true);
     $t3->setAvailable(true);
     $ns3 = new NodesSources($n3, $t3);
     $sources[] = array($ns3, '/');
     /*
      * Test 4 - home node non-default
      */
     $n4 = new Node();
     $n4->setNodeName('page');
     $n4->setHome(true);
     $t4 = new Translation();
     $t4->setLocale('en');
     $t4->setDefaultTranslation(false);
     $t4->setAvailable(true);
     $ns4 = new NodesSources($n4, $t4);
     $sources[] = array($ns4, '/en');
     /*
      * Test 5  - regular node with alias
      */
     $n5 = new Node();
     $n5->setNodeName('page');
     $t5 = new Translation();
     $t5->setLocale('en');
     $t5->setDefaultTranslation(false);
     $t5->setAvailable(true);
     $ns5 = new NodesSources($n5, $t5);
     $a5 = new Urlalias($ns5);
     $a5->setAlias('tralala-en');
     $ns5->getUrlAliases()->add($a5);
     $sources[] = array($ns5, '/tralala-en');
     /*
      * Test 6  - regular node with 1 parent
      */
     $n6 = new Node();
     $n6->setNodeName('other-page');
     $t6 = new Translation();
     $t6->setLocale('en');
     $t6->setDefaultTranslation(true);
     $t6->setAvailable(true);
     $ns6 = new NodesSources($n6, $t6);
     $ns6->getHandler()->setParentNodeSource($ns1);
     $sources[] = array($ns6, '/page/other-page');
     /*
      * Test 7  - regular node with 2 parents
      */
     $n7 = new Node();
     $n7->setNodeName('sub-page');
     $t7 = new Translation();
     $t7->setLocale('en');
     $t7->setDefaultTranslation(true);
     $t7->setAvailable(true);
     $ns7 = new NodesSources($n7, $t7);
     $ns7->getHandler()->setParentNodeSource($ns6);
     $sources[] = array($ns7, '/page/other-page/sub-page');
     /*
      * Test 8  - regular node with 1 parent and 2 alias
      */
     $n8 = new Node();
     $n8->setNodeName('other-page-alias');
     $t8 = new Translation();
     $t8->setLocale('en');
     $t8->setDefaultTranslation(true);
     $t8->setAvailable(true);
     $ns8 = new NodesSources($n8, $t8);
     $a8 = new Urlalias($ns8);
     $a8->setAlias('other-tralala-en');
     $ns8->getUrlAliases()->add($a8);
     $ns8->getHandler()->setParentNodeSource($ns5);
     $sources[] = array($ns8, '/tralala-en/other-tralala-en');
     /*
      * Test 9 - hidden node
      */
     $n9 = new Node();
     $n9->setNodeName('pagehidden');
     $n9->setVisible(false);
     $t9 = new Translation();
     $t9->setLocale('fr');
     $t9->setDefaultTranslation(true);
     $t9->setAvailable(true);
     $ns9 = new NodesSources($n9, $t9);
     $sources[] = array($ns9, '/pagehidden');
     /*
      * Test 10 - regular node with hidden parent
      */
     $n10 = new Node();
     $n10->setNodeName('page-with-hidden-parent');
     $t10 = new Translation();
     $t10->setLocale('fr');
     $t10->setDefaultTranslation(true);
     $t10->setAvailable(true);
     $ns10 = new NodesSources($n10, $t10);
     $ns10->getHandler()->setParentNodeSource($ns9);
     $sources[] = array($ns10, '/page-with-hidden-parent');
     return $sources;
 }
 public function getTags(NodesSources $ns)
 {
     return $ns->getHandler()->getTags();
 }