Esempio n. 1
0
 /**
  * Folder Tree
  *
  * Get folder in an array
  *
  * @uses folder_subtree
  */
 public function folderTreeRecursive($parent_id = 0, $depth = 0, &$arr = array())
 {
     $arr = $arr ? $arr : array();
     if ($parent_id === 0) {
         $arr = array();
         $depth = 0;
     }
     $folders = Folder::findByParentAndSortByName($parent_id);
     if (!$folders) {
         return $arr;
     }
     $root = null;
     foreach ($folders as $folder) {
         if ($depth < 1) {
             $root = $folder->id;
         }
         //			$folder->name_indent		= repeater('&raquo; ', $depth) . $folder->name;
         $folder->root_id = $root;
         $folder->depth = $depth;
         $folder->count_files = count($folder->files);
         $arr[$folder->id] = $folder;
         $old_size = sizeof($arr);
         static::folderTreeRecursive($folder->id, $depth + 1, $arr);
         $folder->count_subfolders = sizeof($arr) - $old_size;
     }
     if ($parent_id === 0) {
         foreach ($arr as $id => &$folder) {
             $folder->virtual_path = static::_buildAscSegments($id, array('segments' => $arr, 'separator' => '/', 'attribute' => 'slug'));
         }
         $this->_folders = $arr;
     }
     if ($parent_id > 0 && $depth < 1) {
         foreach ($arr as $id => &$folder) {
             $folder->virtual_path = $this->_folders[$id]->virtual_path;
         }
     }
     return $arr;
 }