Commit 412f5437 authored by Hugh Davenport's avatar Hugh Davenport Committed by Gerrit Code Review
Browse files

Add search backend for logged in filter



Uses the constraints system, added to the internal plugin.

Third party search libraries will need to be altered

Change-Id: Ib3a0e64eedbf8a57f449e749c97a805dcc1d49c5
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 268d14ba
......@@ -43,6 +43,8 @@ if ($action == 'search') {
$params->l = param_alpha('l', null);
$params->sortby = param_alpha('sortby', 'firstname');
$params->sortdir = param_alpha('sortdir', 'asc');
$params->loggedin = param_alpha('loggedin', 'any');
$params->loggedindate= param_variable('loggedindate', null);
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
......
......@@ -41,6 +41,8 @@ $search = (object) array(
'l' => param_alpha('l', null), // last initial
'sortby' => param_alpha('sortby', 'firstname'),
'sortdir' => param_alpha('sortdir', 'asc'),
'loggedin' => param_alpha('loggedin', 'any'),
'loggedindate'=> param_variable('loggedindate', null),
);
$offset = param_integer('offset', 0);
......
......@@ -223,6 +223,29 @@ function get_admin_user_search_results($search, $offset, $limit) {
'type' => 'starts',
'string' => $search->l);
}
if ($search->loggedin !== 'any') {
if ($search->loggedin == 'never') {
$constraints[] = array('field' => 'lastlogin',
'type' => 'equals',
'string' => null);
}
else if ($search->loggedin == 'ever') {
$constraints[] = array('field' => 'lastlogin',
'type' => 'notequals',
'string' => null);
}
else if ($search->loggedin == 'since') {
$constraints[] = array('field' => 'lastlogin',
'type' => 'greaterthan',
'string' => $search->loggedindate);
}
else if ($search->loggedin == 'notsince') {
$constraints[] = array('field' => 'lastlogin',
'type' => 'lessthanequal',
'string' => $search->loggedindate);
}
}
// Filter by viewable institutions:
global $USER;
......
......@@ -434,7 +434,7 @@ class PluginSearchInternal extends PluginSearch {
$data = get_records_sql_assoc('
SELECT
u.id, u.firstname, u.lastname, u.preferredname, u.username, u.email, u.staff, u.profileicon,
u.active, NOT u.suspendedcusr IS NULL as suspended
u.lastlogin, u.active, NOT u.suspendedcusr IS NULL as suspended
FROM {usr} u ' . $where . '
ORDER BY ' . $sort . ', u.id',
$values,
......
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