Commit 7799bdab authored by Son Nguyen's avatar Son Nguyen
Browse files

Have more sorting options on member's listing in a group Bug#781990



5 sorting options:
 - Admin first
 - Name A to Z
 - Name Z to A
 - First joined
 - Last joined
* Name = display name if not empty, if else = first name lastname.

Change-Id: Ie14ce285a3f3e7f805ae6226c555c507c7e0fe23
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 31966be5
......@@ -79,8 +79,23 @@ $query = trim(param_variable('query', ''));
$setlimit = true; //Enable choosing page size; list of page sizes has been predefined in function build_pagination()
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
// Sort options index and list of sort options
// ORDER BY statements defined in group_user_search function need to be matched
$sortoptions = array(
'adminfirst' => get_string('adminfirst'),
'nameatoz' => get_string('nameatoz'),
'nameztoa' => get_string('nameztoa'),
'firstjoined' => get_string('firstjoined'),
'lastjoined' => get_string('lastjoined')
);
$sortoptionidx = param_alpha('sortoption', 'adminfirst');
if ($membershiptype == 'request') {
array_shift($sortoptions);
$sortoptionidx = param_alpha('sortoption', 'nameatoz');
}
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype);
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype, null, null, $sortoptionidx);
list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersearch_data($results, $group->id, $query, $membershiptype, $setlimit);
// Type-specific instructions
......@@ -114,6 +129,15 @@ $searchform = pieform(array(
'type' => 'text',
'defaultvalue' => $query
),
'sortoption' => array(
'type' => 'select',
'class' => 'sortoption',
'title' => get_string('sortedby'),
'multiple' => false,
'size' => 1,
'defaultvalue' => $sortoptionidx,
'options' => $sortoptions
),
'submit' => array(
'type' => 'submit',
'value' => get_string('search')
......@@ -128,7 +152,8 @@ addLoadEvent(function () {
replaceChildNodes('messages');
var params = {'query': $('search_query').value, 'id':$('search_id').value,
'membershiptype':$('search_membershiptype').value,
'setlimit':$('search_setlimit').value
'setlimit':$('search_setlimit').value,
'sortoption':$('search_sortoption').value
};
p.sendQuery(params);
event.stop();
......
......@@ -37,6 +37,7 @@ $query = trim(param_variable('query', ''));
$setlimit = param_boolean('setlimit', false);
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$sortoptionidx = param_alpha('sortoption', 'adminfirst');
define('GROUP', $id);
$group = group_current_group();
......@@ -69,7 +70,8 @@ if (!empty($membershiptype)) {
$results = get_group_user_search_results(
$group->id, $query, $offset, $limit, $membershiptype, null,
$friends ? $USER->get('id') : null
$friends ? $USER->get('id') : null,
$sortoptionidx
);
if (!param_integer('html', 1)) {
foreach ($results['data'] as &$result) {
......@@ -91,5 +93,6 @@ json_reply(false, array(
'offset' => $offset,
'setlimit' => $setlimit,
'membershiptype' => $membershiptype,
'sortoption' => $sortoptionidx,
)
));
......@@ -120,6 +120,12 @@ $string['alltags'] = 'All tags';
$string['sortalpha'] = 'Sort tags alphabetically';
$string['sortfreq'] = 'Sort tags by frequency';
$string['sortresultsby'] = 'Sort results by:';
$string['sortedby'] = 'sorted by:';
$string['adminfirst'] = 'Admin first';
$string['nameatoz'] = 'Name A to Z';
$string['nameztoa'] = 'Name Z to A';
$string['firstjoined'] = 'First joined';
$string['lastjoined'] = 'Last joined';
$string['date'] = 'Date';
$string['dateformatguide'] = 'Use the format YYYY/MM/DD';
$string['dateofbirthformatguide'] = 'Use the format YYYY/MM/DD';
......
......@@ -394,7 +394,7 @@ function build_admin_user_search_results($search, $offset, $limit) {
* @param int $friendof Only return friends of this user
*
*/
function get_group_user_search_results($group, $query, $offset, $limit, $membershiptype, $order=null, $friendof=null) {
function get_group_user_search_results($group, $query, $offset, $limit, $membershiptype, $order=null, $friendof=null, $sortoptionidx=null) {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
......@@ -437,7 +437,7 @@ function get_group_user_search_results($group, $query, $offset, $limit, $members
$results = call_static_method(
generate_class_name('search', $plugin), 'group_search_user',
$group, $queries, $constraints, $offset, $limit, $membershiptype, $order, $friendof
$group, $queries, $constraints, $offset, $limit, $membershiptype, $order, $friendof, $sortoptionidx
);
if ($results['count']) {
......
......@@ -449,10 +449,26 @@ class PluginSearchInternal extends PluginSearch {
}
public static function group_search_user($group, $query_string, $constraints, $offset, $limit, $membershiptype, $order, $friendof) {
public static function group_search_user($group, $query_string, $constraints, $offset, $limit, $membershiptype, $order, $friendof, $orderbyoptionidx=null) {
list($searchsql, $values) = self::name_search_sql($query_string);
$orderbyoptions = array(
'adminfirst' => 'gm.role = \'admin\' DESC, CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.firstname END ASC,
CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.lastname END ASC, gm.ctime, u.id',
'nameatoz' => 'CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.firstname END ASC,
CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.lastname END ASC, gm.ctime, u.id',
'nameztoa' => 'CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.firstname END DESC,
CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.lastname END DESC, gm.ctime, u.id',
'firstjoined' => 'gm.ctime ASC, CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.firstname END ASC,
CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.lastname END ASC, u.id',
'lastjoined' => 'gm.ctime DESC, CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.firstname END ASC,
CASE WHEN NOT u.preferredname IS NULL AND u.preferredname <> \'\' THEN u.preferredname ELSE u.lastname END ASC, u.id'
);
if (! key_exists($orderbyoptionidx, $orderbyoptions)) {
$orderbyoptionidx = 'adminfirst';
}
if ($membershiptype == 'nonmember') {
$select = '
u.id, u.firstname, u.lastname, u.username, u.email, u.profileicon, u.staff';
......@@ -480,28 +496,31 @@ class PluginSearchInternal extends PluginSearch {
else if ($membershiptype == 'request') {
$select = '
u.id, u.firstname, u.lastname, u.username, u.email, u.profileicon,
u.staff, ' . db_format_tsfield('gmr.ctime', 'jointime');
u.staff, ' . db_format_tsfield('gm.ctime', 'jointime');
$from = '
FROM {usr} u
INNER JOIN {group_member_request} gmr ON (gmr.member = u.id)
INNER JOIN {group_member_request} gm ON (gm.member = u.id)
LEFT OUTER JOIN {usr_account_preference} h ON (u.id = h.usr AND h.field = \'hiderealname\')
WHERE u.id > 0 AND u.deleted = 0 ' . $searchsql . '
AND gmr.group = ?';
AND gm.group = ?';
$values[] = $group;
$orderby = 'u.firstname, u.lastname, gmr.ctime, u.id';
if ($orderbyoptionidx == 'adminfirst') {
$orderbyoptionidx = 'nameatoz';
}
$orderby = $orderbyoptions[$orderbyoptionidx];
}
else if ($membershiptype == 'invite') {
$select = '
u.id, u.firstname, u.lastname, u.username, u.email, u.profileicon,
u.staff, ' . db_format_tsfield('gmi.ctime', 'jointime');
u.staff, ' . db_format_tsfield('gm.ctime', 'jointime');
$from = '
FROM {usr} u
INNER JOIN {group_member_invite} gmi ON (gmi.member = u.id)
INNER JOIN {group_member_invite} gm ON (gm.member = u.id)
LEFT OUTER JOIN {usr_account_preference} h ON (u.id = h.usr AND h.field = \'hiderealname\')
WHERE u.id > 0 AND u.deleted = 0 ' . $searchsql . '
AND gmi.group = ?';
AND gm.group = ?';
$values[] = $group;
$orderby = 'u.firstname, u.lastname, gmi.ctime, u.id';
$orderby = $orderbyoptions[$orderbyoptionidx];
}
else { // All group members
$select = '
......@@ -514,7 +533,7 @@ class PluginSearchInternal extends PluginSearch {
WHERE u.id > 0 AND u.deleted = 0 ' . $searchsql . '
AND gm.group = ?';
$values[] = $group;
$orderby = "gm.role = 'admin' DESC, u.firstname, u.lastname, gm.ctime, u.id";
$orderby = $orderbyoptions[$orderbyoptionidx];
if ($order == 'latest') {
$orderby = 'gm.ctime DESC, u.firstname, u.lastname, u.id';
}
......
......@@ -2781,3 +2781,8 @@ form#register tbody tr.checkbox th {
form#register tbody tr.checkbox td {
width:85%;
}
/* sort options */
.sortoption label{
font-weight:normal;
margin: 0px 5px
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment