/** * Get a counr or list of collections this item can be found in * * @param string $what What to return? * @param array $filters Filters to apply * @param boolean $clear Clear cached results? * @return mixed */ public function collections($what = 'list', $filters = array(), $clear = false) { if (!isset($filters['item_id'])) { $filters['item_id'] = $this->get('id'); } if (!isset($filters['state'])) { $filters['state'] = self::APP_STATE_PUBLISHED; } if (!isset($filters['access'])) { $filters['access'] = !User::isGuest() ? array(0, 1) : 0; } switch (strtolower($what)) { case 'count': if (!isset($this->_cache['collections.count']) || $clear) { $tbl = new Tables\Collection($this->_db); $this->_cache['collections.count'] = $tbl->getCount($filters); } return $this->_cache['collections.count']; break; case 'list': case 'results': default: if (!$this->_cache['collections.list'] instanceof ItemList || $clear) { $tbl = new Tables\Collection($this->_db); if ($results = $tbl->getRecords($filters)) { foreach ($results as $key => $result) { $results[$key] = new Collection($result); } } else { $results = array(); } $this->_cache['collections.list'] = new ItemList($results); } return $this->_cache['collections.list']; break; } }
/** * Get a count or list of collections * * @param array $filters Filters to apply to the query that retrieves records * @return mixed Integer or object */ public function collections($filters = array()) { if ($this->_object_id) { $filters['object_id'] = $this->_object_id; } if ($this->_object_type) { $filters['object_type'] = $this->_object_type; } if (!isset($filters['state'])) { $filters['state'] = 1; } if (isset($filters['count']) && $filters['count']) { $tbl = new Tables\Collection($this->_db); return $tbl->getCount($filters); } if (!$this->_collections instanceof ItemList) { $tbl = new Tables\Collection($this->_db); if ($results = $tbl->getRecords($filters)) { // Loop through all the items and push assets and tags foreach ($results as $key => $result) { $results[$key] = new Collection($result); } } $this->_collections = new ItemList($results); } return $this->_collections; }