1 | <?php |
---|
2 | /** |
---|
3 | * Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
4 | * @file proyectos_operativos_mcti.module |
---|
5 | * Drupal part Module to Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
6 | * Copyright 2013 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL) |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
21 | * |
---|
22 | * @author Cenditel Merida - Ing. Jose Puentes |
---|
23 | * @date 2015-02-03 // (año-mes-dia) |
---|
24 | * @version 0.1 // (0.1) |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | /** |
---|
29 | * |
---|
30 | */ |
---|
31 | function proyectos_operativos_revision_menu() { |
---|
32 | $items = array(); |
---|
33 | $items['proyectosop/%node/revisions/view/%/%'] = array( |
---|
34 | 'title' => 'Diff', |
---|
35 | 'page callback' => 'proyectos_operativos_revision_diff_diffs_show', |
---|
36 | 'page arguments' => array(1, 4, 5), |
---|
37 | 'type' => MENU_LOCAL_TASK, |
---|
38 | 'access callback' => 'diff_node_revision_access', |
---|
39 | 'access arguments' => array(1), |
---|
40 | 'tab_parent' => 'proyectosop/%', |
---|
41 | ); |
---|
42 | |
---|
43 | return $items; |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Implementation of hook_action_info(). |
---|
48 | * asignar los proyectos operativos a los usuarios. |
---|
49 | */ |
---|
50 | function proyectos_operativos_revision_action_info() { |
---|
51 | return array( |
---|
52 | 'proyectos_operativos_revision_action' => array( |
---|
53 | 'description' => t('Compara los tipos de contenido'), |
---|
54 | 'type' => 'system', |
---|
55 | 'configurable' => true, |
---|
56 | ), |
---|
57 | ); |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * implementacion del hook_action_submit() |
---|
62 | */ |
---|
63 | function proyectos_operativos_revision_action_submit($form, $form_state) { |
---|
64 | foreach ($form_state['storage']['selection'] as $id => $info) { |
---|
65 | if($info->vid) { |
---|
66 | $vids[] = $info->vid; |
---|
67 | } |
---|
68 | if($info->node_revisions_title) { |
---|
69 | $titles[] = $info->node_revisions_title; |
---|
70 | } |
---|
71 | if($info->node_nid) { |
---|
72 | $nids[] = $info->node_nid; |
---|
73 | } |
---|
74 | if($info->users_uid) { |
---|
75 | $users[] = $info->users_uid; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | $old_vid = min($vids[0], $vids[1]); |
---|
80 | $new_vid = max($vids[0], $vids[1]); |
---|
81 | drupal_goto('proyectosop/'. $nids[0] .'/revisions/view/'. $old_vid .'/'. $new_vid); |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * Implementar la accion |
---|
86 | */ |
---|
87 | function proyectos_operativos_revision_action(&$node, $context) { |
---|
88 | module_load_include('inc', 'node', 'node.pages'); |
---|
89 | module_load_include('inc', 'diff', 'diff.pages'); |
---|
90 | |
---|
91 | //$output = proyectos_operativos_revision_diff_diffs_show($node, $context['vid']); |
---|
92 | drupal_set_message(t('Los proyectos Fueron Comparados')); |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * Validation for input form to select two revisions. |
---|
97 | */ |
---|
98 | function proyectos_operativos_revision_action_validate($form, $form_state) { |
---|
99 | foreach ($form_state['values']['objects']['selection'] as $id => $info) { |
---|
100 | if($info) { |
---|
101 | $vids[] = $info; |
---|
102 | } |
---|
103 | } |
---|
104 | if (count($vids) != 2) { |
---|
105 | form_set_error('op', t('Porfavor seleccione solo dos articulos a comparar.')); |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * Implementation of hook_form_alter() |
---|
111 | */ |
---|
112 | function proyectos_operativos_revision_form_alter(&$form, $form_state, $form_id) { |
---|
113 | if ($form_id == 'workflow_tab_form' && $form['node']['#value']->type == 'proyectos_operativos') { |
---|
114 | $form['#submit'][] = 'proyectos_operativos_revision_workflow_tab_form_submit'; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * agrega la informacion del nodo, asi como la del flujo de trabajo |
---|
120 | */ |
---|
121 | function proyectos_operativos_revision_workflow_tab_form_submit($form, &$form_state) { |
---|
122 | $values = $form_state['values']; |
---|
123 | db_query("INSERT INTO {proyectos_operativos_workflow_revision} (nid, vid, sid) VALUES (%d, %d, %d)", $values['node']->nid, $values['node']->vid, $values['workflow']); |
---|
124 | } |
---|
125 | |
---|
126 | /** |
---|
127 | * Presenta el nombre del estado del flujo de trabajo |
---|
128 | */ |
---|
129 | function proyectos_operativos_revision_workflow_search($sid) { |
---|
130 | $result = db_result(db_query("SELECT w.state FROM {workflow_states} AS w INNER JOIN {proyectos_operativos_workflow_revision} AS p ON p.sid = w.sid WHERE p.sid = %d", $sid)); |
---|
131 | return $result; |
---|
132 | } |
---|
133 | |
---|
134 | /** |
---|
135 | * Presenta el comentario del estado del flujo de trabajo |
---|
136 | */ |
---|
137 | function proyectos_operativos_revision_workflow_comment_search($sid) { |
---|
138 | $result = db_result(db_query("SELECT w.comment FROM {workflow_node_history} AS w INNER JOIN {proyectos_operativos_workflow_revision} AS p ON p.sid = w.sid WHERE p.sid = %d AND w.comment!=''", $sid)); |
---|
139 | return $result; |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * Implementation of hook_views_api(). |
---|
144 | */ |
---|
145 | function proyectos_operativos_revision_views_api() { |
---|
146 | return array( |
---|
147 | 'api' => '2.0', |
---|
148 | 'path' => drupal_get_path('module', 'proyectos_operativos_revision') . '/views', |
---|
149 | ); |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * Create output string for a comparison of 'node' between |
---|
154 | * versions 'old_vid' and 'new_vid'. |
---|
155 | * |
---|
156 | * @param $node |
---|
157 | * Node on which to perform comparison |
---|
158 | * @param $old_vid |
---|
159 | * Version ID of the old revision. |
---|
160 | * @param $new_vid |
---|
161 | * Version ID of the new revision. |
---|
162 | */ |
---|
163 | function proyectos_operativos_revision_diff_diffs_show($node, $old_vid, $new_vid) { |
---|
164 | module_load_include('inc', 'diff', 'diff.pages'); |
---|
165 | // Set same title as on the 'Revisions' tab for consistency |
---|
166 | drupal_set_title(t('Revisions for %title', array('%title' => $node->title))); |
---|
167 | |
---|
168 | $node_revisions = node_revision_list($node); |
---|
169 | |
---|
170 | $old_node = node_load($node->nid, $old_vid); |
---|
171 | $new_node = node_load($node->nid, $new_vid); |
---|
172 | |
---|
173 | // Generate table header (date, username, logmessage). |
---|
174 | $old_header = t('!date by !username', array( |
---|
175 | '!date' => l(format_date($old_node->revision_timestamp), "proyectosop/$node->nid/revisions/$old_node->vid/view"), |
---|
176 | '!username' => theme('username', $node_revisions[$old_vid]), |
---|
177 | )); |
---|
178 | $new_header = t('!date by !username', array( |
---|
179 | '!date' => l(format_date($new_node->revision_timestamp), "proyectosop/$node->nid/revisions/$new_node->vid/view"), |
---|
180 | '!username' => theme('username', $node_revisions[$new_vid]), |
---|
181 | )); |
---|
182 | |
---|
183 | $old_log = $old_node->log != '' ? '<p class="revision-log">'. filter_xss($old_node->log) .'</p>' : ''; |
---|
184 | $new_log = $new_node->log != '' ? '<p class="revision-log">'. filter_xss($new_node->log) .'</p>' : ''; |
---|
185 | |
---|
186 | // Generate previous diff/next diff links. |
---|
187 | $next_vid = _diff_get_next_vid($node_revisions, $new_vid); |
---|
188 | if ($next_vid) { |
---|
189 | $next_link = l(t('next diff >'), 'proyectosop/'. $node->nid .'/revisions/view/'. $new_vid .'/'. $next_vid); |
---|
190 | } |
---|
191 | else { |
---|
192 | $next_link = ''; |
---|
193 | } |
---|
194 | $prev_vid = _diff_get_previous_vid($node_revisions, $old_vid); |
---|
195 | if ($prev_vid) { |
---|
196 | $prev_link = l(t('< previous diff'), 'proyectosop/'. $node->nid .'/revisions/view/'. $prev_vid .'/'. $old_vid); |
---|
197 | } |
---|
198 | else { |
---|
199 | $prev_link = ''; |
---|
200 | } |
---|
201 | |
---|
202 | $cols = _diff_default_cols(); |
---|
203 | $header = _diff_default_header($old_header, $new_header); |
---|
204 | $rows = array(); |
---|
205 | if ($old_log || $new_log) { |
---|
206 | $rows[] = array( |
---|
207 | array( |
---|
208 | 'data' => $old_log, |
---|
209 | 'colspan' => 2 |
---|
210 | ), |
---|
211 | array( |
---|
212 | 'data' => $new_log, |
---|
213 | 'colspan' => 2 |
---|
214 | ) |
---|
215 | ); |
---|
216 | } |
---|
217 | $rows[] = array( |
---|
218 | array( |
---|
219 | 'data' => $prev_link, |
---|
220 | 'class' => 'diff-prevlink', |
---|
221 | 'colspan' => 2 |
---|
222 | ), |
---|
223 | array( |
---|
224 | 'data' => $next_link, |
---|
225 | 'class' => 'diff-nextlink', |
---|
226 | 'colspan' => 2 |
---|
227 | ) |
---|
228 | ); |
---|
229 | $rows = array_merge($rows, _diff_body_rows($old_node, $new_node)); |
---|
230 | $output = theme('diff_table', $header, $rows, array('class' => 'diff'), NULL, $cols); |
---|
231 | |
---|
232 | if ($node->vid == $new_vid) { |
---|
233 | $output .= '<div class="diff-section-title">'. t('Current revision:') .'</div>'; |
---|
234 | } |
---|
235 | else { |
---|
236 | $output .= '<div class="diff-section-title">'. t('Revision of !new_date:', array('!new_date' => format_date($new_node->revision_timestamp))) .'</div>'; |
---|
237 | } |
---|
238 | // Don't include node links (final argument) when viewing the diff. |
---|
239 | $output .= theme('proyectos_operativos_mcti_ficha_proyecto', $new_node); |
---|
240 | //$output .= node_view($new_node, FALSE, FALSE, FALSE); |
---|
241 | return $output; |
---|
242 | } |
---|