From 14bae08bfc4550b57aede25b9850daeffc472143 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 25 Nov 2013 22:10:17 +0100 Subject: [PATCH] add method isSubFolder(), do not set parent if a child of the current folder --- SeedDMS_Core/Core/inc.ClassFolder.php | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/SeedDMS_Core/Core/inc.ClassFolder.php b/SeedDMS_Core/Core/inc.ClassFolder.php index e3937915b..6db03e2d7 100644 --- a/SeedDMS_Core/Core/inc.ClassFolder.php +++ b/SeedDMS_Core/Core/inc.ClassFolder.php @@ -149,13 +149,37 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $this->_parent; } /* }}} */ + /** + * Check if the folder is subfolder + * + * This function checks if the passed folder is a subfolder of the current + * folder. + * + * @param object $subFolder potential sub folder + * @return boolean true if passes folder is a subfolder + */ + function isSubFolder($subfolder) { /* {{{ */ + $db = $this->_dms->getDB(); + + $path = $this->getPath(); + $sfpath = $subfolder->getPath(); + /* It is a potential sub folder start with the path of the current folder. + * If the path differs, it can't be a sub folder. + */ + for($i=0; $i < count($path); $i++) { + if($path[$i] != $sfpath[$i]) + return false; + } + return true; + } /* }}} */ + /** * Set a new folder * * This function moves a folder from one parent folder into another parent * folder. It will fail if the root folder is moved. * - * @param object new parent folder + * @param object $newParent new parent folder * @return boolean true if operation was successful otherwise false */ function setParent($newParent) { /* {{{ */ @@ -165,6 +189,13 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return false; } + /* Check if the new parent is the folder to be moved or even + * a subfolder of that folder + */ + if($this->isSubFolder($newParent)) { + return false; + } + // Update the folderList of the folder $pathPrefix=""; $path = $newParent->getPath();