You are here

function advuser_build_query in Advanced User 7.3

Same name and namespace in other branches
  1. 6.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/people/advuser/confirm/delete.
advuser_multiple_email_confirm in forms/advuser_multiple_email_confirm.inc
The menu callback function for admin/people/advuser/confirm/email
advuser_multiple_role_edit in ./advuser.module
Callback function for admin mass adding/deleting a user role.

File

./advuser.module, line 479
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();
  switch ($type) {
    case 'users':
      $query = db_select('users', 'u')
        ->fields('u', array(
        'uid',
        'name',
        'mail',
        'status',
        'created',
        'access',
      ))
        ->condition('u.uid', 0, '<>')
        ->distinct();
      break;
    case 'uid':
      $query = db_select('users', 'u')
        ->fields('u', array(
        'uid',
      ))
        ->condition('u.uid', 0, '<>')
        ->distinct();
      break;
    case 'name':
      $query = db_select('users', 'u')
        ->fields('u', array(
        'uid',
        'name',
      ))
        ->condition('u.uid', 0, '<>')
        ->distinct();
      break;
    case 'count':
      $query = db_select('users', 'u')
        ->condition('u.uid', 0, '<>');
      $query
        ->addExpression('COUNT(DISTINCT u.uid)');
      break;
  }
  $users_roles_alias = $query
    ->leftJoin('users_roles', 'ur', '%alias.uid = u.uid');
  foreach (advuser_profile_fields() as $field) {
    if (isset($field->name)) {
      $query
        ->leftJoin('profile_value', $field->name, "%alias.fid = :{$field->name}_fid AND %alias.uid = u.uid", array(
        ":{$field->name}_fid" => $field->fid,
      ));
    }
  }
  $i = 0;
  $where = !empty($filter['where']) ? $filter['where'] : '';
  foreach ($filter['join'] as $join) {
    $alias = $query
      ->join($join[0], $join[1], $join[2]);
    $where = str_ireplace("%alias_{$i}.", "{$alias}.", $where);
    $i++;
  }
  if (!empty($where)) {
    $query
      ->where($where, $filter['args']);
  }
  $include_uid1 = variable_get('advuser_allow_list_uid1', FALSE);
  if (empty($include_uid1)) {
    $query
      ->condition('u.uid', 1, '<>');
  }
  return $query;
}