Пример #1
0
 public function getList()
 {
     if (!isset($this->_list)) {
         $state = $this->_state;
         $state->basepath = rtrim(str_replace('\\', '/', $state->basepath), '\\');
         $path = $state->basepath;
         if (!empty($state->folder) && $state->folder != '/') {
             $path .= '/' . ltrim($state->folder, '/');
         }
         if (!$state->basepath || !is_dir($path)) {
             throw new KModelException('Basepath is not a valid folder');
         }
         if (!empty($state->path)) {
             $folders = array();
             foreach ((array) $state->path as $path) {
                 $folders[] = $path;
             }
         } else {
             $folders = ComFilesIteratorDirectory::getFolders(array('path' => $path, 'recurse' => !!$state->tree, 'filter' => array($this, 'iteratorFilter'), 'map' => array($this, 'iteratorMap')));
         }
         $this->_total = count($folders);
         $folders = array_slice($folders, $state->offset, $state->limit ? $state->limit : $this->_total);
         if (strtolower($this->_state->direction) == 'desc') {
             $folders = array_reverse($folders);
         }
         $results = array();
         foreach ($folders as $folder) {
             $hier = array();
             if ($state->tree) {
                 $hier = explode('/', dirname($folder));
                 if (count($hier) === 1 && $hier[0] === '.') {
                     $hier = array();
                 }
             }
             $results[] = array('basepath' => $state->basepath, 'path' => $folder, 'hierarchy' => $hier);
         }
         $rowset = $this->getService('com://admin/files.database.rowset.folders');
         $rowset->addData($results);
         $this->_list = $rowset;
     }
     return parent::getList();
 }