Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 | 7 | +--------------------------------------------------------------------+ |
e7112fa7 CW |
8 | | This file is a part of CiviCRM. | |
9 | | | | |
6a488035 | 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
e7112fa7 CW |
11 | | under the terms of the GNU Affero General Public License | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
6a488035 | 25 | +--------------------------------------------------------------------+ |
e70a7fc0 | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
fa938177 | 31 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
32 | */ |
33 | class CRM_Report_Form_Event_ParticipantListCount extends CRM_Report_Form_Event { | |
34 | ||
35 | protected $_summary = NULL; | |
26dcc739 E |
36 | protected $_groupFilter = TRUE; |
37 | protected $_tagFilter = TRUE; | |
6a488035 | 38 | protected $_customGroupExtends = array( |
0f18adb9 E |
39 | 'Participant', |
40 | 'Event', | |
41 | ); | |
1728e9a0 | 42 | /** |
43 | * This report has not been optimised for group filtering. | |
44 | * | |
45 | * The functionality for group filtering has been improved but not | |
46 | * all reports have been adjusted to take care of it. This report has not | |
47 | * and will run an inefficient query until fixed. | |
48 | * | |
49 | * CRM-19170 | |
50 | * | |
51 | * @var bool | |
52 | */ | |
53 | protected $groupFilterNotOptimised = TRUE; | |
6a488035 TO |
54 | |
55 | public $_drilldownReport = array('event/income' => 'Link to Detail Report'); | |
74cf4551 | 56 | |
74cf4551 | 57 | /** |
73b448bf | 58 | * Class constructor. |
74cf4551 | 59 | */ |
00be9182 | 60 | public function __construct() { |
6a488035 | 61 | $this->_columns = array( |
9d72cede | 62 | 'civicrm_contact' => array( |
6a488035 | 63 | 'dao' => 'CRM_Contact_DAO_Contact', |
9d72cede EM |
64 | 'fields' => array( |
65 | 'sort_name' => array( | |
66 | 'title' => ts('Name'), | |
6a488035 TO |
67 | 'default' => TRUE, |
68 | 'no_repeat' => TRUE, | |
69 | 'required' => TRUE, | |
70 | ), | |
70bea8e2 | 71 | 'first_name' => array( |
72 | 'title' => ts('First Name'), | |
73 | ), | |
74 | 'middle_name' => array( | |
75 | 'title' => ts('Middle Name'), | |
76 | ), | |
77 | 'last_name' => array( | |
78 | 'title' => ts('Last Name'), | |
79 | ), | |
9d72cede | 80 | 'id' => array( |
6a488035 TO |
81 | 'no_display' => TRUE, |
82 | 'required' => TRUE, | |
83 | ), | |
70bea8e2 | 84 | 'gender_id' => array( |
85 | 'title' => ts('Gender'), | |
86 | ), | |
87 | 'birth_date' => array( | |
88 | 'title' => ts('Birth Date'), | |
89 | ), | |
90 | 'age' => array( | |
91 | 'title' => ts('Age'), | |
92 | 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())', | |
93 | ), | |
94 | 'contact_type' => array( | |
95 | 'title' => ts('Contact Type'), | |
96 | ), | |
97 | 'contact_sub_type' => array( | |
98 | 'title' => ts('Contact Subtype'), | |
99 | ), | |
6a488035 | 100 | ), |
6a488035 | 101 | 'filters' => array( |
9d72cede EM |
102 | 'sort_name' => array( |
103 | 'title' => ts('Participant Name'), | |
6a488035 TO |
104 | 'operator' => 'like', |
105 | ), | |
70bea8e2 | 106 | 'id' => array( |
107 | 'title' => ts('Contact ID'), | |
108 | 'no_display' => TRUE, | |
109 | ), | |
110 | 'gender_id' => array( | |
111 | 'title' => ts('Gender'), | |
112 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
113 | 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), | |
114 | ), | |
115 | 'birth_date' => array( | |
116 | 'title' => ts('Birth Date'), | |
117 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
118 | ), | |
119 | 'contact_type' => array( | |
120 | 'title' => ts('Contact Type'), | |
121 | ), | |
122 | 'contact_sub_type' => array( | |
123 | 'title' => ts('Contact Subtype'), | |
124 | ), | |
125 | ), | |
126 | 'grouping' => 'contact-fields', | |
127 | 'order_bys' => array( | |
47d66b4c | 128 | 'sort_name' => array( |
129 | 'title' => ts('Last Name, First Name'), | |
130 | 'default' => '1', | |
131 | 'default_weight' => '0', | |
132 | 'default_order' => 'ASC', | |
133 | ), | |
70bea8e2 | 134 | 'first_name' => array( |
135 | 'name' => 'first_name', | |
136 | 'title' => ts('First Name'), | |
137 | ), | |
138 | 'gender_id' => array( | |
139 | 'name' => 'gender_id', | |
140 | 'title' => ts('Gender'), | |
141 | ), | |
142 | 'birth_date' => array( | |
143 | 'name' => 'birth_date', | |
144 | 'title' => ts('Birth Date'), | |
145 | ), | |
146 | 'contact_type' => array( | |
147 | 'title' => ts('Contact Type'), | |
148 | ), | |
149 | 'contact_sub_type' => array( | |
150 | 'title' => ts('Contact Subtype'), | |
151 | ), | |
6a488035 TO |
152 | ), |
153 | ), | |
9d72cede EM |
154 | 'civicrm_employer' => array( |
155 | 'dao' => 'CRM_Contact_DAO_Contact', | |
156 | 'grouping' => 'contact-fields', | |
157 | 'fields' => array( | |
158 | 'id' => array( | |
159 | 'no_display' => TRUE, | |
160 | 'required' => TRUE, | |
9cd28c89 DL |
161 | ), |
162 | 'organization_name' => array( | |
ccc29f8e | 163 | 'title' => ts('Employer'), |
9d72cede EM |
164 | 'default' => TRUE, |
165 | 'no_repeat' => TRUE, | |
9cd28c89 DL |
166 | ), |
167 | ), | |
168 | ), | |
9d72cede | 169 | 'civicrm_email' => array( |
6a488035 TO |
170 | 'dao' => 'CRM_Core_DAO_Email', |
171 | 'fields' => array( | |
9d72cede EM |
172 | 'email' => array( |
173 | 'title' => ts('Email'), | |
6a488035 TO |
174 | 'no_repeat' => TRUE, |
175 | ), | |
176 | ), | |
177 | 'grouping' => 'contact-fields', | |
9d72cede EM |
178 | 'filters' => array( |
179 | 'email' => array( | |
180 | 'title' => ts('Participant E-mail'), | |
6a488035 TO |
181 | 'operator' => 'like', |
182 | ), | |
183 | ), | |
184 | ), | |
9d72cede EM |
185 | 'civicrm_phone' => array( |
186 | 'dao' => 'CRM_Core_DAO_Phone', | |
187 | 'grouping' => 'contact-fields', | |
188 | 'fields' => array( | |
189 | 'phone' => array( | |
190 | 'title' => ts('Phone No'), | |
191 | 'default' => TRUE, | |
192 | ), | |
193 | ), | |
194 | ), | |
195 | 'civicrm_address' => array( | |
6a488035 | 196 | 'dao' => 'CRM_Core_DAO_Address', |
9d72cede | 197 | 'fields' => array( |
6a488035 | 198 | 'street_address' => NULL, |
9cd28c89 DL |
199 | 'city' => NULL, |
200 | 'postal_code' => NULL, | |
9d72cede EM |
201 | 'state_province_id' => array( |
202 | 'title' => ts('State/Province'), | |
9cd28c89 | 203 | ), |
9d72cede EM |
204 | 'country_id' => array( |
205 | 'title' => ts('Country'), | |
9cd28c89 | 206 | ), |
6a488035 TO |
207 | ), |
208 | 'grouping' => 'contact-fields', | |
209 | ), | |
9d72cede | 210 | 'civicrm_participant' => array( |
6a488035 | 211 | 'dao' => 'CRM_Event_DAO_Participant', |
9d72cede EM |
212 | 'fields' => array( |
213 | 'participant_id' => array( | |
214 | 'title' => ts('Participant ID'), | |
6a488035 TO |
215 | 'default' => TRUE, |
216 | ), | |
9d72cede EM |
217 | 'event_id' => array( |
218 | 'title' => ts('Event'), | |
6a488035 TO |
219 | 'type' => CRM_Utils_Type::T_STRING, |
220 | ), | |
9d72cede EM |
221 | 'role_id' => array( |
222 | 'title' => ts('Role'), | |
6a488035 TO |
223 | 'default' => TRUE, |
224 | ), | |
9d72cede EM |
225 | 'status_id' => array( |
226 | 'title' => ts('Status'), | |
6a488035 TO |
227 | 'default' => TRUE, |
228 | ), | |
9d72cede EM |
229 | 'participant_register_date' => array( |
230 | 'title' => ts('Registration Date'), | |
6a488035 TO |
231 | ), |
232 | ), | |
233 | 'grouping' => 'event-fields', | |
9d72cede | 234 | 'filters' => array( |
2107cde9 | 235 | 'event_id' => array( |
6a488035 TO |
236 | 'name' => 'event_id', |
237 | 'title' => ts('Event'), | |
2107cde9 CW |
238 | 'operatorType' => CRM_Report_Form::OP_ENTITYREF, |
239 | 'type' => CRM_Utils_Type::T_INT, | |
9d72cede EM |
240 | 'attributes' => array( |
241 | 'entity' => 'event', | |
21dfd5f5 | 242 | 'select' => array('minimumInputLength' => 0), |
9d72cede | 243 | ), |
6a488035 | 244 | ), |
9d72cede | 245 | 'sid' => array( |
6a488035 TO |
246 | 'name' => 'status_id', |
247 | 'title' => ts('Participant Status'), | |
525ae77a | 248 | 'type' => CRM_Utils_Type::T_INT, |
6a488035 TO |
249 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
250 | 'options' => CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'), | |
251 | ), | |
9d72cede | 252 | 'rid' => array( |
6a488035 TO |
253 | 'name' => 'role_id', |
254 | 'title' => ts('Participant Role'), | |
2039ce87 | 255 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT_SEPARATOR, |
1c193324 | 256 | 'type' => CRM_Utils_Type::T_INT, |
6a488035 TO |
257 | 'options' => CRM_Event_PseudoConstant::participantRole(), |
258 | ), | |
9d72cede EM |
259 | 'participant_register_date' => array( |
260 | 'title' => ts('Registration Date'), | |
6a488035 TO |
261 | 'operatorType' => CRM_Report_Form::OP_DATE, |
262 | ), | |
263 | ), | |
9d72cede EM |
264 | 'group_bys' => array( |
265 | 'event_id' => array( | |
266 | 'title' => ts('Event'), | |
6a488035 TO |
267 | ), |
268 | ), | |
269 | ), | |
9d72cede | 270 | 'civicrm_event' => array( |
6a488035 | 271 | 'dao' => 'CRM_Event_DAO_Event', |
9d72cede EM |
272 | 'fields' => array( |
273 | 'event_type_id' => array( | |
274 | 'title' => ts('Event Type'), | |
6a488035 | 275 | ), |
9d72cede EM |
276 | 'start_date' => array( |
277 | 'title' => ts('Event Start Date'), | |
6a488035 | 278 | ), |
9d72cede EM |
279 | 'end_date' => array( |
280 | 'title' => ts('Event End Date'), | |
6a488035 TO |
281 | ), |
282 | ), | |
283 | 'grouping' => 'event-fields', | |
284 | 'filters' => array( | |
9d72cede | 285 | 'eid' => array( |
6a488035 TO |
286 | 'name' => 'event_type_id', |
287 | 'title' => ts('Event Type'), | |
525ae77a | 288 | 'type' => CRM_Utils_Type::T_INT, |
6a488035 TO |
289 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, |
290 | 'options' => CRM_Core_OptionGroup::values('event_type'), | |
291 | ), | |
9d72cede | 292 | 'event_start_date' => array( |
c4c31bc4 | 293 | 'name' => 'event_start_date', |
6a488035 TO |
294 | 'title' => ts('Event Start Date'), |
295 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
296 | ), | |
9d72cede | 297 | 'event_end_date' => array( |
c4c31bc4 | 298 | 'name' => 'event_end_date', |
6a488035 TO |
299 | 'title' => ts('Event End Date'), |
300 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
301 | ), | |
302 | ), | |
9d72cede EM |
303 | 'group_bys' => array( |
304 | 'event_type_id' => array( | |
305 | 'title' => ts('Event Type '), | |
6a488035 TO |
306 | ), |
307 | ), | |
308 | ), | |
9d72cede | 309 | 'civicrm_line_item' => array( |
6a488035 | 310 | 'dao' => 'CRM_Price_DAO_LineItem', |
9d72cede EM |
311 | 'fields' => array( |
312 | 'line_total' => array( | |
313 | 'title' => ts('Income'), | |
6a488035 | 314 | 'default' => TRUE, |
9d72cede EM |
315 | 'statistics' => array( |
316 | 'sum' => ts('Amount'), | |
6a488035 TO |
317 | 'avg' => ts('Average'), |
318 | ), | |
319 | ), | |
9d72cede EM |
320 | 'participant_count' => array( |
321 | 'title' => ts('Count'), | |
6a488035 | 322 | 'default' => TRUE, |
9d72cede EM |
323 | 'statistics' => array( |
324 | 'sum' => ts('Count'), | |
6a488035 TO |
325 | ), |
326 | ), | |
327 | ), | |
328 | ), | |
329 | ); | |
330 | ||
331 | $this->_options = array( | |
9d72cede EM |
332 | 'blank_column_begin' => array( |
333 | 'title' => ts('Blank column at the Begining'), | |
6a488035 TO |
334 | 'type' => 'checkbox', |
335 | ), | |
9d72cede EM |
336 | 'blank_column_end' => array( |
337 | 'title' => ts('Blank column at the End'), | |
6a488035 TO |
338 | 'type' => 'select', |
339 | 'options' => array( | |
340 | '' => '-select-', | |
341 | 1 => ts('One'), | |
342 | 2 => ts('Two'), | |
343 | 3 => ts('Three'), | |
344 | ), | |
345 | ), | |
346 | ); | |
347 | parent::__construct(); | |
348 | } | |
349 | ||
00be9182 | 350 | public function preProcess() { |
6a488035 TO |
351 | parent::preProcess(); |
352 | } | |
353 | ||
74cf4551 | 354 | /** |
fe482240 | 355 | * Add The statistics. |
74cf4551 EM |
356 | * @param $rows |
357 | * | |
358 | * @return array | |
359 | */ | |
00be9182 | 360 | public function statistics(&$rows) { |
6a488035 TO |
361 | |
362 | $statistics = parent::statistics($rows); | |
9d72cede EM |
363 | $avg = NULL; |
364 | $select = " SELECT SUM( {$this->_aliases['civicrm_line_item']}.participant_count ) as count, | |
2f4c2f5d | 365 | SUM( {$this->_aliases['civicrm_line_item']}.line_total ) as amount |
366 | "; | |
6a488035 TO |
367 | $sql = "{$select} {$this->_from} {$this->_where}"; |
368 | $dao = CRM_Core_DAO::executeQuery($sql); | |
369 | if ($dao->fetch()) { | |
370 | ||
371 | if ($dao->count && $dao->amount) { | |
372 | $avg = $dao->amount / $dao->count; | |
373 | } | |
374 | $statistics['counts']['count'] = array( | |
375 | 'value' => $dao->count, | |
ccc29f8e | 376 | 'title' => ts('Total Participants'), |
6a488035 TO |
377 | 'type' => CRM_Utils_Type::T_INT, |
378 | ); | |
379 | $statistics['counts']['amount'] = array( | |
380 | 'value' => $dao->amount, | |
ccc29f8e | 381 | 'title' => ts('Total Income'), |
6a488035 TO |
382 | 'type' => CRM_Utils_Type::T_MONEY, |
383 | ); | |
ccc29f8e | 384 | $statistics['counts']['avg'] = array( |
6a488035 | 385 | 'value' => $avg, |
ccc29f8e | 386 | 'title' => ts('Average'), |
6a488035 TO |
387 | 'type' => CRM_Utils_Type::T_MONEY, |
388 | ); | |
389 | } | |
390 | ||
391 | return $statistics; | |
392 | } | |
393 | ||
00be9182 | 394 | public function select() { |
6a488035 TO |
395 | $select = array(); |
396 | $this->_columnHeaders = array(); | |
397 | ||
398 | //add blank column at the Start | |
9d72cede EM |
399 | if (array_key_exists('options', $this->_params) && |
400 | !empty($this->_params['options']['blank_column_begin']) | |
401 | ) { | |
6a488035 TO |
402 | $select[] = " '' as blankColumnBegin"; |
403 | $this->_columnHeaders['blankColumnBegin']['title'] = '_ _ _ _'; | |
404 | } | |
405 | foreach ($this->_columns as $tableName => $table) { | |
406 | if (array_key_exists('fields', $table)) { | |
407 | foreach ($table['fields'] as $fieldName => $field) { | |
9d72cede EM |
408 | if (!empty($field['required']) || |
409 | !empty($this->_params['fields'][$fieldName]) | |
410 | ) { | |
a7488080 | 411 | if (!empty($field['statistics'])) { |
6a488035 TO |
412 | foreach ($field['statistics'] as $stat => $label) { |
413 | switch (strtolower($stat)) { | |
414 | case 'sum': | |
415 | $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}"; | |
416 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT; | |
417 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label; | |
418 | $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}"; | |
419 | break; | |
420 | } | |
421 | } | |
422 | } | |
423 | else { | |
424 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; | |
425 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
426 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
427 | } | |
428 | } | |
429 | } | |
430 | } | |
431 | } | |
432 | //add blank column at the end | |
433 | if ($blankcols = CRM_Utils_Array::value('blank_column_end', $this->_params)) { | |
434 | for ($i = 1; $i <= $blankcols; $i++) { | |
435 | $select[] = " '' as blankColumnEnd_{$i}"; | |
436 | $this->_columnHeaders["blank_{$i}"]['title'] = "_ _ _ _"; | |
437 | } | |
438 | } | |
d1641c51 | 439 | $this->_selectClauses = $select; |
6a488035 TO |
440 | $this->_select = "SELECT " . implode(', ', $select) . " "; |
441 | } | |
442 | ||
74cf4551 EM |
443 | /** |
444 | * @param $fields | |
445 | * @param $files | |
446 | * @param $self | |
447 | * | |
448 | * @return array | |
449 | */ | |
00be9182 | 450 | public static function formRule($fields, $files, $self) { |
6a488035 TO |
451 | $errors = $grouping = array(); |
452 | return $errors; | |
453 | } | |
454 | ||
00be9182 | 455 | public function from() { |
6a488035 | 456 | $this->_from = " |
f813f78e | 457 | FROM civicrm_participant {$this->_aliases['civicrm_participant']} |
458 | LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']} | |
99f13d8d | 459 | ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND {$this->_aliases['civicrm_event']}.is_template = 0 |
f813f78e | 460 | LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} |
461 | ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) | |
462 | {$this->_aclFrom} | |
463 | LEFT JOIN civicrm_contact {$this->_aliases['civicrm_employer']} | |
464 | ON ({$this->_aliases['civicrm_employer']}.id = {$this->_aliases['civicrm_contact']}.employer_id ) | |
465 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} | |
466 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND | |
467 | {$this->_aliases['civicrm_address']}.is_primary = 1 | |
468 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} | |
469 | ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND | |
470 | {$this->_aliases['civicrm_email']}.is_primary = 1) | |
2f4c2f5d | 471 | LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} |
6a488035 TO |
472 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND |
473 | {$this->_aliases['civicrm_phone']}.is_primary = 1 | |
2f4c2f5d | 474 | LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']} |
5fa8e57d | 475 | ON {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant' AND {$this->_aliases['civicrm_participant']}.id ={$this->_aliases['civicrm_line_item']}.entity_id"; |
6a488035 TO |
476 | } |
477 | ||
00be9182 | 478 | public function storeWhereHavingClauseArray() { |
e8b2628d DS |
479 | parent::storeWhereHavingClauseArray(); |
480 | $this->_whereClauses[] = "{$this->_aliases['civicrm_participant']}.is_test = 0"; | |
6a488035 TO |
481 | } |
482 | ||
00be9182 | 483 | public function groupBy() { |
0179fdce | 484 | // We override this function because we use GROUP functions in the |
485 | // SELECT clause, therefore we have to group by *something*. If the | |
486 | // user doesn't select a column to group by, we should group by participant id. | |
a49d6344 | 487 | parent::groupBy(); |
0179fdce | 488 | if (empty($this->_groupBy)) { |
b708c08d | 489 | $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, "{$this->_aliases['civicrm_participant']}.id"); |
6a488035 | 490 | } |
6a488035 TO |
491 | } |
492 | ||
00be9182 | 493 | public function postProcess() { |
6a488035 TO |
494 | |
495 | // get ready with post process params | |
496 | $this->beginPostProcess(); | |
497 | ||
498 | // get the acl clauses built before we assemble the query | |
499 | $this->buildACLClause($this->_aliases['civicrm_contact']); | |
500 | // build query | |
501 | $sql = $this->buildQuery(TRUE); | |
502 | ||
503 | // build array of result based on column headers. This method also allows | |
504 | // modifying column headers before using it to build result set i.e $rows. | |
505 | $this->buildRows($sql, $rows); | |
506 | ||
507 | // format result set. | |
508 | $this->formatDisplay($rows); | |
509 | ||
510 | // assign variables to templates | |
511 | $this->doTemplateAssignment($rows); | |
512 | ||
513 | // do print / pdf / instance stuff if needed | |
514 | $this->endPostProcess($rows); | |
515 | } | |
516 | ||
74cf4551 | 517 | /** |
ced9bfed EM |
518 | * Alter display of rows. |
519 | * | |
520 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
521 | * such as rendering contacts as links. | |
522 | * | |
523 | * @param array $rows | |
524 | * Rows generated by SQL, with an array for each row. | |
74cf4551 | 525 | */ |
00be9182 | 526 | public function alterDisplay(&$rows) { |
6a488035 TO |
527 | $entryFound = FALSE; |
528 | $eventType = CRM_Core_OptionGroup::values('event_type'); | |
529 | ||
530 | foreach ($rows as $rowNum => $row) { | |
531 | ||
532 | // convert sort name to links | |
533 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
534 | array_key_exists('civicrm_contact_id', $row) | |
535 | ) { | |
536 | if ($value = $row['civicrm_contact_sort_name']) { | |
537 | $url = CRM_Utils_System::url("civicrm/contact/view", | |
538 | 'reset=1&cid=' . $row['civicrm_contact_id'], | |
539 | $this->_absoluteUrl | |
540 | ); | |
541 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
542 | $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact."); | |
543 | } | |
544 | $entryFound = TRUE; | |
545 | } | |
546 | ||
547 | // convert participant ID to links | |
548 | if (array_key_exists('civicrm_participant_participant_id', $row) && | |
549 | array_key_exists('civicrm_contact_id', $row) | |
550 | ) { | |
551 | if ($value = $row['civicrm_participant_participant_id']) { | |
552 | $url = CRM_Utils_System::url("civicrm/contact/view/participant", | |
9d72cede EM |
553 | 'reset=1&id=' . $row['civicrm_participant_participant_id'] . |
554 | '&cid=' . $row['civicrm_contact_id'] . | |
555 | '&action=view&context=participant', | |
6a488035 TO |
556 | $this->_absoluteUrl |
557 | ); | |
558 | $rows[$rowNum]['civicrm_participant_participant_id_link'] = $url; | |
559 | $rows[$rowNum]['civicrm_participant_participant_id_hover'] = ts("View Participant Record for this Contact."); | |
560 | } | |
561 | $entryFound = TRUE; | |
562 | } | |
563 | ||
564 | // convert event name to links | |
565 | if (array_key_exists('civicrm_participant_event_id', $row)) { | |
566 | if ($value = $row['civicrm_participant_event_id']) { | |
567 | $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant::event($value, FALSE); | |
568 | $url = CRM_Report_Utils_Report::getNextUrl('event/Income', | |
569 | 'reset=1&force=1&event_id_op=eq&event_id_value=' . $value, | |
570 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport | |
571 | ); | |
572 | $rows[$rowNum]['civicrm_participant_event_id_link'] = $url; | |
573 | $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event"); | |
574 | } | |
575 | $entryFound = TRUE; | |
576 | } | |
577 | ||
578 | // handle event type id | |
579 | if (array_key_exists('civicrm_event_event_type_id', $row)) { | |
580 | if ($value = $row['civicrm_event_event_type_id']) { | |
581 | $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value]; | |
582 | } | |
583 | $entryFound = TRUE; | |
584 | } | |
585 | ||
586 | // handle participant status id | |
587 | if (array_key_exists('civicrm_participant_status_id', $row)) { | |
588 | if ($value = $row['civicrm_participant_status_id']) { | |
589 | $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant::participantStatus($value, FALSE); | |
590 | } | |
591 | $entryFound = TRUE; | |
592 | } | |
593 | ||
594 | // handle participant role id | |
595 | if (array_key_exists('civicrm_participant_role_id', $row)) { | |
596 | if ($value = $row['civicrm_participant_role_id']) { | |
597 | $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value); | |
598 | $value = array(); | |
599 | foreach ($roles as $role) { | |
600 | $value[$role] = CRM_Event_PseudoConstant::participantRole($role, FALSE); | |
601 | } | |
602 | $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $value); | |
603 | } | |
604 | $entryFound = TRUE; | |
605 | } | |
606 | ||
70bea8e2 | 607 | //handle gender |
608 | if (array_key_exists('civicrm_contact_gender_id', $row)) { | |
609 | if ($value = $row['civicrm_contact_gender_id']) { | |
610 | $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); | |
611 | $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value]; | |
612 | } | |
613 | $entryFound = TRUE; | |
614 | } | |
615 | ||
616 | // display birthday in the configured custom format | |
617 | if (array_key_exists('civicrm_contact_birth_date', $row)) { | |
618 | $birthDate = $row['civicrm_contact_birth_date']; | |
619 | if ($birthDate) { | |
620 | $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d'); | |
621 | } | |
622 | $entryFound = TRUE; | |
623 | } | |
624 | ||
6a488035 TO |
625 | // skip looking further in rows, if first row itself doesn't |
626 | // have the column we need | |
627 | if (!$entryFound) { | |
628 | break; | |
629 | } | |
630 | } | |
631 | } | |
96025800 | 632 | |
6a488035 | 633 | } |