1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_plugin_access_role.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Access plugin that provides role-based access control.
|
10
|
*
|
11
|
* @ingroup views_access_plugins
|
12
|
*/
|
13
|
class views_plugin_access_role extends views_plugin_access {
|
14
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function access($account) {
|
19
|
return views_check_roles(array_filter($this->options['role']), $account);
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
* {@inheritdoc}
|
24
|
*/
|
25
|
public function get_access_callback() {
|
26
|
return array('views_check_roles', array(array_filter($this->options['role'])));
|
27
|
}
|
28
|
|
29
|
/**
|
30
|
* {@inheritdoc}
|
31
|
*/
|
32
|
public function summary_title() {
|
33
|
$count = count($this->options['role']);
|
34
|
if ($count < 1) {
|
35
|
return t('No role(s) selected');
|
36
|
}
|
37
|
elseif ($count > 1) {
|
38
|
return t('Multiple roles');
|
39
|
}
|
40
|
else {
|
41
|
$rids = views_ui_get_roles();
|
42
|
$rid = reset($this->options['role']);
|
43
|
return check_plain($rids[$rid]);
|
44
|
}
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* {@inheritdoc}
|
49
|
*/
|
50
|
public function option_definition() {
|
51
|
$options = parent::option_definition();
|
52
|
$options['role'] = array('default' => array());
|
53
|
|
54
|
return $options;
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* {@inheritdoc}
|
59
|
*/
|
60
|
public function options_form(&$form, &$form_state) {
|
61
|
parent::options_form($form, $form_state);
|
62
|
$form['role'] = array(
|
63
|
'#type' => 'checkboxes',
|
64
|
'#title' => t('Role'),
|
65
|
'#default_value' => $this->options['role'],
|
66
|
'#options' => array_map('check_plain', views_ui_get_roles()),
|
67
|
'#description' => t('Only the checked roles will be able to access this display. Note that users with "access all views" can see any view, regardless of role.'),
|
68
|
);
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* {@inheritdoc}
|
73
|
*/
|
74
|
public function options_validate(&$form, &$form_state) {
|
75
|
if (!array_filter($form_state['values']['access_options']['role'])) {
|
76
|
form_error($form['role'], t('You must select at least one role if type is "by role"'));
|
77
|
}
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* {@inheritdoc}
|
82
|
*/
|
83
|
public function options_submit(&$form, &$form_state) {
|
84
|
// I hate checkboxes.
|
85
|
$form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']);
|
86
|
}
|
87
|
|
88
|
}
|