function advuser_build_filter_query in Advanced User 6.3
Same name and namespace in other branches
- 5.2 advuser_filters.inc \advuser_build_filter_query()
- 6.2 advuser_filters.inc \advuser_build_filter_query()
- 7.3 advuser.module \advuser_build_filter_query()
Build query for advuser administration filters based on session.
Parameters
$reset Resets the static cached array.:
Return value
array containing 'join' clauses, 'where' clauses and replacement 'args' for the variable sections of the clauses.
5 calls to advuser_build_filter_query()
- advuser_admin_account in forms/
advuser_admin_account.inc - Provide the list of filtered users.
- advuser_build_query in ./
advuser.module - Get the sql query string.
- advuser_multiple_delete_confirm in forms/
advuser_multiple_delete_confirm.inc - Implement the menu callback function for admin/user/user/advuser/confirm/delete.
- advuser_multiple_email_confirm in forms/
advuser_multiple_email_confirm.inc - The menu callback function for admin/user/user/advuser/confirm/email
- advuser_multiple_role_edit in ./
advuser.module - Callback function for admin mass adding/deleting a user role.
File
- ./
advuser.module, line 563 - Advanced user module allows you to select users based on an advanced set of filtering and apply actions to block, unblock, delete or email the selected users.
Code
function advuser_build_filter_query($reset = FALSE) {
$advuser =& $_SESSION['advuser'];
static $filter_array = array();
if (empty($filter_array) || $reset) {
$filters =& $advuser['filters'];
$advuser_filters = advuser_filters();
// Build query
$where = $args = $join = array();
foreach ($filters as $filter) {
list($key, $op, $qop, $value) = array_values($filter);
// This checks to see if this permission filter is an enabled permission
// for the authenticated role. If so, then all users would be listed, and
// we can skip adding it to the filter query.
switch ($key) {
case 'permission':
$account = new stdClass();
$account->uid = 'advuser_filter';
$account->roles = array(
DRUPAL_AUTHENTICATED_RID => 1,
);
if (user_access($value, $account)) {
continue;
}
break;
case 'created':
case 'last_access':
// Convert the string date to a unix time value.
$value = strtotime($value);
break;
case 'user_roles':
// Allow for filtering for users where no role is set.
if (ord($value) === 0) {
$qop = 'IS';
$value = 'NULL';
}
break;
}
// Provide for '%%%s%%', '%%%s' and '%s%%' as needed.
$arg_prefix = $arg_suffix = NULL;
switch ($qop) {
case 'NOT LIKE':
case 'LIKE':
$arg_prefix = $arg_suffix = '%';
break;
case 'BEGINS WITH':
$qop = 'LIKE';
$arg_suffix = '%';
break;
case 'ENDS WITH':
$qop = 'LIKE';
$arg_prefix = '%';
break;
}
// Provide operator symbol to SQL translation.
switch ($qop) {
case '!=':
case 'NOT LIKE':
$in = 'NOT IN';
$eq = '!=';
$andor = 'AND';
break;
default:
$in = 'IN';
$eq = '=';
$andor = 'OR';
}
// Build the 'where' clauses.
$_where = $op . ' ' . str_ireplace("%op", $qop, $advuser_filters[$key]['where']);
$_where = str_ireplace("%eq", $eq, $_where);
$_where = str_ireplace("%andor", $andor, $_where);
$where[] = str_ireplace("%in", $in, $_where);
// Build the argument values.
$args[] = $arg_prefix . $value . $arg_suffix;
// Build the join clauses.
$join[] = $advuser_filters[$key]['join'];
}
$where = count($where) ? '(' . implode(' ', $where) . ')' : '';
$join = count($join) ? ' ' . implode(' ', array_unique($join)) : '';
$filter_array = array(
'where' => $where,
'join' => $join,
'args' => $args,
);
}
return $filter_array;
}