You are here

function views_handler_filter_user_name::validate_user_strings in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 6.2 modules/user/views_handler_filter_user_name.inc \views_handler_filter_user_name::validate_user_strings()
  2. 7.3 modules/user/views_handler_filter_user_name.inc \views_handler_filter_user_name::validate_user_strings()

Validate the user string. Since this can come from either the form or the exposed filter, this is abstracted out a bit so it can handle the multiple input sources.

2 calls to views_handler_filter_user_name::validate_user_strings()
views_handler_filter_user_name::exposed_validate in modules/user/views_handler_filter_user_name.inc
Validate the exposed handler form
views_handler_filter_user_name::value_validate in modules/user/views_handler_filter_user_name.inc
Validate the options form.

File

modules/user/views_handler_filter_user_name.inc, line 86

Class

views_handler_filter_user_name
Filter handler for usernames.

Code

function validate_user_strings(&$form, $values) {
  $uids = array();
  $placeholders = array();
  $args = array();
  $results = array();
  foreach ($values as $value) {
    if (strtolower($value) == 'anonymous') {
      $uids[] = 0;
    }
    else {
      $missing[strtolower($value)] = TRUE;
      $args[] = $value;
      $placeholders[] = "'%s'";
    }
  }
  if (!$args) {
    return $uids;
  }
  $result = db_query("SELECT * FROM {users} WHERE name IN (" . implode(', ', $placeholders) . ")", $args);
  while ($account = db_fetch_object($result)) {
    unset($missing[strtolower($account->name)]);
    $uids[] = $account->uid;
  }
  if ($missing) {
    form_error($form, format_plural(count($missing), 'Unable to find user: @users', 'Unable to find users: @users', array(
      '@users' => implode(', ', array_keys($missing)),
    )));
  }
  return $uids;
}