public function getList() { if (!isset($this->_list)) { $state = $this->_state; $folders = $state->container->getAdapter('iterator')->getFolders(array('path' => $this->_getPath(), 'recurse' => !!$state->tree, 'filter' => array($this, 'iteratorFilter'), 'map' => array($this, 'iteratorMap'))); if ($folders === false) { throw new KModelException('Invalid folder'); } $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) { $hierarchy = array(); if ($state->tree) { $hierarchy = explode('/', dirname($folder)); if (count($hierarchy) === 1 && $hierarchy[0] === '.') { $hierarchy = array(); } } $results[] = array('container' => $state->container, 'folder' => $hierarchy ? implode('/', $hierarchy) : $state->folder, 'name' => basename($folder), 'hierarchy' => $hierarchy); } $this->_list = $this->getRowset()->addData($results); } return parent::getList(); }
public function getList() { if (!isset($this->_list)) { $state = $this->_state; $files = $state->container->getAdapter('iterator')->getFiles(array('path' => $this->_getPath(), 'exclude' => array('.svn', '.htaccess', '.git', 'CVS', 'index.html', '.DS_Store', 'Thumbs.db', 'Desktop.ini'), 'filter' => array($this, 'iteratorFilter'), 'map' => array($this, 'iteratorMap'))); if ($files === false) { throw new KModelException('Invalid folder'); } $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, 'folder' => $state->folder, 'name' => $file); } $this->_list = $this->getRowset(array('data' => $data)); } return parent::getList(); }
/** * Returns the current container row * * @return ComFilesModelEntityContainer * @throws UnexpectedValueException */ public function getContainer() { if (!isset(self::$_container)) { //Set the container $container = $this->getObject('com:files.model.containers')->slug($this->getState()->container)->fetch(); if (!is_object($container) || !count($container) || $container->isNew()) { throw new UnexpectedValueException('Invalid container: ' . $this->getState()->container); } self::$_container = $container->top(); } return self::$_container; }
public function __construct(KObjectConfig $config) { parent::__construct($config); $this->getState()->insert('tree', 'boolean', false); }