/** * Returns a QueryBuilder to grab the siblings of the given node * * @param \DoctrineExtensions\Hierarchical\MaterializedPath\MaterializedPathNodeInfo $node * @return \Doctrine\ORM\QueryBuilder */ public function getSiblingQueryBuilder(MaterializedPathNodeInfo $node) { $qb = $this->getBaseQueryBuilder(); $expr = $qb->expr(); $andX = $expr->andX(); $andX->add($expr->eq('e.' . $node->getDepthFieldName(), $node->getDepth())); if ($node->getDepth() > 1) { $parentPath = PathHelper::getBasePath($node, $node->getPath(), $node->getDepth() - 1); $pathInterval = PathHelper::getChildrenPathInterval($node, $parentPath); $andX->add($expr->between('e.' . $node->getPathFieldName(), $expr->literal($pathInterval[0]), $expr->literal($pathInterval[1]))); } $qb->where($andX); return $qb; }
/** * The interval of all possible children paths for a node * * @param Node $node * @param string $path * @return array Index 0: start - Index 1: end */ public static function getChildrenPathInterval(NodeInfo $node, $path) { return array($path . str_repeat(substr($node->getAlphabet(), 0, 1), $node->getStepLength()), $path . str_repeat(substr($node->getAlphabet(), -1), $node->getStepLength())); }