[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/views/plugins/ -> views_plugin_access_role.inc (source)

   1  <?php
   2  
   3  /**
   4   * Access plugin that provides role-based access control.
   5   */
   6  class views_plugin_access_role extends views_plugin_access {
   7    function access($account) {
   8      return views_check_roles(array_filter($this->options['role']), $account);
   9    }
  10  
  11    function get_access_callback() {
  12      return array('views_check_roles', array(array_filter($this->options['role'])));
  13    }
  14  
  15    function summary_title() {
  16      $count = count($this->options['role']);
  17      if ($count < 1) {
  18        return t('No role(s) selected');
  19      }
  20      else if ($count > 1) {
  21        return t('Multiple roles');
  22      }
  23      else {
  24        $rids = views_ui_get_roles();
  25        $rid = reset($this->options['role']);
  26        return $rids[$rid];
  27      }
  28    }
  29  
  30    function option_defaults(&$options) {
  31      $options['role'] = array();
  32    }
  33  
  34    function options_form(&$form, &$form_state) {
  35      $form['role'] = array(
  36        '#type' => 'checkboxes',
  37        '#title' => t('Role'),
  38        '#default_value' => $this->options['role'],
  39        '#options' => views_ui_get_roles(),
  40        '#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.'),
  41      );
  42    }
  43  
  44    function options_validate(&$form, &$form_state) {
  45      if (!array_filter($form_state['values']['access_options']['role'])) {
  46        form_error($form['role'], t('You must select at least one role if type is "by role"'));
  47      }
  48    }
  49  
  50    function options_submit(&$form, &$form_state) {
  51      // I hate checkboxes.
  52      $form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']);
  53    }
  54  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7