1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * |
---|
5 | * Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana |
---|
6 | * @file handler_field_ente_sector.inc |
---|
7 | * Drupal part Module to install ente planificador module |
---|
8 | * Copyright 2011 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL) |
---|
9 | * |
---|
10 | * This program is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; either version 2 of the License, or |
---|
13 | * (at your option) any later version. |
---|
14 | * |
---|
15 | * This program is distributed in the hope that it will be useful, |
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | * GNU General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with this program; if not, write to the Free Software |
---|
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | * |
---|
24 | * Probado con un servidor Apache 2.0, |
---|
25 | * Postgresql version 7.4.7 y 8.1 mysql 5.0.32 y PHP version 4.3.11 y 5.2.0-8 |
---|
26 | * |
---|
27 | * @author Cenditel Merida - Ing. Jose Puentes |
---|
28 | * @date 2014-11-19 // (año-mes-dia) |
---|
29 | * @version 0.2 // (0.1) |
---|
30 | * |
---|
31 | */ |
---|
32 | |
---|
33 | /** |
---|
34 | * Generar una lista de los ambitos existentes para realizar filtrados |
---|
35 | */ |
---|
36 | class views_handler_filter_ente_ambito extends views_handler_filter_many_to_one { |
---|
37 | function get_value_options() { } |
---|
38 | function value_form(&$form, &$form_state) { |
---|
39 | $tid = variable_get('ente_planificador_sector_Ambitos', 0); |
---|
40 | $terms = taxonomy_get_tree($tid); |
---|
41 | $options['0']= "seleccione"; |
---|
42 | foreach($terms as $term) { |
---|
43 | if ($term->depth == 0) { //si el termino es padre |
---|
44 | $options[$term->tid] .= $term->name; |
---|
45 | } |
---|
46 | } |
---|
47 | $form['value']['ambito'] = array( |
---|
48 | '#type' =>'select', |
---|
49 | '#options' => $options, |
---|
50 | ); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Provide the basic form which calls through to subforms. |
---|
55 | * If overridden, it is best to call through to the parent, |
---|
56 | * or to at least make sure all of the functions in this form |
---|
57 | * are called. |
---|
58 | */ |
---|
59 | function options_form(&$form, &$form_state) { |
---|
60 | if ($this->can_expose()) { |
---|
61 | $this->show_expose_button($form, $form_state); |
---|
62 | } |
---|
63 | $form['op_val_start'] = array('#value' => '<div class="clear-block">'); |
---|
64 | $this->show_operator_form($form, $form_state); |
---|
65 | $this->show_value_form($form, $form_state); |
---|
66 | $this->value_submit($form, $form_state); |
---|
67 | $form['op_val_end'] = array('#value' => '</div>'); |
---|
68 | if ($this->can_expose()) { |
---|
69 | $this->show_expose_form($form, $form_state); |
---|
70 | } |
---|
71 | if ($this->options['exposed'] == 1) { |
---|
72 | //excluyendo el campo |
---|
73 | $roles = user_roles(); |
---|
74 | $form['fieldset_roles'] = array( |
---|
75 | '#type' => 'fieldset', |
---|
76 | '#title' => t('Excluir Filtros'), |
---|
77 | '#weight' => 0, |
---|
78 | ); |
---|
79 | $form['fieldset_roles']['roles_exclude_ambito'] = array( |
---|
80 | '#type' => 'checkboxes', |
---|
81 | '#weight' => 0, |
---|
82 | '#title' => t('Excluir Filtros por roles de la Presentacion'), |
---|
83 | '#options' => $roles, |
---|
84 | '#default_value' => variable_get('roles_exclude_ambito', 0), |
---|
85 | '#description' => t('Seleccione los roles para escluir los filtros.'), |
---|
86 | ); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | * Perform any necessary changes to the form values prior to storage. |
---|
92 | * There is no need for this function to actually store the data. |
---|
93 | */ |
---|
94 | function value_submit($form, &$form_state) { |
---|
95 | if (isset($form_state['values']['options']['fieldset_roles']['roles_exclude_ambito'])) { |
---|
96 | variable_set('roles_exclude_ambito', $form_state['values']['options']['fieldset_roles']['roles_exclude_ambito']); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | function query() { |
---|
101 | $aid = explode('_',$this->field); |
---|
102 | $aid = $aid[1]; |
---|
103 | $this->ensure_my_table(); |
---|
104 | $field = "$this->table_alias.$this->real_field"; |
---|
105 | $upper = ''; |
---|
106 | $operation_attribute = "="; |
---|
107 | if($this->operator == 'not in') { |
---|
108 | $operation_attribute = '<>'; |
---|
109 | } |
---|
110 | if(!is_array($this->value)) { |
---|
111 | $this->value = array($this->value); |
---|
112 | } |
---|
113 | foreach ($this->value as &$value) { |
---|
114 | if ($value) { |
---|
115 | $this->query->add_where($this->options['group'], "$upper(%s) %s %d", $field, $operation_attribute, $value); |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | } |
---|