function advuser_build_filter_query in Advanced User 5.2
Same name and namespace in other branches
- 6.3 advuser.module \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.
1 call to advuser_build_filter_query()
File
- ./
advuser_filters.inc, line 365 - 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() {
$filters = advuser_filters();
// Build query
$where = $args = $join = array();
foreach ($_SESSION['advuser_overview_filter'] as $filter) {
list($key, $value, $op, $qop) = $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':
$value = strtotime($value);
break;
}
$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;
}
switch ($qop) {
case '!=':
case 'NOT LIKE':
$in = 'NOT IN';
$eq = '!=';
$andor = 'AND';
break;
default:
$in = 'IN';
$eq = '=';
$andor = 'OR';
}
$_where = $op . ' ' . str_ireplace("%op", $qop, $filters[$key]['where']);
$_where = str_ireplace("%eq", $eq, $_where);
$_where = str_ireplace("%andor", $andor, $_where);
$where[] = str_ireplace("%in", $in, $_where);
$args[] = $arg_prefix . $value . $arg_suffix;
$join[] = $filters[$key]['join'];
}
$where = count($where) ? 'AND (' . implode(' ', $where) . ')' : '';
$join = count($join) ? ' ' . implode(' ', array_unique($join)) : '';
return array(
'where' => $where,
'join' => $join,
'args' => $args,
);
}