Commit c0fabcd038ea63e4b2c4eaf07d20ba771cf1dc41
1 parent
ababedba
Added function to get a folder's sub-folders
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1105 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
39 additions
and
3 deletions
lib/foldermanagement/Folder.inc
| ... | ... | @@ -11,6 +11,8 @@ |
| 11 | 11 | * @package lib.foldermanagement |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | +require_once("$default->fileSystemRoot/lib/foldermanagement/PhysicalFolderManagement.inc"); | |
| 15 | + | |
| 14 | 16 | class Folder { |
| 15 | 17 | |
| 16 | 18 | /** folder primary key */ |
| ... | ... | @@ -260,7 +262,11 @@ class Folder { |
| 260 | 262 | function update($bPathChange) { |
| 261 | 263 | global $default, $lang_err_database, $lang_err_object_key; |
| 262 | 264 | //can only update the object if it has already been stored |
| 265 | + $sOldPath; | |
| 263 | 266 | if ($this->iId >= 0) { |
| 267 | + if ($bPathChange){ | |
| 268 | + $sOldPath = $default->documentRoot . "/" . $this->sFullPath . "/" . $this->sName; | |
| 269 | + } | |
| 264 | 270 | $sql = $default->db; |
| 265 | 271 | $sQuery = "UPDATE " . $default->owl_folders_table . " SET " . |
| 266 | 272 | "name = '" . addslashes($this->sName) . "', " . |
| ... | ... | @@ -283,7 +289,8 @@ class Folder { |
| 283 | 289 | if ($result) { |
| 284 | 290 | if ($bPathChange) { |
| 285 | 291 | //must update all the children paths |
| 286 | - $this->updateChildrenPaths($this->iId, $sql); | |
| 292 | + $this->updateChildPaths($this->iId, $sql); | |
| 293 | + $this->renameFolder($sOldPath); | |
| 287 | 294 | } |
| 288 | 295 | return true; |
| 289 | 296 | } |
| ... | ... | @@ -293,17 +300,46 @@ class Folder { |
| 293 | 300 | $_SESSION["errorMessage"] = $lang_err_object_key; |
| 294 | 301 | } |
| 295 | 302 | |
| 296 | - function updateChildrenPaths($iID, $sql) { | |
| 303 | + function renameFolder($sOldPath) { | |
| 304 | + PhysicalFolderManagement::renameFolder($sOldPath, $default->documentRoot . "/" . $this->sFullPath . "/" . $this->sName); | |
| 305 | + } | |
| 306 | + | |
| 307 | + /** | |
| 308 | + * When a folder is renamed, we must update | |
| 309 | + * the paths of the children in the database | |
| 310 | + * | |
| 311 | + */ | |
| 312 | + function updateChildPaths($iID, $sql) { | |
| 297 | 313 | global $default; |
| 298 | 314 | $sql->query("SELECT id from $default->owl_folders_table WHERE parent_id = $iID"); |
| 299 | 315 | while ($sql->next_record()) { |
| 300 | 316 | $oFolder = Folder::get($sql->f("id")); |
| 301 | 317 | $oFolder->update(true); |
| 302 | - $this->updateChildrenPaths($sql->f("id"), $sql); | |
| 318 | + $this->updateChildPaths($sql->f("id"), $sql); | |
| 303 | 319 | } |
| 304 | 320 | return; |
| 305 | 321 | } |
| 306 | 322 | |
| 323 | + /** | |
| 324 | + * Get a folder's sub-folders | |
| 325 | + * | |
| 326 | + * @param int primary key of folder to get children for | |
| 327 | + * | |
| 328 | + * @return Array array of child ids | |
| 329 | + */ | |
| 330 | + function getChildren($iFolderID, $aChildren = array()) { | |
| 331 | + global $default; | |
| 332 | + $sql = $default->db; | |
| 333 | + $sql->query("SELECT id from $default->owl_folders_table WHERE parent_id = $iFolderID"); | |
| 334 | + while ($sql->next_record()) { | |
| 335 | + $aChildren[count($aChildren)] = $sql->f("id"); | |
| 336 | + Folder::getChildren($sql->f("id"), & $aChildren); | |
| 337 | + //$sChildString .= $sql->f("id") . "," . Folder::getChildren($sql->f("id")); | |
| 338 | + } | |
| 339 | + //return $sChildString; | |
| 340 | + return $aChildren; | |
| 341 | + } | |
| 342 | + | |
| 307 | 343 | |
| 308 | 344 | /** |
| 309 | 345 | * Delete the current object from the database | ... | ... |