/** * Get a count or list of posts * * @param array $filters Filters to apply to the query that retrieves records * @return mixed Integer or array */ public function posts($filters = array()) { $filters['object_id'] = $this->_object_id; $filters['object_type'] = $this->_object_type; if (!isset($filters['state'])) { $filters['state'] = 1; } if (isset($filters['count']) && $filters['count']) { $tbl = new Tables\Post($this->_db); return $tbl->getCount($filters); } $tbl = new Tables\Post($this->_db); return $tbl->getRecords($filters); }
/** * 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')); }
/** * Get a list of posts in this collection * Accepts an array of filters for database query * that retrieves results * * @param array $filters Filters to apply * @param boolean $clear Clear cached data? * @return mixed Integer or object */ public function posts($filters = array(), $clear = false) { if (!isset($filters['collection_id'])) { $filters['collection_id'] = $this->get('id'); } if (!isset($filters['state'])) { $filters['state'] = self::APP_STATE_PUBLISHED; } if (!isset($filters['access'])) { $filters['access'] = User::isGuest() ? 0 : array(0, 1); } if (!isset($filters['sort'])) { if ($sort = $this->get('sort', 'created')) { $filters['sort'] = 'p.' . $sort; } $filters['sort_Dir'] = $this->get('sort', 'created') == 'ordering' ? 'asc' : 'desc'; } if (isset($filters['count']) && $filters['count']) { $tbl = new Tables\Post($this->_db); return $tbl->getCount($filters); } if (!isset($this->_posts) || !$this->_posts instanceof ItemList) { $tbl = new Tables\Post($this->_db); if ($results = $tbl->getRecords($filters)) { $ids = array(); foreach ($results as $key => $result) { $ids[] = $result->item_id; } // Get all the assets for this list of items $ba = new Tables\Asset($this->_db); $assets = $ba->getRecords(array('item_id' => $ids)); // Get all the tags for this list of items $bt = new Tags(); $tags = $bt->getTagsForIds($ids); // Loop through all the items and push assets and tags foreach ($results as $key => $result) { $results[$key] = new Post($result); if ($assets) { foreach ($assets as $asset) { if ($asset->item_id == $results[$key]->get('item_id')) { $results[$key]->item()->addAsset($asset); } else { $results[$key]->item()->addAsset(null); } } } else { $results[$key]->item()->addAsset(null); } if (isset($tags[$results[$key]->get('item_id')])) { $results[$key]->item()->addTag($tags[$results[$key]->get('item_id')]); } else { $results[$key]->item()->addTag(null); } } } else { $results = array(); } $this->_posts = new ItemList($results); } return $this->_posts; }