/** * Get all folders and files within a folder * * @param int $parent The id of this folder * @return array * **/ public function folderContents($parent = 0) { // ci()->load->library('keywords/Keywords'); // they can also pass a url hash such as #foo/bar/some-other-folder-slug if (!is_numeric($parent)) { $segment = explode('/', trim($parent, '/#')); $result = Folder::findBySlug(array_pop($segment))->first(); $parent = $result ? $result->id : 0; } $folders = Folder::findByParentBySort($parent)->toArray(); $files = File::findByFolderIdBySort($parent)->toArray(); // let's be nice and add a date in that's formatted like the rest of the CMS if ($folders) { foreach ($folders as &$folder) { $folder['file_count'] = File::findByFolderId($folder->id)->count(); } } if ($files) { foreach ($files as &$file) { $file['keywords_hash'] = $file->keywords; // $file['keywords'] = ci()->keywords->get_string($file->keywords); } } return $this->result(true, null, null, array('folder' => $folders, 'file' => $files, 'parent_id' => $parent)); }