Skip to content

Commit 2bd013f

Browse files
authored
Merge pull request lazychaser#189 from dcanaud/feature-self-or-descendant-and-ancestor
Add isSelfOrDescendantOf and isSelfOrAncestorOf helpers
2 parents b787af1 + d3bc3dd commit 2bd013f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/NodeTrait.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,19 @@ public function isDescendantOf(self $other)
10061006
$this->getLft() < $other->getRgt();
10071007
}
10081008

1009+
/**
1010+
* Get whether a node is itself or a descendant of other node.
1011+
*
1012+
* @param self $other
1013+
*
1014+
* @return bool
1015+
*/
1016+
public function isSelfOrDescendantOf(self $other)
1017+
{
1018+
return $this->getLft() >= $other->getLft() &&
1019+
$this->getLft() < $other->getRgt();
1020+
}
1021+
10091022
/**
10101023
* Get whether the node is immediate children of other node.
10111024
*
@@ -1042,6 +1055,18 @@ public function isAncestorOf(self $other)
10421055
return $other->isDescendantOf($this);
10431056
}
10441057

1058+
/**
1059+
* Get whether the node is itself or an ancestor of other node, including immediate parent.
1060+
*
1061+
* @param self $other
1062+
*
1063+
* @return bool
1064+
*/
1065+
public function isSelfOrAncestorOf(self $other)
1066+
{
1067+
return $other->isSelfOrDescendantOf($this);
1068+
}
1069+
10451070
/**
10461071
* Get whether the node has moved since last save.
10471072
*

0 commit comments

Comments
 (0)