* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * HUBzero is a registered trademark of Purdue University. * * @package hubzero-cms * @author Shawn Rice <*****@*****.**> * @copyright Copyright 2005-2015 HUBzero Foundation, LLC. * @license http://opensource.org/licenses/MIT MIT */ // No direct access defined('_HZEXEC_') or die; if ($this->row instanceof \Components\Collections\Models\Collection) { $collection = $this->row; } else { $collection = \Components\Collections\Models\Collection::getInstance($this->row->item()->get('object_id')); if ($this->row->get('description')) { $collection->set('description', $this->row->get('description')); } } ?> <h4<?php if ($collection->get('access', 0) == 4) { echo ' class="private"'; } ?> > <a href="<?php echo Route::url($collection->link()); ?> ">
/** * 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); }
/** * Display a list of posts for all collections * * @return string */ private function _posts() { $view = $this->view('default', 'collection'); $view->name = $this->_name; $view->group = $this->group; $view->option = $this->option; $view->params = $this->params; $view->model = $this->model; // Filters for returning results $view->filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'state' => 1, 'object_type' => 'group', 'object_id' => $this->group->get('gidNumber'), 'user_id' => User::get('id'), 'sort' => 'created', 'sort_Dir' => 'desc'); // Filters for returning results $count = array('count' => true); if (!$this->params->get('access-manage-collection')) { $view->filters['access'] = User::isGuest() ? 0 : array(0, 1); if (in_array(User::get('id'), $this->group->get('members'))) { $view->filters['access'] = array(0, 1, 4); } $count['access'] = $view->filters['access']; } if ($this->authorized) { $count['access'] = -1; $view->filters['access'] = -1; } $view->collections = $this->model->collections($count); $view->posts = $this->model->posts($count); $view->followers = $this->model->followers($count); if ($this->params->get('access-can-follow')) { $view->following = $this->model->following($count); } $view->collection = \Components\Collections\Models\Collection::getInstance(); //$view->filters['user_id'] = User::get('id'); $view->count = $view->posts; $view->rows = $view->collection->posts($view->filters); $view->scope = 'posts'; foreach ($this->getErrors() as $error) { $view->setError($error); } return $view->loadTemplate(); }
/** * Display a list of items in a collection * * @return string */ private function _posts() { $view = $this->view('default', 'collection'); $view->name = $this->_name; $view->member = $this->member; $view->option = $this->option; $view->params = $this->params; $view->model = $this->model; // Filters for returning results $view->filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'created_by' => $this->member->get('uidNumber'), 'search' => Request::getVar('search', ''), 'state' => 1, 'object_id' => $this->member->get('uidNumber'), 'object_type' => 'member', 'access' => -1, 'sort' => 'created', 'sort_Dir' => 'desc'); // Filters for returning results //$filters = array(); $count = array('count' => true); if (!$this->params->get('access-manage-collection')) { $view->filters['access'] = User::isGuest() ? 0 : array(0, 1); $count['access'] = $view->filters['access']; } $view->collections = $this->model->collections($count); $view->followers = $this->model->followers($count); $view->following = $this->model->following($count); $view->posts = $this->model->posts($count); $view->total = $view->posts; $view->collection = \Components\Collections\Models\Collection::getInstance(); $view->filters['user_id'] = $this->member->get('uidNumber'); $view->rows = $view->collection->posts($view->filters); $view->task = 'posts'; foreach ($this->getErrors() as $error) { $view->setError($error); } return $view->loadTemplate(); }
/** * Set and get a specific collection * * @param mixed $id * @return object */ public function collection($id = null) { // If the current offering isn't set // OR the ID passed doesn't equal the current offering's ID or alias if (!isset($this->_collection) || $id !== null && (int) $this->_collection->get('id') != $id && (string) $this->_collection->get('alias') != $id) { // Reset current offering $this->_collection = null; // If the list of all offerings is available ... if ($this->_collections instanceof ItemList) { // Find an offering in the list that matches the ID passed foreach ($this->collections() as $key => $collection) { if ((int) $collection->get('id') == $id || (string) $collection->get('alias') == $id) { // Set current offering $this->_collection = $collection; break; } } } if (!$this->_collection) { $this->_collection = Collection::getInstance($id, $this->_object_id, $this->_object_type); } } // Return current offering return $this->_collection; }