Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
232624b1 | 5 | | CiviCRM version 4.4 | |
6a488035 TO |
6 | +--------------------------------------------------------------------+ |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
33 | * $Id$ | |
34 | * | |
35 | */ | |
36 | class CRM_Report_Form_Grant_Detail extends CRM_Report_Form { | |
37 | ||
38 | protected $_addressField = FALSE; | |
39 | ||
40 | protected $_customGroupExtends = array( | |
41 | 'Grant'); | |
42 | ||
43 | function __construct() { | |
44 | $this->_columns = array( | |
45 | 'civicrm_contact' => | |
46 | array( | |
47 | 'dao' => 'CRM_Contact_DAO_Contact', | |
48 | 'fields' => | |
49 | array( | |
50 | 'sort_name' => | |
51 | array('title' => ts('Contact Name'), | |
52 | 'required' => TRUE, | |
53 | 'no_repeat' => TRUE, | |
54 | ), | |
55 | 'id' => | |
56 | array( | |
57 | 'no_display' => TRUE, | |
58 | 'required' => TRUE, | |
59 | ), | |
60 | ), | |
61 | 'grouping' => 'contact-fields', | |
62 | 'filters' => | |
63 | array( | |
64 | 'sort_name' => | |
65 | array('title' => ts('Contact Name'), | |
66 | 'operator' => 'like', | |
67 | ), | |
68 | 'gender_id' => | |
69 | array('title' => ts('Gender'), | |
70 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
26cf88b5 | 71 | 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), |
6a488035 TO |
72 | ), |
73 | 'id' => | |
74 | array('title' => ts('Contact ID'), | |
75 | 'no_display' => TRUE, | |
76 | ), | |
77 | ), | |
78 | ), | |
79 | 'civicrm_address' => | |
80 | array( | |
81 | 'dao' => 'CRM_Core_DAO_Address', | |
82 | 'filters' => | |
83 | array( | |
84 | 'country_id' => | |
85 | array('title' => ts('Country'), | |
86 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
87 | 'options' => CRM_Core_PseudoConstant::country(), | |
88 | ), | |
89 | 'state_province_id' => | |
90 | array('title' => ts('State/Province'), | |
91 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
92 | 'options' => CRM_Core_PseudoConstant::stateProvince(), | |
93 | ), | |
94 | ), | |
95 | ), | |
96 | 'civicrm_grant' => | |
97 | array( | |
98 | 'dao' => 'CRM_Grant_DAO_Grant', | |
99 | 'fields' => | |
100 | array( | |
101 | 'grant_type_id' => | |
102 | array( | |
103 | 'name' => 'grant_type_id', | |
104 | 'title' => ts('Grant Type'), | |
105 | ), | |
6a488035 TO |
106 | 'status_id' => |
107 | array( | |
108 | 'name' => 'status_id', | |
109 | 'title' => ts('Grant Status'), | |
110 | ), | |
111 | 'amount_total' => | |
112 | array( | |
113 | 'name' => 'amount_total', | |
114 | 'title' => ts('Amount Requested'), | |
115 | 'type' => CRM_Utils_Type::T_MONEY, | |
116 | ), | |
117 | 'amount_granted' => | |
118 | array( | |
119 | 'name' => 'amount_granted', | |
120 | 'title' => ts('Amount Granted'), | |
121 | ), | |
122 | 'application_received_date' => | |
123 | array( | |
124 | 'name' => 'application_received_date', | |
125 | 'title' => ts('Application Received'), | |
126 | 'default' => TRUE, | |
127 | ), | |
128 | 'money_transfer_date' => | |
129 | array( | |
130 | 'name' => 'money_transfer_date', | |
131 | 'title' => ts('Money Transfer Date'), | |
132 | 'type' => CRM_Utils_Type::T_DATE, | |
133 | ), | |
134 | 'grant_due_date' => | |
135 | array( | |
136 | 'name' => 'grant_due_date', | |
137 | 'title' => ts('Grant Report Due'), | |
138 | 'type' => CRM_Utils_Type::T_DATE, | |
139 | ), | |
140 | 'decision_date' => | |
141 | array( | |
142 | 'name' => 'decision_date', | |
143 | 'title' => ts('Grant Decision Date'), | |
144 | 'type' => CRM_Utils_Type::T_DATE, | |
145 | ), | |
146 | 'rationale' => | |
147 | array( | |
148 | 'name' => 'rationale', | |
149 | 'title' => ts('Rationale'), | |
150 | ), | |
151 | 'grant_report_received' => | |
152 | array( | |
153 | 'name' => 'grant_report_received', | |
154 | 'title' => ts('Grant Report Received'), | |
155 | ), | |
156 | ), | |
157 | 'filters' => | |
158 | array( | |
159 | 'grant_type' => | |
160 | array( | |
161 | 'name' => 'grant_type_id', | |
162 | 'title' => ts('Grant Type'), | |
163 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
fb1fd730 | 164 | 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'), |
6a488035 | 165 | ), |
6a488035 TO |
166 | 'status_id' => |
167 | array( | |
168 | 'name' => 'status_id', | |
169 | 'title' => ts('Grant Status'), | |
170 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
fb1fd730 | 171 | 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'), |
6a488035 TO |
172 | ), |
173 | 'amount_granted' => | |
174 | array( | |
175 | 'title' => ts('Amount Granted'), | |
176 | 'operatorType' => CRM_Report_Form::OP_INT, | |
177 | ), | |
178 | 'amount_total' => | |
179 | array( | |
180 | 'title' => ts('Amount Requested'), | |
181 | 'operatorType' => CRM_Report_Form::OP_INT, | |
182 | ), | |
183 | 'application_received_date' => | |
184 | array( | |
185 | 'title' => ts('Application Received'), | |
186 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
187 | ), | |
188 | 'money_transfer_date' => | |
189 | array( | |
190 | 'title' => ts('Money Transfer Date'), | |
191 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
192 | ), | |
193 | 'grant_due_date' => | |
194 | array( | |
195 | 'title' => ts('Grant Report Due'), | |
196 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
197 | 'type' => CRM_Report_Form::OP_DATE, | |
198 | ), | |
199 | 'decision_date' => | |
200 | array( | |
201 | 'title' => ts('Grant Decision Date'), | |
202 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
203 | 'type' => CRM_Utils_Type::T_DATE, | |
204 | ), | |
205 | ), | |
206 | 'group_bys' => | |
207 | array( | |
208 | 'grant_type_id' => | |
209 | array( | |
210 | 'title' => ts('Grant Type'), | |
211 | ), | |
6a488035 TO |
212 | 'status_id' => |
213 | array( | |
214 | 'title' => ts('Grant Status'), | |
215 | ), | |
216 | 'amount_total' => | |
217 | array( | |
218 | 'title' => ts('Amount Requested'), | |
219 | ), | |
220 | 'amount_granted' => | |
221 | array( | |
222 | 'title' => ts('Amount Granted'), | |
223 | ), | |
224 | 'application_received_date' => | |
225 | array( | |
226 | 'title' => ts('Application Received Date'), | |
227 | ), | |
228 | 'money_transfer_date' => | |
229 | array( | |
230 | 'title' => ts('Money Transfer Date'), | |
231 | ), | |
232 | 'decision_date' => | |
233 | array( | |
234 | 'title' => ts('Grant Decision Date'), | |
235 | ), | |
236 | ), | |
237 | ), | |
238 | ); | |
239 | ||
240 | parent::__construct(); | |
241 | } | |
242 | ||
243 | function select() { | |
244 | $select = array(); | |
245 | ||
246 | $this->_columnHeaders = array(); | |
247 | foreach ($this->_columns as $tableName => $table) { | |
248 | if ($tableName == 'civicrm_address') { | |
249 | $this->_addressField = TRUE; | |
250 | } | |
251 | if (array_key_exists('fields', $table)) { | |
252 | foreach ($table['fields'] as $fieldName => $field) { | |
8cc574cf | 253 | if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) { |
6a488035 TO |
254 | |
255 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; | |
256 | ||
257 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
258 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
259 | } | |
260 | } | |
261 | } | |
262 | } | |
263 | ||
264 | $this->_select = "SELECT " . implode(', ', $select) . " "; | |
265 | } | |
266 | ||
267 | function from() { | |
268 | $this->_from = " | |
269 | FROM civicrm_grant {$this->_aliases['civicrm_grant']} | |
b2708486 | 270 | LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} |
6a488035 TO |
271 | ON ({$this->_aliases['civicrm_grant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) "; |
272 | if ($this->_addressField) { | |
273 | $this->_from .= " | |
b2708486 DL |
274 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} |
275 | ON {$this->_aliases['civicrm_contact']}.id = | |
276 | {$this->_aliases['civicrm_address']}.contact_id AND | |
6a488035 TO |
277 | {$this->_aliases['civicrm_address']}.is_primary = 1\n"; |
278 | } | |
279 | } | |
280 | ||
281 | function where() { | |
282 | $clauses = array(); | |
283 | $this->_where = ''; | |
284 | foreach ($this->_columns as $tableName => $table) { | |
285 | if (array_key_exists('filters', $table)) { | |
286 | foreach ($table['filters'] as $fieldName => $field) { | |
287 | ||
288 | $clause = NULL; | |
289 | if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) { | |
290 | $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); | |
291 | $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); | |
292 | $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); | |
293 | ||
294 | if ($relative || $from || $to) { | |
295 | $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']); | |
296 | } | |
297 | } | |
298 | else { | |
299 | $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); | |
300 | if ($op) { | |
301 | $clause = $this->whereClause($field, | |
302 | $op, | |
303 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), | |
304 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), | |
305 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) | |
306 | ); | |
307 | } | |
308 | } | |
309 | if (!empty($clause)) { | |
310 | $clauses[] = $clause; | |
311 | $this->_where = "WHERE " . implode(' AND ', $clauses); | |
312 | } | |
313 | } | |
314 | } | |
315 | } | |
316 | } | |
317 | ||
318 | function groupBy() { | |
319 | $this->_groupBy = ""; | |
a7488080 | 320 | if (!empty($this->_params['group_bys']) && |
6a488035 TO |
321 | is_array($this->_params['group_bys']) && |
322 | !empty($this->_params['group_bys']) | |
323 | ) { | |
324 | foreach ($this->_columns as $tableName => $table) { | |
325 | if (array_key_exists('group_bys', $table)) { | |
326 | foreach ($table['group_bys'] as $fieldName => $field) { | |
a7488080 | 327 | if (!empty($this->_params['group_bys'][$fieldName])) { |
6a488035 TO |
328 | $this->_groupBy[] = $field['dbAlias']; |
329 | } | |
330 | } | |
331 | } | |
332 | } | |
333 | } | |
334 | if (!empty($this->_groupBy)) { | |
335 | $this->_groupBy = "ORDER BY " . implode(', ', $this->_groupBy) . ", {$this->_aliases['civicrm_contact']}.sort_name"; | |
336 | } | |
337 | else { | |
338 | $this->_groupBy = "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name"; | |
339 | } | |
340 | } | |
341 | ||
342 | function alterDisplay(&$rows) { | |
343 | // custom code to alter rows | |
344 | $entryFound = FALSE; | |
345 | foreach ($rows as $rowNum => $row) { | |
346 | // convert display name to links | |
347 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
348 | array_key_exists('civicrm_contact_id', $row) | |
349 | ) { | |
350 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
b2708486 | 351 | 'reset=1&cid=' . $row['civicrm_contact_id'], |
6a488035 TO |
352 | $this->_absoluteUrl |
353 | ); | |
354 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
355 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View contact details for this record."); | |
356 | $entryFound = TRUE; | |
357 | } | |
358 | ||
359 | if (array_key_exists('civicrm_grant_grant_type_id', $row)) { | |
360 | if ($value = $row['civicrm_grant_grant_type_id']) { | |
a8c23526 | 361 | $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Grant_DAO_Grant', 'grant_type_id', $value); |
6a488035 TO |
362 | } |
363 | $entryFound = TRUE; | |
364 | } | |
6a488035 TO |
365 | if (array_key_exists('civicrm_grant_status_id', $row)) { |
366 | if ($value = $row['civicrm_grant_status_id']) { | |
a8c23526 | 367 | $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Grant_DAO_Grant', 'status_id', $value); |
6a488035 TO |
368 | } |
369 | $entryFound = TRUE; | |
370 | } | |
371 | if (array_key_exists('civicrm_grant_grant_report_received', $row)) { | |
372 | if ($value = $row['civicrm_grant_grant_report_received']) { | |
373 | if ($value == 1) { | |
374 | $value = 'Yes'; | |
375 | } | |
376 | else { | |
377 | $value = 'No'; | |
378 | } | |
379 | $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value; | |
380 | } | |
381 | $entryFound = TRUE; | |
382 | } | |
383 | if (!$entryFound) { | |
384 | break; | |
385 | } | |
386 | } | |
387 | } | |
388 | } | |
389 |