示例#1
0
 /**
  * Tries to recover a branch - assuming that level and left of $rootNode are correct!
  * @param \Cx\Core\ContentManager\Model\Entity\Node $rootNode Node to start with
  */
 private function recoverBranch($rootNode, &$left = null, $level = null)
 {
     if ($left == null) {
         $left = $rootNode->getLft();
     }
     if ($level == null) {
         $level = $rootNode->getLvl();
     }
     // The order in which the children are returned by $rootnode->getChildren() is wrong.
     // Therefore we'll have to manually put the children in the right order.
     // Tote that $children is an object, which is why we have to transform it into an array
     // to be able to using usort() to sort the children.
     $children = $rootNode->getChildren();
     $aChildren = array();
     foreach ($children as $child) {
         $aChildren[] = $child;
     }
     usort($aChildren, function ($a, $b) {
         if ($a->getLft() < $b->getLft()) {
             return -1;
         } elseif ($a->getLft() > $b->getLft()) {
             return 1;
         } else {
             return 0;
         }
     });
     $level++;
     foreach ($aChildren as $child) {
         $left++;
         $child->setLft($left);
         $child->setLvl($level);
         $this->recoverBranch($child, $left, $level);
     }
     $left++;
     $rootNode->setRgt($left);
     $this->em->persist($rootNode);
     $this->em->flush();
 }
 public function getChildren($lang = NULL)
 {
     $this->_load();
     return parent::getChildren($lang);
 }