You are here

function purge_users_never_loggedin_user_ids in Auto Purge Users 7

Same name and namespace in other branches
  1. 8.3 purge_users.module \purge_users_never_loggedin_user_ids()
  2. 8 purge_users.module \purge_users_never_loggedin_user_ids()
  3. 8.2 purge_users.module \purge_users_never_loggedin_user_ids()
  4. 7.2 purge_users.module \purge_users_never_loggedin_user_ids()

Get not logged in user ids.

Parameters

array $param: Form parameters.

array $user_roles: Selected user roles.

Return value

mixed Users ids.

2 calls to purge_users_never_loggedin_user_ids()
purge_users_cron in ./purge_users.module
Implements hook_cron().
purge_users_get_users_list in ./purge_users.module
Get users ids to cancel.

File

./purge_users.module, line 130
Purge users module file.

Code

function purge_users_never_loggedin_user_ids(array $param, array $user_roles = array()) {

  // Get a time stamp according to the period selected.
  $logindate = '';
  if (!empty($param['never_login_value'])) {
    $logindate = strtotime('-' . $param['never_login_value'] . ' ' . $param['never_login_period']);
  }

  // Query through db table to get users ids.
  $query = db_select('users', 'u');
  $query
    ->leftjoin('users_roles', 'ur', 'ur.uid = u.uid');
  $query
    ->fields('u', array(
    'uid',
  ));
  $query
    ->condition('u.uid', 1, '>');
  if (!empty($param['never_login_value'])) {
    $query
      ->condition('u.created', $logindate, '<');
    $query
      ->condition('u.login', 0);
  }
  if (in_array(DRUPAL_AUTHENTICATED_RID, $user_roles)) {
    $db_or = db_or();
    $db_or
      ->condition('ur.rid', NULL);
    $db_or
      ->condition('ur.rid', $user_roles, 'IN');
    $query
      ->condition($db_or);
  }
  else {
    $query
      ->condition('ur.rid', $user_roles, 'IN');
  }
  $uids = $query
    ->execute()
    ->fetchCol();
  return $uids;
}