From eed57674f99621e5354a13543067e9556eb9c6d0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 24 Jan 2009 05:14:44 +0000 Subject: Add move support. Use the move icon in the quick pane. You can't move an item into its own hierarchy, or into an album where you don't have edit permission. --- core/libraries/ORM_MPTT.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'core/libraries') 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 @@ -102,6 +102,15 @@ class ORM_MPTT_Core extends ORM { parent::delete(); } + /** + * 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 * @@ -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; -- cgit v1.2.3