Exemplo n.º 1
0
 function getGroups()
 {
     $group = new User_group();
     // Disable this to get global group searches
     $group->joinAdd(array('id', 'local_group:group_id'));
     $order = false;
     if (!empty($this->q)) {
         $wheres = array('nickname', 'fullname', 'homepage', 'description', 'location');
         foreach ($wheres as $where) {
             // Double % because of sprintf
             $group->whereAdd(sprintf('LOWER(%1$s.%2$s) LIKE LOWER("%%%3$s%%")', $group->escapedTableName(), $where, $group->escape($this->q)), 'OR');
         }
         $order = sprintf('%1$s.%2$s %3$s', $group->escapedTableName(), $this->getSortKey('created'), $this->reverse ? 'DESC' : 'ASC');
     } else {
         // User is browsing via AlphaNav
         switch ($this->filter) {
             case 'all':
                 // NOOP
                 break;
             case '0-9':
                 $group->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s', $group->escapedTableName(), 'nickname', $group->_quote("0"), $group->_quote("9")));
                 break;
             default:
                 $group->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s', $group->escapedTableName(), 'nickname', $group->_quote($this->filter)));
         }
         $order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC', $group->escapedTableName(), $this->getSortKey('nickname'), $this->reverse ? 'DESC' : 'ASC', 'nickname');
     }
     $offset = ($this->page - 1) * PROFILES_PER_PAGE;
     $limit = PROFILES_PER_PAGE + 1;
     $group->selectAdd();
     $group->selectAdd('profile_id');
     $group->orderBy($order);
     $group->limit($offset, $limit);
     $group->find();
     return Profile::multiGet('id', $group->fetchAll('profile_id'));
 }
Exemplo n.º 2
0
 function showContent()
 {
     $this->elementStart('p', array('id' => 'new_group'));
     $this->element('a', array('href' => common_local_url('newgroup'), 'class' => 'more'), _('Create a new group'));
     $this->elementEnd('p');
     $offset = ($this->page - 1) * GROUPS_PER_PAGE;
     $limit = GROUPS_PER_PAGE + 1;
     $groups = new User_group();
     $groups->orderBy('created DESC');
     $groups->limit($offset, $limit);
     if ($groups->find()) {
         $gl = new GroupList($groups, null, $this);
         $cnt = $gl->show();
     }
     $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE, $this->page, 'groups');
 }