Commit bd0bba87868d53066ec67f2cfb94e8e7e4ecc3d4

Authored by michael
1 parent 28f0b3ff

added methods to retrieve the folder path as an array, and to lookup the folder …

…id from the folder name


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@436 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 39 additions and 3 deletions
lib/foldermanagement/Folder.inc
... ... @@ -290,11 +290,30 @@ class Folder {
290 290 global $default;
291 291 //if the folder has a parent
292 292 if (Folder::getParentFolderID($iFolderID) != 0) {
293   - $sCurrentPath = Folder::getFolderPath(Folder::getParentFolderID($iFolderID), Folder::getFolderName($iFolderID)) . "/" . $sCurremtPath;
  293 + $sCurrentPath = Folder::getFolderPath(Folder::getParentFolderID($iFolderID), Folder::getFolderName($iFolderID)) . "/" . $sCurrentPath;
294 294 }
295 295 return $default->owl_FileDir . "/" . Folder::getFolderName($iFolderID);
296   -
297 296 }
  297 +
  298 + /**
  299 + * Static function.
  300 + * Get the full path for a folder as an array
  301 + *
  302 + * @param int primary key of folder to generate path for
  303 + *
  304 + * @return array full path of folder as an array
  305 + */
  306 + function getFolderPathAsArray($iFolderID) {
  307 + global $default;
  308 + //if the folder has a parent
  309 + if (Folder::getParentFolderID($iFolderID) != 0) {
  310 + $aPathArray = Folder::getFolderPathAsArray(Folder::getParentFolderID($iFolderID));
  311 + $aPathArray[] = Folder::getFolderName($iFolderID);
  312 + } else {
  313 + $aPathArray[] = Folder::getFolderName($iFolderID);
  314 + }
  315 + return $aPathArray;
  316 + }
298 317  
299 318 /**
300 319 * Static function
... ... @@ -377,7 +396,7 @@ class Folder {
377 396 /**
378 397 * Get the folder name using the primary key
379 398 *
380   - * @param $iFolderID Primary key of folder to get name for
  399 + * @param int primary key of folder to get name for
381 400 *
382 401 * @return String name on success, false otherwise and set $_SESSION["errorMessage"]
383 402 */
... ... @@ -392,6 +411,23 @@ class Folder {
392 411 return false;
393 412 }
394 413  
  414 + /**
  415 + * Get the folder id using the folder name
  416 + *
  417 + * @param string the name of the folder to get the ID for
  418 + *
  419 + * @return int name on success, false otherwise and set $_SESSION["errorMessage"]
  420 + */
  421 + function getFolderID($sFolderName) {
  422 + global $default, $lang_err_database;
  423 + $sql = new Owl_DB();
  424 + $sql->query("SELECT id FROM " . $default->owl_folders_table . " WHERE name = '" . addslashes($sFolderName) . "'");
  425 + if ($sql->next_record()) {
  426 + return $sql->f("id");
  427 + }
  428 + $_SESSION["errorMessage"] = $lang_err_database;
  429 + return false;
  430 + }
395 431 }
396 432  
397 433 ?>
... ...