|
@@ -354,17 +354,21 @@ class NestedTreeRepository extends AbstractTreeRepository
|
|
|
|
|
|
$config = $this->listener->getConfiguration($this->_em, $meta->name);
|
|
$config = $this->listener->getConfiguration($this->_em, $meta->name);
|
|
$parent = $wrapped->getPropertyValue($config['parent']);
|
|
$parent = $wrapped->getPropertyValue($config['parent']);
|
|
- if (!$parent) {
|
|
|
|
|
|
+ if (isset($config['root']) && !$parent) {
|
|
throw new InvalidArgumentException("Cannot get siblings from tree root node");
|
|
throw new InvalidArgumentException("Cannot get siblings from tree root node");
|
|
}
|
|
}
|
|
- $wrappedParent = new EntityWrapper($parent, $this->_em);
|
|
|
|
- $parentId = $wrappedParent->getIdentifier();
|
|
|
|
|
|
|
|
$left = $wrapped->getPropertyValue($config['left']);
|
|
$left = $wrapped->getPropertyValue($config['left']);
|
|
$sign = $includeSelf ? '>=' : '>';
|
|
$sign = $includeSelf ? '>=' : '>';
|
|
|
|
|
|
$dql = "SELECT node FROM {$config['useObjectClass']} node";
|
|
$dql = "SELECT node FROM {$config['useObjectClass']} node";
|
|
- $dql .= " WHERE node.{$config['parent']} = {$parentId}";
|
|
|
|
|
|
+ if ($parent) {
|
|
|
|
+ $wrappedParent = new EntityWrapper($parent, $this->_em);
|
|
|
|
+ $parentId = $wrappedParent->getIdentifier();
|
|
|
|
+ $dql .= " WHERE node.{$config['parent']} = {$parentId}";
|
|
|
|
+ } else {
|
|
|
|
+ $dql .= " WHERE node.{$config['parent']} IS NULL";
|
|
|
|
+ }
|
|
$dql .= " AND node.{$config['left']} {$sign} {$left}";
|
|
$dql .= " AND node.{$config['left']} {$sign} {$left}";
|
|
$dql .= " ORDER BY node.{$config['left']} ASC";
|
|
$dql .= " ORDER BY node.{$config['left']} ASC";
|
|
return $this->_em->createQuery($dql);
|
|
return $this->_em->createQuery($dql);
|
|
@@ -403,17 +407,21 @@ class NestedTreeRepository extends AbstractTreeRepository
|
|
|
|
|
|
$config = $this->listener->getConfiguration($this->_em, $meta->name);
|
|
$config = $this->listener->getConfiguration($this->_em, $meta->name);
|
|
$parent = $wrapped->getPropertyValue($config['parent']);
|
|
$parent = $wrapped->getPropertyValue($config['parent']);
|
|
- if (!$parent) {
|
|
|
|
|
|
+ if (isset($config['root']) && !$parent) {
|
|
throw new InvalidArgumentException("Cannot get siblings from tree root node");
|
|
throw new InvalidArgumentException("Cannot get siblings from tree root node");
|
|
}
|
|
}
|
|
- $wrappedParent = new EntityWrapper($parent, $this->_em);
|
|
|
|
- $parentId = $wrappedParent->getIdentifier();
|
|
|
|
|
|
|
|
$left = $wrapped->getPropertyValue($config['left']);
|
|
$left = $wrapped->getPropertyValue($config['left']);
|
|
$sign = $includeSelf ? '<=' : '<';
|
|
$sign = $includeSelf ? '<=' : '<';
|
|
|
|
|
|
$dql = "SELECT node FROM {$config['useObjectClass']} node";
|
|
$dql = "SELECT node FROM {$config['useObjectClass']} node";
|
|
- $dql .= " WHERE node.{$config['parent']} = {$parentId}";
|
|
|
|
|
|
+ if ($parent) {
|
|
|
|
+ $wrappedParent = new EntityWrapper($parent, $this->_em);
|
|
|
|
+ $parentId = $wrappedParent->getIdentifier();
|
|
|
|
+ $dql .= " WHERE node.{$config['parent']} = {$parentId}";
|
|
|
|
+ } else {
|
|
|
|
+ $dql .= " WHERE node.{$config['parent']} IS NULL";
|
|
|
|
+ }
|
|
$dql .= " AND node.{$config['left']} {$sign} {$left}";
|
|
$dql .= " AND node.{$config['left']} {$sign} {$left}";
|
|
$dql .= " ORDER BY node.{$config['left']} ASC";
|
|
$dql .= " ORDER BY node.{$config['left']} ASC";
|
|
return $this->_em->createQuery($dql);
|
|
return $this->_em->createQuery($dql);
|