class activity_views_handler_filter_access in Activity 6.2
Same name and namespace in other branches
- 7 views/views_handler_filters.inc \activity_views_handler_filter_access
@file generic handler that provides access control on where
Hierarchy
- class \activity_views_handler_filter_access extends \views_handler_filter
Expanded class hierarchy of activity_views_handler_filter_access
1 string reference to 'activity_views_handler_filter_access'
- activity_views_data in views/
activity.views.inc - Implementation of hook_views_data().
File
- views/
activity_views_handler_filter_access.inc, line 7 - generic handler that provides access control on where
View source
class activity_views_handler_filter_access extends views_handler_filter {
/**
* tell Views UI this filter can't be exposed
*/
function can_expose() {
return FALSE;
}
/**
* Override the options_definition().
*/
function option_definition() {
$options = parent::option_definition();
$info = activity_get_module_info($this->definition['module']);
$realms = $info->realms;
foreach ($realms as $realm => $name) {
$default_realms[$realm] = $realm;
}
$options['realms'] = array(
'default' => $default_realms,
);
return $options;
}
/**
* Override the options_form().
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$info = activity_get_module_info($this->definition['module']);
$realms = $info->realms;
$options = array();
foreach ($realms as $realm => $title) {
$options[$realm] = t($title);
}
$form['realms'] = array(
'#type' => 'checkboxes',
'#title' => t('Specific Relationships'),
'#options' => $options,
'#default_value' => $this->options['realms'],
);
}
/**
* override query
*/
function query() {
$this
->ensure_my_table();
$group = activity_views_group();
$placeholder = '%d';
// ensure the file is included for this module
activity_get_module_info($this->definition['module']);
// go through each grant that this user has
$realms = module_invoke($this->definition['module'], 'activity_access_grants', activity_views_access_user());
// All the valid realms according to the options form.
$valid_realms = array_intersect(array_keys($this->options['realms']), array_keys($realms));
if (empty($valid_realms)) {
// The user hasn't done anything that $this->definition['module'] realms
// keep track of, use a dummy realm.
$realms = array(
'activity_none' => array(
-1,
),
);
$valid_realms = array(
'activity_none',
);
}
foreach ($valid_realms as $realm) {
if (is_null($group)) {
// Static cache the where group for other access handlers to use.
$group = activity_views_group($this->query
->set_where_group('OR'));
}
$values = $realms[$realm];
$replace = array_fill(0, sizeof($values), $placeholder);
$in = ' (' . implode(", ", $replace) . ')';
// Use the group to keep all access handlers in the same OR query.
$this->query
->add_where($group, "({$this->table_alias}.realm = '%s' AND {$this->table_alias}.{$this->real_field} IN {$in})", array_merge(array(
$realm,
), $values));
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
activity_views_handler_filter_access:: |
function | tell Views UI this filter can't be exposed | ||
activity_views_handler_filter_access:: |
function | Override the options_form(). | ||
activity_views_handler_filter_access:: |
function | Override the options_definition(). | ||
activity_views_handler_filter_access:: |
function | override query |