You are here

function activity_views_handler_filter_access::query in Activity 7

Same name and namespace in other branches
  1. 6.2 views/activity_views_handler_filter_access.inc \activity_views_handler_filter_access::query()

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides views_handler_filter::query

File

views/views_handler_filters.inc, line 47
Provides the Views Filter Handlers.

Class

activity_views_handler_filter_access
Filters the Activity records to those that are visible to the context user.

Code

function query() {
  $table = $this
    ->ensure_my_table();
  $allowed_realms = activity_cache_get('realms');
  $realm_values = array();
  foreach ($this->options['realms'] as $realm) {
    if (isset($allowed_realms[$realm])) {
      $realm_values += module_invoke($allowed_realms[$realm]['module'], 'activity_access_grants', user_load($GLOBALS['user']->uid));
    }
  }
  if (empty($realm_values)) {
    $realm_values = array(
      'activity_none' => array(
        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);
  }
}