/**
  * Add query part to select descendants of $node.
  *
  * @param  \BackBee\NestedNode\AbstractNestedNode                       $node
  * @param  boolean                                               $strict   If TRUE, $node is excluded from the selection
  * @param  int                                                   $at_level Filter ancestors by their level
  * @param  string                                                $alias    optional, the alias to use
  * @return \BackBee\NestedNode\Repository\NestedNodeQueryBuilder
  */
 public function andIsDescendantOf(AbstractNestedNode $node, $strict = false, $at_level = null, $alias = null)
 {
     $this->andRootIs($node->getRoot(), $alias)->andLeftnodeIsUpperThan($node->getLeftnode(), $strict, $alias)->andRightnodeIsLowerThan($node->getRightnode(), $strict, $alias);
     if (null !== $at_level) {
         $this->andLevelEquals($at_level);
     }
     return $this;
 }
示例#2
0
 /**
  * Returns the new left node from $dest node and position.
  *
  * @param  \BackBee\NestedNode\AbstractNestedNode $dest
  * @param  string                          $position
  * @return \BackBee\NestedNode\AbstractNestedNode
  * @throws InvalidArgumentException        Occurs if $position is unknown
  */
 private function getNewLeftFromPosition(AbstractNestedNode $dest, $position)
 {
     switch ($position) {
         case 'before':
             $newleft = $dest->getLeftnode();
             break;
         case 'after':
             $newleft = $dest->getRightnode() + 1;
             break;
         case 'firstin':
             $newleft = $dest->getLeftnode() + 1;
             break;
         case 'lastin':
             $newleft = $dest->getRightnode();
             break;
         default:
             throw new InvalidArgumentException(sprintf('Unknown position %s to move node', $position));
     }
     return $newleft;
 }
 /**
  * Is this node is a descendant of the provided one ?
  *
  * @param  \BackBee\NestedNode\AbstractNestedNode $node
  * @param  Boolean                         $strict Optional, if TRUE (default) this node is excluded of descendants list
  *
  * @return Boolean                         TRUE if this node is a descendant or provided node, FALSE otherwise
  */
 public function isDescendantOf(AbstractNestedNode $node, $strict = true)
 {
     if (true === $strict) {
         return $this->getLeftnode() > $node->getLeftnode() && $this->getRightnode() < $node->getRightnode() && $this->getRoot() === $node->getRoot();
     } else {
         return $this->getLeftnode() >= $node->getLeftnode() && $this->getRightnode() <= $node->getRightnode() && $this->getRoot() === $node->getRoot();
     }
 }