GroupdirectoryAction now has no direct SQL queries
also various fixes uppers
This commit is contained in:
parent
94e19e1ac6
commit
e64ac4c418
|
@ -275,69 +275,59 @@ class GroupdirectoryAction extends ManagedAction
|
||||||
{
|
{
|
||||||
$group = new User_group();
|
$group = new User_group();
|
||||||
|
|
||||||
$offset = ($this->page-1) * PROFILES_PER_PAGE;
|
|
||||||
$limit = PROFILES_PER_PAGE + 1;
|
|
||||||
|
|
||||||
if (!empty($this->q)) {
|
|
||||||
|
|
||||||
// Disable this to get global group searches
|
// Disable this to get global group searches
|
||||||
$group->joinAdd(array('id', 'local_group:group_id'));
|
$group->joinAdd(array('id', 'local_group:group_id'));
|
||||||
|
|
||||||
|
$order = false;
|
||||||
|
|
||||||
|
if (!empty($this->q)) {
|
||||||
$wheres = array('nickname', 'fullname', 'homepage', 'description', 'location');
|
$wheres = array('nickname', 'fullname', 'homepage', 'description', 'location');
|
||||||
foreach ($wheres as $where) {
|
foreach ($wheres as $where) {
|
||||||
$group->whereAdd("LOWER({$group->__table}.{$where}) LIKE LOWER('%".$group->escape($this->q)."%')", 'OR');
|
// 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 = "{$group->__table}.created ASC";
|
$order = sprintf('%1$s.%2$s %3$s',
|
||||||
|
$group->escapedTableName(),
|
||||||
if ($this->sort == 'nickname') {
|
$this->getSortKey('created'),
|
||||||
$order = $this->reverse
|
$this->reverse ? 'DESC' : 'ASC');
|
||||||
? "{$group->__table}.nickname DESC"
|
|
||||||
: "{$group->__table}.nickname ASC";
|
|
||||||
} elseif ($this->reverse) {
|
|
||||||
$order = "{$group->__table}.created DESC";
|
|
||||||
}
|
|
||||||
|
|
||||||
$group->orderBy($order);
|
|
||||||
$group->limit($offset, $limit);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// User is browsing via AlphaNav
|
// User is browsing via AlphaNav
|
||||||
$sort = $this->getSortKey();
|
|
||||||
|
|
||||||
$sql = <<< GROUP_QUERY_END
|
switch($this->filter) {
|
||||||
SELECT user_group.*
|
|
||||||
FROM user_group
|
|
||||||
JOIN local_group ON user_group.id = local_group.group_id
|
|
||||||
GROUP_QUERY_END;
|
|
||||||
|
|
||||||
switch($this->filter)
|
|
||||||
{
|
|
||||||
case 'all':
|
case 'all':
|
||||||
// NOOP
|
// NOOP
|
||||||
break;
|
break;
|
||||||
case '0-9':
|
case '0-9':
|
||||||
$sql .=
|
$group->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s',
|
||||||
' AND LEFT(user_group.nickname, 1) BETWEEN \'0\' AND \'9\'';
|
$group->escapedTableName(),
|
||||||
|
'nickname',
|
||||||
|
$group->_quote("0"),
|
||||||
|
$group->_quote("9")));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$sql .= sprintf(
|
$group->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s',
|
||||||
' AND LEFT(LOWER(user_group.nickname), 1) = \'%s\'',
|
$group->escapedTableName(),
|
||||||
$this->filter
|
'nickname',
|
||||||
);
|
$group->_quote($this->filter)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= sprintf(
|
$order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
|
||||||
' ORDER BY user_group.%s %s, user_group.nickname ASC LIMIT %d, %d',
|
$group->escapedTableName(),
|
||||||
$sort,
|
$this->getSortKey('nickname'),
|
||||||
$this->reverse ? 'DESC' : 'ASC',
|
$this->reverse ? 'DESC' : 'ASC',
|
||||||
$offset,
|
'nickname');
|
||||||
$limit
|
|
||||||
);
|
|
||||||
|
|
||||||
$group->query($sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$offset = ($this->page-1) * PROFILES_PER_PAGE;
|
||||||
|
$limit = PROFILES_PER_PAGE + 1;
|
||||||
|
|
||||||
|
$group->orderBy($order);
|
||||||
|
$group->limit($offset, $limit);
|
||||||
|
|
||||||
$group->find();
|
$group->find();
|
||||||
|
|
||||||
return $group;
|
return $group;
|
||||||
|
@ -348,17 +338,14 @@ GROUP_QUERY_END;
|
||||||
*
|
*
|
||||||
* @return string a column name for sorting
|
* @return string a column name for sorting
|
||||||
*/
|
*/
|
||||||
function getSortKey()
|
function getSortKey($def='created')
|
||||||
{
|
{
|
||||||
switch ($this->sort) {
|
switch ($this->sort) {
|
||||||
case 'nickname':
|
case 'nickname':
|
||||||
return $this->sort;
|
|
||||||
break;
|
|
||||||
case 'created':
|
case 'created':
|
||||||
return $this->sort;
|
return $this->sort;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return 'nickname';
|
return $def;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user