You are here

function activity_views_handler_argument_activity_user::query in Activity 7

Extract the value and enforce the realms restrictions.

Overrides views_handler_argument_numeric::query

File

views/views_handler_arguments.inc, line 36
Provide argument handlers for Activity module

Class

activity_views_handler_argument_activity_user
@file Provide argument handlers for Activity module

Code

function query() {
  $table = $this
    ->ensure_my_table();
  if (!empty($this->options['break_phrase'])) {
    views_break_phrase($this->argument, $this);
  }
  else {
    $this->value = array(
      $this->argument,
    );
  }
  $allowed_realms = activity_cache_get('realms');
  $realm_values = array();
  foreach ($this->options['realms'] as $realm) {
    if (isset($allowed_realms[$realm])) {
      foreach ($this->value as $uid) {
        $realm_values += module_invoke($allowed_realms[$realm]['module'], 'activity_access_grants', user_load($uid));
      }
    }
  }

  // No valid values, probably an error but prevent anything from being shown.
  if (empty($realm_values)) {
    $realm_values = array(
      'activity_none' => 1,
    );
  }
  if (count($realm_values) > 1) {
    $grants = db_or();
    foreach ($realm_values as $realm => $ids) {
      $grants
        ->condition(db_and()
        ->condition($table . '.realm', $realm)
        ->condition($table . '.value', $ids, 'IN'));
    }
    $this->query
      ->add_where('AND', $grants);
  }
  else {
    $keys = array_keys($realm_values);
    $realm = $keys[0];
    $grants = db_and()
      ->condition($table . '.realm', $realm)
      ->condition($table . '.value', $realm_values[$realm]);
    $this->query
      ->add_where(0, $grants);
  }
}