KickAssets::handleFolderContents PHP Méthode

handleFolderContents() public méthode

Gets the contents of a folder, and applies a sort. Splits the response into folder metadata and folder children
public handleFolderContents ( SS_HTTPRequest $r ) : SS_HTTPResponse
$r SS_HTTPRequest
Résultat SS_HTTPResponse
    public function handleFolderContents(SS_HTTPRequest $r)
    {
        if (!$r->param('FolderID')) {
            $folder = Injector::inst()->get('Folder');
            $folder->Filename = ASSETS_DIR;
        } else {
            $folder = Folder::get()->byID($r->param('FolderID'));
        }
        if (!$folder) {
            return $this->httpError(404, 'That folder does not exist');
        }
        $cursor = (int) $r->getVar('cursor');
        $result = array('folder' => $this->createFolderJSON($folder), 'breadcrumbs' => $this->createBreadcrumbJSON($folder), 'children' => array());
        $files = File::get()->filter(array('ParentID' => $folder->ID))->sort($this->getSortClause($r->getVar('sort')));
        $totalFiles = (int) $files->count();
        $files = $files->limit($this->config()->folder_items_limit, $cursor);
        foreach ($files as $file) {
            if (!$file->canView()) {
                continue;
            }
            $result['children'][] = $file instanceof Folder ? $this->createFolderJSON($file) : $this->createFileJSON($file, $folder);
        }
        $cursor += $files->count();
        $result['cursor'] = $cursor;
        $result['has_more'] = $cursor < $totalFiles;
        $result['total_items'] = $totalFiles;
        return (new SS_HTTPResponse(Convert::array2json($result), 200))->addHeader('Content-Type', 'application/json');
    }