/[drupal]/contributions/modules/views/plugins/views_plugin_access_role.inc
ViewVC logotype

Contents of /contributions/modules/views/plugins/views_plugin_access_role.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Wed Jan 7 23:31:13 2009 UTC (10 months, 2 weeks ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, DRUPAL-6--2-6, DRUPAL-6--2-5, DRUPAL-6--2-4, DRUPAL-6--2-3, DRUPAL-6--3-0-ALPHA1, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-6--3, DRUPAL-7--3
Changes since 1.1: +2 -2 lines
File MIME type: text/x-php
#343047 by alienbrain: Allow all handlers to participate in view validation.
1 <?php
2 // $Id: views_plugin_access_role.inc,v 1.1 2008/09/08 22:50:17 merlinofchaos Exp $
3
4 /**
5 * Access plugin that provides role-based access control.
6 */
7 class views_plugin_access_role extends views_plugin_access {
8 function access($account) {
9 $roles = array_keys($account->roles);
10 $roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
11 return array_intersect(array_filter($this->options['role']), $roles);
12 }
13
14 function get_access_callback() {
15 return array('views_check_roles', array(array_filter($this->options['role'])));
16 }
17
18 function summary_title() {
19 $count = count($this->options['role']);
20 if ($count < 1) {
21 return t('No role(s) selected');
22 }
23 else if ($count > 1) {
24 return t('Multiple roles');
25 }
26 else {
27 $rids = views_ui_get_roles();
28 $rid = array_shift($this->options['role']);
29 return $rids[$rid];
30 }
31 }
32
33 function option_defaults(&$options) {
34 $options['role'] = array();
35 }
36
37 function options_form(&$form, &$form_state) {
38 $form['role'] = array(
39 '#type' => 'checkboxes',
40 '#title' => t('Role'),
41 '#default_value' => $this->options['role'],
42 '#options' => views_ui_get_roles(),
43 '#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.'),
44 );
45 }
46
47 function options_validate(&$form, &$form_state) {
48 if (!array_filter($form_state['values']['access_options']['role'])) {
49 form_error($form['role'], t('You must select at least one role if type is "by role"'));
50 }
51 }
52
53 function options_submit(&$form, &$form_state) {
54 // I hate checkboxes.
55 $form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']);
56 }
57 }
58
59
60

  ViewVC Help
Powered by ViewVC 1.1.2