summaryrefslogtreecommitdiff
path: root/core/libraries/ORM_MPTT.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/libraries/ORM_MPTT.php')
-rw-r--r--core/libraries/ORM_MPTT.php14
1 files changed, 14 insertions, 0 deletions
diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php
index e8411db0..e67478a7 100644
--- a/core/libraries/ORM_MPTT.php
+++ b/core/libraries/ORM_MPTT.php
@@ -103,6 +103,15 @@ class ORM_MPTT_Core extends ORM {
}
/**
+ * Return true if the target is descendant of this item.
+ * @param ORM $target
+ * @return boolean
+ */
+ function is_descendant($target) {
+ return ($this->left <= $target->left && $this->right >= $target->right);
+ }
+
+ /**
* Return the parent of this node
*
* @return ORM
@@ -203,6 +212,11 @@ class ORM_MPTT_Core extends ORM {
throw new Exception("@todo INVALID_SOURCE root album");
}
+ if ($this->left <= $target->left &&
+ $this->right >= $target->right) {
+ throw new Exception("@todo INVALID_TARGET can't move item inside itself");
+ }
+
$number_to_move = (int)(($this->right - $this->left) / 2 + 1);
$size_of_hole = $number_to_move * 2;
$original_left = $this->left;