public function getList() { if (!isset($this->_list)) { $state = $this->_state; $type = !empty($state->types) ? (array) $state->types : array(); $list = $this->getService('com://admin/files.database.rowset.nodes'); // Special case for limit=0. We set it to -1 // so loop goes on till end since limit is a negative value $limit_left = $state->limit ? $state->limit : -1; $offset_left = $state->offset; $total = 0; if (empty($type) || in_array('folder', $type)) { $folders = $this->getService('com://admin/files.model.folders')->set($state->getData())->getList(); foreach ($folders as $folder) { if (!$limit_left) { break; } if ($offset_left) { $offset_left--; continue; } $list->insert($folder); $limit_left--; } $total += count($folders); } if (empty($type) || (in_array('file', $type) || in_array('image', $type))) { $files = $this->getService('com://admin/files.model.files')->set($state->getData())->getList(); foreach ($files as $file) { if (!$limit_left) { break; } if ($offset_left) { $offset_left--; continue; } $list->insert($file); $limit_left--; } $total += count($files); } $this->_total = $total; //$list = array_slice($list, $state->offset, $state->limit ? $state->limit : $this->_total); $this->_list = $list; } return parent::getList(); }
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(); }
public function getList() { if (!isset($this->_list)) { $state = $this->_state; if (!$state->basepath) { throw new KModelException('Basepath is not a valid folder'); } $basepath = $state->basepath; $path = $basepath; if (!empty($state->folder) && $state->folder != '/') { $path .= '/' . ltrim($state->folder, '/'); } if (!is_dir($path)) { throw new KModelException('Basepath is not a valid folder'); } $name = $state->path ? $state->path : null; if (is_string($name)) { $files[] = $name; } else { if (is_array($name)) { $files = array(); foreach ($name as $n) { $files[] = $n; } } else { $files = ComFilesIteratorDirectory::getFiles(array('path' => $path, 'exclude' => array('.svn', '.htaccess', '.git', 'CVS', 'index.html', '.DS_Store', 'Thumbs.db', 'Desktop.ini'), 'filter' => array($this, 'iteratorFilter'), 'map' => array($this, 'iteratorMap'))); } } $this->_total = count($files); $files = array_slice($files, $state->offset, $state->limit ? $state->limit : $this->_total); if (strtolower($this->_state->direction) == 'desc') { $files = array_reverse($files); } $data = array(); foreach ($files as $file) { $data[] = array('container' => $state->container, 'basepath' => $basepath, 'path' => $file); } $this->_list = $this->getService('com://admin/files.database.rowset.files', array('data' => $data)); } return parent::getList(); }