UserdirectoryAction now ManagedAction and better SQL
This commit is contained in:
parent
d445e0c877
commit
4ad7e8f459
|
@ -27,12 +27,7 @@
|
||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET'))
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
{
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once INSTALLDIR . '/lib/publicgroupnav.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User directory
|
* User directory
|
||||||
|
@ -43,7 +38,7 @@ require_once INSTALLDIR . '/lib/publicgroupnav.php';
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
class UserdirectoryAction extends Action
|
class UserdirectoryAction extends ManagedAction
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The page we're on
|
* The page we're on
|
||||||
|
@ -137,17 +132,8 @@ class UserdirectoryAction extends Action
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function doPreparation()
|
||||||
* Take arguments for running
|
|
||||||
*
|
|
||||||
* @param array $args $_REQUEST args
|
|
||||||
*
|
|
||||||
* @return boolean success flag
|
|
||||||
*/
|
|
||||||
function prepare($args)
|
|
||||||
{
|
{
|
||||||
parent::prepare($args);
|
|
||||||
|
|
||||||
$this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
|
$this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
|
||||||
$this->filter = $this->arg('filter', 'all');
|
$this->filter = $this->arg('filter', 'all');
|
||||||
$this->reverse = $this->boolean('reverse');
|
$this->reverse = $this->boolean('reverse');
|
||||||
|
@ -155,23 +141,6 @@ class UserdirectoryAction extends Action
|
||||||
$this->sort = $this->arg('sort', 'nickname');
|
$this->sort = $this->arg('sort', 'nickname');
|
||||||
|
|
||||||
common_set_returnto($this->selfUrl());
|
common_set_returnto($this->selfUrl());
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle request
|
|
||||||
*
|
|
||||||
* Shows the page
|
|
||||||
*
|
|
||||||
* @param array $args $_REQUEST args; handled in prepare()
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function handle($args)
|
|
||||||
{
|
|
||||||
parent::handle($args);
|
|
||||||
$this->showPage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -291,10 +260,13 @@ class UserdirectoryAction extends Action
|
||||||
{
|
{
|
||||||
$profile = new Profile();
|
$profile = new Profile();
|
||||||
|
|
||||||
|
// Comment this out or disable to get global profile searches
|
||||||
|
$profile->joinAdd(array('id', 'user:id'));
|
||||||
|
|
||||||
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
|
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
|
||||||
$limit = PROFILES_PER_PAGE + 1;
|
$limit = PROFILES_PER_PAGE + 1;
|
||||||
|
|
||||||
if (isset($this->q)) {
|
if (!empty($this->q)) {
|
||||||
// User is searching via query
|
// User is searching via query
|
||||||
$search_engine = $profile->getSearchEngine('profile');
|
$search_engine = $profile->getSearchEngine('profile');
|
||||||
|
|
||||||
|
@ -319,34 +291,34 @@ class UserdirectoryAction extends Action
|
||||||
$profile->find();
|
$profile->find();
|
||||||
} else {
|
} else {
|
||||||
// User is browsing via AlphaNav
|
// User is browsing via AlphaNav
|
||||||
$sort = $this->getSortKey();
|
|
||||||
$sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id';
|
|
||||||
|
|
||||||
switch($this->filter)
|
switch ($this->filter) {
|
||||||
{
|
|
||||||
case 'all':
|
case 'all':
|
||||||
// NOOP
|
// NOOP
|
||||||
break;
|
break;
|
||||||
case '0-9':
|
case '0-9':
|
||||||
$sql .=
|
$profile->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s',
|
||||||
' AND LEFT(profile.nickname, 1) BETWEEN \'0\' AND \'9\'';
|
$profile->escapedTableName(),
|
||||||
|
'nickname',
|
||||||
|
$profile->_quote("0"),
|
||||||
|
$profile->_quote("9")));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$sql .= sprintf(
|
$profile->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s',
|
||||||
' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'',
|
$profile->escapedTableName(),
|
||||||
$this->filter
|
'nickname',
|
||||||
);
|
$profile->_quote($this->filter)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= sprintf(
|
$order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
|
||||||
' ORDER BY profile.%s %s, profile.nickname ASC LIMIT %d, %d',
|
$profile->escapedTableName(),
|
||||||
$sort,
|
$this->getSortKey('nickname'),
|
||||||
$this->reverse ? 'DESC' : 'ASC',
|
$this->reverse ? 'DESC' : 'ASC',
|
||||||
$offset,
|
'nickname');
|
||||||
$limit
|
$profile->orderBy($order);
|
||||||
);
|
$profile->limit($offset, $limit);
|
||||||
|
|
||||||
$profile->query($sql);
|
$profile->find();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $profile;
|
return $profile;
|
||||||
|
@ -357,15 +329,12 @@ class UserdirectoryAction extends Action
|
||||||
*
|
*
|
||||||
* @return string a column name for sorting
|
* @return string a column name for sorting
|
||||||
*/
|
*/
|
||||||
function getSortKey()
|
function getSortKey($def='nickname')
|
||||||
{
|
{
|
||||||
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 'nickname';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user