/** * Display a list of all categories * * @return void */ public function displayTask() { // Get filters $this->view->filters = array('state' => -1, 'access' => -1, 'object_type' => Request::getState($this->_option . '.' . $this->_controller . '.object_type', 'object_type', ''), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'title'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'state' => Request::getState($this->_option . '.' . $this->_controller . '.state', 'state', '-1'), '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 Archive(); // Get record count $this->view->filters['count'] = true; $this->view->total = $obj->collections($this->view->filters); // Get records $this->view->filters['count'] = false; $this->view->rows = $obj->collections($this->view->filters); // Output the HTML $this->view->display(); }
/** * Get a count for the specified key * * @param string $what Key name [following, followers, collectios, posts] * @return integer */ public function count($what = 'following') { $what = strtolower(trim($what)); $value = $this->get($what); switch ($what) { case 'following': if ($value === null) { $value = $this->_tbl->count(array('follower_type' => $this->get('following_type'), 'follower_id' => $this->get('following_id'))); $this->set($what, $value); } break; case 'followers': if ($value === null) { $value = $this->_tbl->count(array('following_type' => $this->get('following_type'), 'following_id' => $this->get('following_id'))); $this->set($what, $value); } break; case 'collections': if ($value === null && $this->get('following_type') != 'collection') { $model = Collections::getInstance($this->get('following_type'), $this->get('following_id')); $value = $model->collections(array('count')); $this->set($what, $value); } break; case 'posts': if ($value === null) { if ($this->get('following_type') != 'collection') { $model = Archive::getInstance($this->get('following_type'), $this->get('following_id')); $value = $model->posts(array('count')); $this->set($what, $value); } else { $model = Collection::getInstance($this->get('following_id')); $value = $model->posts(array('count')); $this->set($what, $value); } } break; } if ($value === null) { $value = 0; } return $value; }
/** * Display a list of collections * * @apiMethod GET * @apiUri /collections/list * @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 Archive(); $filters = array('limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'state' => 1, 'sort_Dir' => strtoupper(Request::getWord('sortDir', 'DESC')), 'is_default' => 0, 'access' => 0, 'count' => true); $response = new stdClass(); $response->collections = array(); $response->total = $model->collections($filters); if ($response->total) { $base = rtrim(Request::base(), '/'); $filters['count'] = false; foreach ($model->collections($filters) as $i => $entry) { $collection = Collection::getInstance($entry->item()->get('object_id')); $obj = $collection->toObject(); $obj->created_by = new stdClass(); $obj->created_by->id = $collection->get('created_by'); $obj->created_by->name = $collection->creator()->get('name'); $obj->url = str_replace('/api', '', $base . '/' . ltrim(Route::url($collection->link()), '/')); $response->collections[] = $obj; } } $this->send($response); }
/** * Repost an entry * * @return string */ public function collectTask() { if (User::isGuest()) { return $this->loginTask(); } $model = new Archive('member', User::get('id')); $no_html = Request::getInt('no_html', 0); // No collection ID selected so present repost form $repost = Request::getInt('repost', 0); if (!$repost) { // Incoming $post_id = Request::getInt('post', 0); $collection_id = Request::getVar('board', 0); if (!$post_id && $collection_id) { $collection = $model->collection($collection_id); $item_id = $collection->item()->get('id'); $collection_id = $collection->item()->get('object_id'); } else { $post = Post::getInstance($post_id); $item_id = $post->get('item_id'); } $this->view->myboards = $model->mine(); $this->view->groupboards = $model->mine('groups'); //$this->view->name = $this->_name; $this->view->option = $this->_option; $this->view->no_html = $no_html; $this->view->post_id = $post_id; $this->view->collection_id = $collection_id; $this->view->item_id = $item_id; $this->view->display(); return; } Request::checkToken(); $collection_title = Request::getVar('collection_title', ''); $collection_id = Request::getInt('collection_id', 0); $item_id = Request::getInt('item_id', 0); if ($collection_title) { $collection = new Collection(); $collection->set('title', $collection_title); $collection->set('object_id', User::get('id')); $collection->set('object_type', 'member'); if (!$collection->store()) { $this->setError($collection->getError()); } $collection_id = $collection->get('id'); } // Try loading the current collection/post to see // if this has already been posted to the collection (i.e., no duplicates) $post = new Tables\Post($this->database); $post->loadByBoard($collection_id, $item_id); if (!$post->get('id')) { // No record found -- we're OK to add one $post->item_id = $item_id; $post->collection_id = $collection_id; $post->description = Request::getVar('description', ''); if ($post->check()) { $this->setError($post->getError()); } // Store new content if (!$post->store()) { $this->setError($post->getError()); } } if ($this->getError()) { return $this->getError(); } // Display updated item stats if called via AJAX if ($no_html) { echo Lang::txt('COM_COLLECTIONS_NUM_REPOSTS', $post->getCount(array('item_id' => $post->get('item_id'), 'original' => 0))); exit; } // Display the main listing App::redirect(Route::url('index.php?option=' . $this->option . '&controller=collections&task=posts')); }
/** * Display information about collections * * @return void */ public function aboutTask() { // Filters for returning results $this->view->filters = array('id' => Request::getInt('id', 0), 'search' => Request::getVar('search', ''), 'sort' => 'p.created', 'state' => 1, 'access' => !User::isGuest() ? array(0, 1) : 0); if ($this->view->filters['id']) { $this->view->filters['object_type'] = 'site'; } $this->view->collection = new Collection(); $this->view->filters['count'] = true; $this->view->total = $this->view->collection->posts($this->view->filters); $model = Archive::getInstance(); $this->view->collections = $model->collections(array('count' => true, 'state' => 1, 'access' => !User::isGuest() ? array(0, 1) : 0)); $this->_buildTitle(); $this->_buildPathway(); $this->view->setLayout('about')->display(); }