コード例 #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'));
 }