You are here

function advuser_build_query in Advanced User 6.3

Same name and namespace in other branches
  1. 7.3 advuser.module \advuser_build_query()

Get the sql query string.

Parameters

$type:

Return value

The sql string.

  • $type = 'users' returns a select string that include uid, name, mail, status, created and access.
  • $type = 'name' returns a select string that includes uid and name.
  • $type = 'count' returns a select string for the count for the list.
  • $type = 'uid' returns a select string that includes the uid.
4 calls to advuser_build_query()
advuser_admin_account in forms/advuser_admin_account.inc
Provide the list of filtered users.
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 524
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_query($type = 'users') {
  $filter = advuser_build_filter_query();

  // Array used for user profile DB query joins.
  $pf = array();
  foreach (advuser_profile_fields() as $field) {
    if (isset($field->name)) {
      $pf[] = "LEFT JOIN {profile_values} {$field->name} ON {$field->name}.fid = {$field->fid} AND {$field->name}.uid = u.uid";
    }
  }
  $filter['join'] .= count($pf) ? ' ' . implode(' ', array_unique($pf)) : NULL;
  switch ($type) {
    case 'users':
      $sql = 'SELECT DISTINCT u.uid, u.name, u.mail, u.status, u.created, u.access FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid ' . $filter['join'];
      break;
    case 'uid':
      $sql = 'SELECT DISTINCT u.uid as uid FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid ' . $filter['join'];
      break;
    case 'name':
      $sql = 'SELECT DISTINCT u.uid, u.name FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid ' . $filter['join'];
      break;
    case 'count':
      $sql = 'SELECT COUNT(DISTINCT u.uid) FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid ' . $filter['join'];
      break;
  }
  return $sql . (empty($filter['where']) ? '' : ' WHERE ' . $filter['where']);
}