File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -327,6 +327,12 @@ To check whether the node is root:
327327$bool = $node->isRoot();
328328```
329329
330+ Other checks:
331+
332+ * ` $node->isChildOf($other); `
333+ * ` $node->isAncestorOf($other); `
334+ * ` $node->isSiblingOf($other); `
335+
330336### Checking consistency
331337
332338You can check whether a tree is broken (i.e. has some structural errors):
Original file line number Diff line number Diff line change @@ -1035,6 +1035,42 @@ public function isDescendantOf(Node $other)
10351035 return $ this ->getLft () > $ other ->getLft () and $ this ->getLft () < $ other ->getRgt ();
10361036 }
10371037
1038+ /**
1039+ * Get whether the node is immediate children of other node.
1040+ *
1041+ * @param Node $other
1042+ *
1043+ * @return bool
1044+ */
1045+ public function isChildOf (Node $ other )
1046+ {
1047+ return $ this ->getParentId () == $ other ->getKey ();
1048+ }
1049+
1050+ /**
1051+ * Get whether the node is a sibling of another node.
1052+ *
1053+ * @param Node $other
1054+ *
1055+ * @return bool
1056+ */
1057+ public function isSiblingOf (Node $ other )
1058+ {
1059+ return $ this ->getParentId () == $ other ->getParentId ();
1060+ }
1061+
1062+ /**
1063+ * Get whether the node is an ancestor of other node, including immediate parent.
1064+ *
1065+ * @param Node $other
1066+ *
1067+ * @return bool
1068+ */
1069+ public function isAncestorOf (Node $ other )
1070+ {
1071+ return $ other ->isDescendantOf ($ this );
1072+ }
1073+
10381074 /**
10391075 * Get statistics of errors of the tree.
10401076 *
You can’t perform that action at this time.
0 commit comments