You are here

function spaces_og_plugin_argument_validate_useringroups::validate_argument in Spaces 6.3

Same name and namespace in other branches
  1. 7.3 spaces_og/views/spaces_og_plugin_argument_validate_useringroups.inc \spaces_og_plugin_argument_validate_useringroups::validate_argument()
  2. 7 spaces_og/views/spaces_og_plugin_argument_validate_useringroups.inc \spaces_og_plugin_argument_validate_useringroups::validate_argument()

File

spaces_og/views/spaces_og_plugin_argument_validate_useringroups.inc, line 32

Class

spaces_og_plugin_argument_validate_useringroups
Validate whether an argument is a valid user that is a member of one of the current user's groups. This check works through the implementation of db_rewrite_sql() in spaces_og.

Code

function validate_argument($argument) {
  $type = $this->argument->options['validate_user_argument_type'];

  // is_numeric() can return false positives, so we ensure it's an integer.
  // However, is_integer() will always fail, since $argument is a string.
  if (is_numeric($argument) && $argument == (int) $argument) {
    if ($type == 'uid' || $type == 'either') {
      $where = 'u.uid = %d';
    }
  }
  else {
    if ($type == 'name' || $type == 'either') {
      $where = "u.name = '%s'";
    }
  }
  if (!empty($where)) {
    $query = db_rewrite_sql("SELECT u.uid FROM {users} u WHERE {$where}", 'u', 'uid', array(
      $argument,
    ));
    $validated = db_result(db_query($query, $argument));
    return $validated;
  }
  return FALSE;
}