/** * Display a list of all categories * * @return void */ public function displayTask() { // Get filters $this->view->filters = array('state' => -1, 'access' => -1, 'collection_id' => Request::getState($this->_option . '.' . $this->_controller . '.collection_id', 'collection_id', 0, 'int'), 'item_id' => Request::getState($this->_option . '.' . $this->_controller . '.item_id', 'item_id', 0, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int')); $obj = new Collection($this->view->filters['collection_id']); // Get record count $this->view->filters['count'] = true; $this->view->total = $obj->posts($this->view->filters); // Get records $this->view->filters['count'] = false; $this->view->rows = $obj->posts($this->view->filters); // Output the HTML $this->view->display(); }
/** * Display posts for a collection * * @apiMethod GET * @apiUri /collections/{id}/posts * @apiParameter { * "name": "collection_id", * "description": "Collection identifier", * "type": "integer", * "required": true, * "default": null * } * @apiParameter { * "name": "limit", * "description": "Number of result to return.", * "type": "integer", * "required": false, * "default": 25 * } * @apiParameter { * "name": "start", * "description": "Number of where to start returning results.", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "search", * "description": "A word or phrase to search for.", * "type": "string", * "required": false, * "default": "" * } * @apiParameter { * "name": "sort", * "description": "Field to sort results by.", * "type": "string", * "required": false, * "default": "created", * "allowedValues": "created, ordering" * } * @apiParameter { * "name": "sort_Dir", * "description": "Direction to sort results by.", * "type": "string", * "required": false, * "default": "desc", * "allowedValues": "asc, desc" * } * @return void */ public function listTask() { $model = new Collection(); $filters = array('collection_id' => Request::getInt('collection_id', -1), 'limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'state' => 1, 'sort' => Request::getVar('sort', 'created'), 'sort_Dir' => strtoupper(Request::getWord('sortDir', 'DESC')), 'is_default' => 0, 'access' => 0, 'count' => true); $filters['sort'] = 'p.' . $filters['sort']; $response = new stdClass(); $response->posts = array(); $response->total = $model->posts($filters); if ($response->total) { $href = 'index.php?option=com_collections&controller=media&post='; $base = rtrim(Request::base(), '/'); $filters['count'] = false; foreach ($model->posts($filters) as $i => $entry) { $item = $entry->item(); $obj = new stdClass(); $obj->id = $entry->get('id'); $obj->title = $entry->get('title', $item->get('title')); $obj->type = $item->get('type'); $obj->posted = $entry->get('created'); $obj->author = $entry->creator()->get('name'); $obj->uri = str_replace('/api', '', $base . '/' . ltrim(Route::url($entry->link()), '/')); $obj->tags = $item->tags('string'); $obj->comments = $item->get('comments', 0); $obj->likes = $item->get('positive', 0); $obj->reposts = $item->get('reposts', 0); $obj->assets = array(); $assets = $item->assets(); if ($assets->total() > 0) { foreach ($assets as $asset) { $a = new stdClass(); $a->title = ltrim($asset->get('filename'), '/'); $a->description = $asset->get('description'); $a->url = $asset->get('type') == 'link' ? $asset->get('filename') : $base . '/' . ltrim(Route::url($href . $entry->get('id') . '&task=download&file=' . $a->title), '/'); $obj->assets[] = $a; } } $response->posts[] = $obj; } } $this->send($response); }