00001 <?php
00002
00006 class views_plugin_access_role extends views_plugin_access {
00007 function access($account) {
00008 return views_check_roles(array_filter($this->options['role']), $account);
00009 }
00010
00011 function get_access_callback() {
00012 return array('views_check_roles', array(array_filter($this->options['role'])));
00013 }
00014
00015 function summary_title() {
00016 $count = count($this->options['role']);
00017 if ($count < 1) {
00018 return t('No role(s) selected');
00019 }
00020 elseif ($count > 1) {
00021 return t('Multiple roles');
00022 }
00023 else {
00024 $rids = views_ui_get_roles();
00025 $rid = reset($this->options['role']);
00026 return check_plain($rids[$rid]);
00027 }
00028 }
00029
00030
00031 function option_definition() {
00032 $options = parent::option_definition();
00033 $options['role'] = array('default' => array());
00034
00035 return $options;
00036 }
00037
00038 function options_form(&$form, &$form_state) {
00039 parent::options_form($form, $form_state);
00040 $form['role'] = array(
00041 '#type' => 'checkboxes',
00042 '#title' => t('Role'),
00043 '#default_value' => $this->options['role'],
00044 '#options' => array_map('check_plain', views_ui_get_roles()),
00045 '#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.'),
00046 );
00047 }
00048
00049 function options_validate(&$form, &$form_state) {
00050 if (!array_filter($form_state['values']['access_options']['role'])) {
00051 form_error($form['role'], t('You must select at least one role if type is "by role"'));
00052 }
00053 }
00054
00055 function options_submit(&$form, &$form_state) {
00056
00057 $form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']);
00058 }
00059 }