コード例 #1
0
ファイル: Cms.php プロジェクト: janhenckens/ride-lib-cms
 /**
  * Gets the node type of the provided node
  * @param \ride\library\cms\node\Node $node Node to get the type from
  * @return \ride\library\cms\node\type\NodeType
  */
 public function getNodeType(Node $node)
 {
     $nodeTypeManager = $this->nodeModel->getNodeTypeManager();
     return $nodeTypeManager->getNodeType($node->getType());
 }
コード例 #2
0
 /**
  * Clones a node
  * @param \ride\library\cms\node\Node $node Node to clone
  * @param boolean $recursive Set to true to also clone the children of the
  * node
  * @param boolean $reorder Set to false to just clone the order index
  * instead of adding the cloned node after the source node
  * @param boolean $keepOriginalName Set to true to keep the name untouched,
  * else a suffix like (clone) or (clone 2, 3 ...) will be added to the name
  * of the clone
  * @param boolean $cloneRoutesAndId Set to true to clone the routes of the nodes.
  * This will only work when copying a root node, else a validation error
  * will occur
  * @param boolean $newParent Provide a new parent for the clone, needed for
  * recursive cloning
  * @param boolean $autoPublish Set to false to skip auto publishing
  * @return null
  */
 public function cloneNode(Node $node, $recursive = true, $reorder = null, $keepOriginalName = false, $cloneRoutesAndId = null, $newParent = null, $autoPublish = true)
 {
     $id = $node->getId();
     $rootNodeId = $node->getRootNodeId();
     $isRootNode = $id === $rootNodeId;
     if ($reorder === null) {
         if ($isRootNode) {
             $reorder = false;
         } else {
             $reorder = true;
         }
     }
     if ($cloneRoutesAndId === null) {
         if ($isRootNode) {
             $cloneRoutesAndId = true;
         } else {
             $cloneRoutesAndId = false;
         }
     }
     if ($newParent === null) {
         $this->widgetTable = array();
     }
     $nodeType = $this->nodeTypeManager->getNodeType($node->getType());
     $clone = $nodeType->createNode();
     $clone->setRevision($node->getRevision());
     if (!$isRootNode && $cloneRoutesAndId) {
         $clone->setId($node->getId());
     }
     if ($newParent) {
         $clone->setParent($newParent);
     } else {
         $clone->setParent($node->getParent());
     }
     if ($clone->getParent()) {
         $clone->setParentNode($this->io->getNode($clone->getRootNodeId(), $node->getRevision(), $clone->getParentNodeId()));
     }
     if ($reorder) {
         $clone->setOrderIndex($node->getOrderIndex() + 1);
     } else {
         $clone->setOrderIndex($node->getOrderIndex());
     }
     $this->cloneNodeProperties($node, $clone, $keepOriginalName, $cloneRoutesAndId);
     if ($reorder) {
         // reorder the siblings to insert the clone
         $cloneOrderIndex = $clone->getOrderIndex();
         $siblings = $this->io->getChildren($node->getRootNodeId(), $node->getRevision(), $node->getParent(), 0);
         foreach ($siblings as $sibling) {
             $siblingOrderIndex = $sibling->getOrderIndex();
             if ($siblingOrderIndex < $cloneOrderIndex) {
                 continue;
             }
             $sibling->setOrderIndex($siblingOrderIndex + 1);
             $this->setNode($sibling, 'Reordered ' . $sibling->getName() . ' after clone of ' . $node->getName(), false);
         }
     }
     $this->setNode($clone, 'Cloned ' . $node->getName(), false);
     if ($recursive) {
         // clone the children
         $path = $clone->getPath();
         $children = $this->io->getChildren($node->getRootNodeId(), $node->getRevision(), $node->getPath(), 0);
         foreach ($children as $child) {
             $this->cloneNode($child, true, false, true, $cloneRoutesAndId, $path, false);
         }
     }
     if ($newParent === null) {
         unset($this->widgetTable);
     }
     // save the root for newly created widgets
     $this->setNode($clone->getRootNode(), 'Updated widgets for clone of ' . $node->getName(), false);
     // perform auto publishing if enabled
     if (!$isRootNode && $autoPublish && $node->getRootNode()->isAutoPublish()) {
         $this->publishNode($node);
     }
     return $clone;
 }
コード例 #3
0
 /**
  * Gets an array of a node with all it's properties
  * @param \ride\library\cms\node\Node $node
  * @return array
  */
 protected function getArrayFromNode(Node $node)
 {
     $array = array();
     $array[self::PROPERTY_TYPE] = new NodeProperty(self::PROPERTY_TYPE, $node->getType());
     $array[self::PROPERTY_ID] = new NodeProperty(self::PROPERTY_ID, $node->getId());
     $array[self::PROPERTY_PARENT] = new NodeProperty(self::PROPERTY_PARENT, $node->getParent());
     $array[self::PROPERTY_ORDER] = new NodeProperty(self::PROPERTY_ORDER, $node->getOrderIndex());
     $array += $node->getProperties();
     return $array;
 }