From c0fabcd038ea63e4b2c4eaf07d20ba771cf1dc41 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 25 Feb 2003 15:19:09 +0000 Subject: [PATCH] Added function to get a folder's sub-folders --- lib/foldermanagement/Folder.inc | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/foldermanagement/Folder.inc b/lib/foldermanagement/Folder.inc index b8e675e..969f045 100644 --- a/lib/foldermanagement/Folder.inc +++ b/lib/foldermanagement/Folder.inc @@ -11,6 +11,8 @@ * @package lib.foldermanagement */ +require_once("$default->fileSystemRoot/lib/foldermanagement/PhysicalFolderManagement.inc"); + class Folder { /** folder primary key */ @@ -260,7 +262,11 @@ class Folder { function update($bPathChange) { global $default, $lang_err_database, $lang_err_object_key; //can only update the object if it has already been stored + $sOldPath; if ($this->iId >= 0) { + if ($bPathChange){ + $sOldPath = $default->documentRoot . "/" . $this->sFullPath . "/" . $this->sName; + } $sql = $default->db; $sQuery = "UPDATE " . $default->owl_folders_table . " SET " . "name = '" . addslashes($this->sName) . "', " . @@ -283,7 +289,8 @@ class Folder { if ($result) { if ($bPathChange) { //must update all the children paths - $this->updateChildrenPaths($this->iId, $sql); + $this->updateChildPaths($this->iId, $sql); + $this->renameFolder($sOldPath); } return true; } @@ -293,17 +300,46 @@ class Folder { $_SESSION["errorMessage"] = $lang_err_object_key; } - function updateChildrenPaths($iID, $sql) { + function renameFolder($sOldPath) { + PhysicalFolderManagement::renameFolder($sOldPath, $default->documentRoot . "/" . $this->sFullPath . "/" . $this->sName); + } + + /** + * When a folder is renamed, we must update + * the paths of the children in the database + * + */ + function updateChildPaths($iID, $sql) { global $default; $sql->query("SELECT id from $default->owl_folders_table WHERE parent_id = $iID"); while ($sql->next_record()) { $oFolder = Folder::get($sql->f("id")); $oFolder->update(true); - $this->updateChildrenPaths($sql->f("id"), $sql); + $this->updateChildPaths($sql->f("id"), $sql); } return; } + /** + * Get a folder's sub-folders + * + * @param int primary key of folder to get children for + * + * @return Array array of child ids + */ + function getChildren($iFolderID, $aChildren = array()) { + global $default; + $sql = $default->db; + $sql->query("SELECT id from $default->owl_folders_table WHERE parent_id = $iFolderID"); + while ($sql->next_record()) { + $aChildren[count($aChildren)] = $sql->f("id"); + Folder::getChildren($sql->f("id"), & $aChildren); + //$sChildString .= $sql->f("id") . "," . Folder::getChildren($sql->f("id")); + } + //return $sChildString; + return $aChildren; + } + /** * Delete the current object from the database -- libgit2 0.21.4