Beispiel #1
0
 /**
  * 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;
     }
 }
Beispiel #2
0
 /**
  * Get a list of collections for a user
  *
  * - If no type or type='member', returns an array of collections
  *   that user created.
  * - If type='group', returns an array of collections in the groups
  *   the user is a member of.
  *
  * @param   string $type What type ot get collections for [group, member]
  * @return  array
  */
 public function mine($type = '')
 {
     $user = User::getInstance();
     $tbl = new Tables\Collection($this->_db);
     switch (strtolower(trim($type))) {
         case 'group':
         case 'groups':
             $collections = array();
             $usergroups = $user->groups('members');
             $usergroups_manager = $user->groups('managers');
             if ($usergroups) {
                 if ($usergroups_manager) {
                     foreach ($usergroups_manager as $manager_group) {
                         foreach ($usergroups as $user_group) {
                             if ($user_group->gidNumber == $manager_group->gidNumber) {
                                 $user_group->manager = $manager_group->manager;
                             }
                         }
                     }
                 }
                 foreach ($usergroups as $usergroup) {
                     $groups = $tbl->getRecords(array('object_type' => 'group', 'object_id' => $usergroup->gidNumber, 'state' => 1));
                     if ($groups) {
                         if (!isset($usergroup->params) || !is_object($usergroup->params)) {
                             $usergroup->params = Params::getCustomParams($usergroup->gidNumber, 'groups', 'collections');
                         }
                         foreach ($groups as $s) {
                             if (!isset($collections[$s->group_alias])) {
                                 $collections[$s->group_alias] = array();
                             }
                             if ($usergroup->params->get('create_post', 0) == 1 && !$usergroup->manager) {
                                 continue;
                             }
                             /*if ($s->access == 4 && !$usergroup->manager)
                             		{
                             			continue;
                             		}*/
                             $collections[$s->group_alias][] = $s;
                             asort($collections[$s->group_alias]);
                         }
                     }
                 }
             }
             asort($collections);
             break;
         case 'member':
         default:
             $collections = $tbl->getRecords(array('object_type' => 'member', 'object_id' => $user->get('id'), 'state' => 1));
             break;
     }
     return $collections;
 }