source: sipes/modules_contrib/views/plugins/views_plugin_access_role.inc @ a8b1f3f

stableversion-3.0
Last change on this file since a8b1f3f was 59029b2, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se actualizo la version del modulo views

  • Propiedad mode establecida a 100644
File size: 1.7 KB
Línea 
1<?php
2
3/**
4 * Access plugin that provides role-based access control.
5 */
6class 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
31  function option_definition() {
32    $options = parent::option_definition();
33    $options['role'] = array('default' => array());
34
35    return $options;
36  }
37
38  function options_form(&$form, &$form_state) {
39    $form['role'] = array(
40      '#type' => 'checkboxes',
41      '#title' => t('Role'),
42      '#default_value' => $this->options['role'],
43      '#options' => views_ui_get_roles(),
44      '#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.'),
45    );
46  }
47
48  function options_validate(&$form, &$form_state) {
49    if (!array_filter($form_state['values']['access_options']['role'])) {
50      form_error($form['role'], t('You must select at least one role if type is "by role"'));
51    }
52  }
53
54  function options_submit(&$form, &$form_state) {
55    // I hate checkboxes.
56    $form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']);
57  }
58}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.