Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
e7112fa7 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Report_Form_Event_ParticipantListCount extends CRM_Report_Form_Event { | |
36 | ||
37 | protected $_summary = NULL; | |
26dcc739 E |
38 | protected $_groupFilter = TRUE; |
39 | protected $_tagFilter = TRUE; | |
6a488035 | 40 | protected $_customGroupExtends = array( |
0f18adb9 E |
41 | 'Participant', |
42 | 'Event', | |
43 | ); | |
6a488035 TO |
44 | |
45 | public $_drilldownReport = array('event/income' => 'Link to Detail Report'); | |
74cf4551 | 46 | |
74cf4551 | 47 | /** |
74cf4551 | 48 | */ |
00be9182 | 49 | public function __construct() { |
6a488035 | 50 | $this->_columns = array( |
9d72cede | 51 | 'civicrm_contact' => array( |
6a488035 | 52 | 'dao' => 'CRM_Contact_DAO_Contact', |
9d72cede EM |
53 | 'fields' => array( |
54 | 'sort_name' => array( | |
55 | 'title' => ts('Name'), | |
6a488035 TO |
56 | 'default' => TRUE, |
57 | 'no_repeat' => TRUE, | |
58 | 'required' => TRUE, | |
59 | ), | |
70bea8e2 | 60 | 'first_name' => array( |
61 | 'title' => ts('First Name'), | |
62 | ), | |
63 | 'middle_name' => array( | |
64 | 'title' => ts('Middle Name'), | |
65 | ), | |
66 | 'last_name' => array( | |
67 | 'title' => ts('Last Name'), | |
68 | ), | |
9d72cede | 69 | 'id' => array( |
6a488035 TO |
70 | 'no_display' => TRUE, |
71 | 'required' => TRUE, | |
72 | ), | |
70bea8e2 | 73 | 'gender_id' => array( |
74 | 'title' => ts('Gender'), | |
75 | ), | |
76 | 'birth_date' => array( | |
77 | 'title' => ts('Birth Date'), | |
78 | ), | |
79 | 'age' => array( | |
80 | 'title' => ts('Age'), | |
81 | 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())', | |
82 | ), | |
83 | 'contact_type' => array( | |
84 | 'title' => ts('Contact Type'), | |
85 | ), | |
86 | 'contact_sub_type' => array( | |
87 | 'title' => ts('Contact Subtype'), | |
88 | ), | |
6a488035 | 89 | ), |
6a488035 | 90 | 'filters' => array( |
9d72cede EM |
91 | 'sort_name' => array( |
92 | 'title' => ts('Participant Name'), | |
6a488035 TO |
93 | 'operator' => 'like', |
94 | ), | |
70bea8e2 | 95 | 'id' => array( |
96 | 'title' => ts('Contact ID'), | |
97 | 'no_display' => TRUE, | |
98 | ), | |
99 | 'gender_id' => array( | |
100 | 'title' => ts('Gender'), | |
101 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
102 | 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), | |
103 | ), | |
104 | 'birth_date' => array( | |
105 | 'title' => ts('Birth Date'), | |
106 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
107 | ), | |
108 | 'contact_type' => array( | |
109 | 'title' => ts('Contact Type'), | |
110 | ), | |
111 | 'contact_sub_type' => array( | |
112 | 'title' => ts('Contact Subtype'), | |
113 | ), | |
114 | ), | |
115 | 'grouping' => 'contact-fields', | |
116 | 'order_bys' => array( | |
47d66b4c | 117 | 'sort_name' => array( |
118 | 'title' => ts('Last Name, First Name'), | |
119 | 'default' => '1', | |
120 | 'default_weight' => '0', | |
121 | 'default_order' => 'ASC', | |
122 | ), | |
70bea8e2 | 123 | 'first_name' => array( |
124 | 'name' => 'first_name', | |
125 | 'title' => ts('First Name'), | |
126 | ), | |
127 | 'gender_id' => array( | |
128 | 'name' => 'gender_id', | |
129 | 'title' => ts('Gender'), | |
130 | ), | |
131 | 'birth_date' => array( | |
132 | 'name' => 'birth_date', | |
133 | 'title' => ts('Birth Date'), | |
134 | ), | |
135 | 'contact_type' => array( | |
136 | 'title' => ts('Contact Type'), | |
137 | ), | |
138 | 'contact_sub_type' => array( | |
139 | 'title' => ts('Contact Subtype'), | |
140 | ), | |
6a488035 TO |
141 | ), |
142 | ), | |
9d72cede EM |
143 | 'civicrm_employer' => array( |
144 | 'dao' => 'CRM_Contact_DAO_Contact', | |
145 | 'grouping' => 'contact-fields', | |
146 | 'fields' => array( | |
147 | 'id' => array( | |
148 | 'no_display' => TRUE, | |
149 | 'required' => TRUE, | |
9cd28c89 DL |
150 | ), |
151 | 'organization_name' => array( | |
9d72cede EM |
152 | 'title' => 'Employer', |
153 | 'default' => TRUE, | |
154 | 'no_repeat' => TRUE, | |
9cd28c89 DL |
155 | ), |
156 | ), | |
157 | ), | |
9d72cede | 158 | 'civicrm_email' => array( |
6a488035 TO |
159 | 'dao' => 'CRM_Core_DAO_Email', |
160 | 'fields' => array( | |
9d72cede EM |
161 | 'email' => array( |
162 | 'title' => ts('Email'), | |
6a488035 TO |
163 | 'no_repeat' => TRUE, |
164 | ), | |
165 | ), | |
166 | 'grouping' => 'contact-fields', | |
9d72cede EM |
167 | 'filters' => array( |
168 | 'email' => array( | |
169 | 'title' => ts('Participant E-mail'), | |
6a488035 TO |
170 | 'operator' => 'like', |
171 | ), | |
172 | ), | |
173 | ), | |
9d72cede EM |
174 | 'civicrm_phone' => array( |
175 | 'dao' => 'CRM_Core_DAO_Phone', | |
176 | 'grouping' => 'contact-fields', | |
177 | 'fields' => array( | |
178 | 'phone' => array( | |
179 | 'title' => ts('Phone No'), | |
180 | 'default' => TRUE, | |
181 | ), | |
182 | ), | |
183 | ), | |
184 | 'civicrm_address' => array( | |
6a488035 | 185 | 'dao' => 'CRM_Core_DAO_Address', |
9d72cede | 186 | 'fields' => array( |
6a488035 | 187 | 'street_address' => NULL, |
9cd28c89 DL |
188 | 'city' => NULL, |
189 | 'postal_code' => NULL, | |
9d72cede EM |
190 | 'state_province_id' => array( |
191 | 'title' => ts('State/Province'), | |
9cd28c89 | 192 | ), |
9d72cede EM |
193 | 'country_id' => array( |
194 | 'title' => ts('Country'), | |
9cd28c89 | 195 | ), |
6a488035 TO |
196 | ), |
197 | 'grouping' => 'contact-fields', | |
198 | ), | |
9d72cede | 199 | 'civicrm_participant' => array( |
6a488035 | 200 | 'dao' => 'CRM_Event_DAO_Participant', |
9d72cede EM |
201 | 'fields' => array( |
202 | 'participant_id' => array( | |
203 | 'title' => ts('Participant ID'), | |
6a488035 TO |
204 | 'default' => TRUE, |
205 | ), | |
9d72cede EM |
206 | 'event_id' => array( |
207 | 'title' => ts('Event'), | |
6a488035 TO |
208 | 'type' => CRM_Utils_Type::T_STRING, |
209 | ), | |
9d72cede EM |
210 | 'role_id' => array( |
211 | 'title' => ts('Role'), | |
6a488035 TO |
212 | 'default' => TRUE, |
213 | ), | |
9d72cede EM |
214 | 'status_id' => array( |
215 | 'title' => ts('Status'), | |
6a488035 TO |
216 | 'default' => TRUE, |
217 | ), | |
9d72cede EM |
218 | 'participant_register_date' => array( |
219 | 'title' => ts('Registration Date'), | |
6a488035 TO |
220 | ), |
221 | ), | |
222 | 'grouping' => 'event-fields', | |
9d72cede | 223 | 'filters' => array( |
2107cde9 | 224 | 'event_id' => array( |
6a488035 TO |
225 | 'name' => 'event_id', |
226 | 'title' => ts('Event'), | |
2107cde9 CW |
227 | 'operatorType' => CRM_Report_Form::OP_ENTITYREF, |
228 | 'type' => CRM_Utils_Type::T_INT, | |
9d72cede EM |
229 | 'attributes' => array( |
230 | 'entity' => 'event', | |
21dfd5f5 | 231 | 'select' => array('minimumInputLength' => 0), |
9d72cede | 232 | ), |
6a488035 | 233 | ), |
9d72cede | 234 | 'sid' => array( |
6a488035 TO |
235 | 'name' => 'status_id', |
236 | 'title' => ts('Participant Status'), | |
237 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
238 | 'options' => CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'), | |
239 | ), | |
9d72cede | 240 | 'rid' => array( |
6a488035 TO |
241 | 'name' => 'role_id', |
242 | 'title' => ts('Participant Role'), | |
2039ce87 | 243 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT_SEPARATOR, |
6a488035 TO |
244 | 'options' => CRM_Event_PseudoConstant::participantRole(), |
245 | ), | |
9d72cede EM |
246 | 'participant_register_date' => array( |
247 | 'title' => ts('Registration Date'), | |
6a488035 TO |
248 | 'operatorType' => CRM_Report_Form::OP_DATE, |
249 | ), | |
250 | ), | |
9d72cede EM |
251 | 'group_bys' => array( |
252 | 'event_id' => array( | |
253 | 'title' => ts('Event'), | |
6a488035 TO |
254 | ), |
255 | ), | |
256 | ), | |
9d72cede | 257 | 'civicrm_event' => array( |
6a488035 | 258 | 'dao' => 'CRM_Event_DAO_Event', |
9d72cede EM |
259 | 'fields' => array( |
260 | 'event_type_id' => array( | |
261 | 'title' => ts('Event Type'), | |
6a488035 | 262 | ), |
9d72cede EM |
263 | 'start_date' => array( |
264 | 'title' => ts('Event Start Date'), | |
6a488035 | 265 | ), |
9d72cede EM |
266 | 'end_date' => array( |
267 | 'title' => ts('Event End Date'), | |
6a488035 TO |
268 | ), |
269 | ), | |
270 | 'grouping' => 'event-fields', | |
271 | 'filters' => array( | |
9d72cede | 272 | 'eid' => array( |
6a488035 TO |
273 | 'name' => 'event_type_id', |
274 | 'title' => ts('Event Type'), | |
275 | 'operatorType' => CRM_Report_Form::OP_MULTISELECT, | |
276 | 'options' => CRM_Core_OptionGroup::values('event_type'), | |
277 | ), | |
9d72cede | 278 | 'event_start_date' => array( |
6a488035 TO |
279 | 'name' => 'start_date', |
280 | 'title' => ts('Event Start Date'), | |
281 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
282 | ), | |
9d72cede | 283 | 'event_end_date' => array( |
6a488035 TO |
284 | 'name' => 'end_date', |
285 | 'title' => ts('Event End Date'), | |
286 | 'operatorType' => CRM_Report_Form::OP_DATE, | |
287 | ), | |
288 | ), | |
9d72cede EM |
289 | 'group_bys' => array( |
290 | 'event_type_id' => array( | |
291 | 'title' => ts('Event Type '), | |
6a488035 TO |
292 | ), |
293 | ), | |
294 | ), | |
9d72cede | 295 | 'civicrm_line_item' => array( |
6a488035 | 296 | 'dao' => 'CRM_Price_DAO_LineItem', |
9d72cede EM |
297 | 'fields' => array( |
298 | 'line_total' => array( | |
299 | 'title' => ts('Income'), | |
6a488035 | 300 | 'default' => TRUE, |
9d72cede EM |
301 | 'statistics' => array( |
302 | 'sum' => ts('Amount'), | |
6a488035 TO |
303 | 'avg' => ts('Average'), |
304 | ), | |
305 | ), | |
9d72cede EM |
306 | 'participant_count' => array( |
307 | 'title' => ts('Count'), | |
6a488035 | 308 | 'default' => TRUE, |
9d72cede EM |
309 | 'statistics' => array( |
310 | 'sum' => ts('Count'), | |
6a488035 TO |
311 | ), |
312 | ), | |
313 | ), | |
314 | ), | |
315 | ); | |
316 | ||
317 | $this->_options = array( | |
9d72cede EM |
318 | 'blank_column_begin' => array( |
319 | 'title' => ts('Blank column at the Begining'), | |
6a488035 TO |
320 | 'type' => 'checkbox', |
321 | ), | |
9d72cede EM |
322 | 'blank_column_end' => array( |
323 | 'title' => ts('Blank column at the End'), | |
6a488035 TO |
324 | 'type' => 'select', |
325 | 'options' => array( | |
326 | '' => '-select-', | |
327 | 1 => ts('One'), | |
328 | 2 => ts('Two'), | |
329 | 3 => ts('Three'), | |
330 | ), | |
331 | ), | |
332 | ); | |
333 | parent::__construct(); | |
334 | } | |
335 | ||
00be9182 | 336 | public function preProcess() { |
6a488035 TO |
337 | parent::preProcess(); |
338 | } | |
339 | ||
74cf4551 | 340 | /** |
fe482240 | 341 | * Add The statistics. |
74cf4551 EM |
342 | * @param $rows |
343 | * | |
344 | * @return array | |
345 | */ | |
00be9182 | 346 | public function statistics(&$rows) { |
6a488035 TO |
347 | |
348 | $statistics = parent::statistics($rows); | |
9d72cede EM |
349 | $avg = NULL; |
350 | $select = " SELECT SUM( {$this->_aliases['civicrm_line_item']}.participant_count ) as count, | |
2f4c2f5d | 351 | SUM( {$this->_aliases['civicrm_line_item']}.line_total ) as amount |
352 | "; | |
6a488035 TO |
353 | $sql = "{$select} {$this->_from} {$this->_where}"; |
354 | $dao = CRM_Core_DAO::executeQuery($sql); | |
355 | if ($dao->fetch()) { | |
356 | ||
357 | if ($dao->count && $dao->amount) { | |
358 | $avg = $dao->amount / $dao->count; | |
359 | } | |
360 | $statistics['counts']['count'] = array( | |
361 | 'value' => $dao->count, | |
362 | 'title' => 'Total Participants', | |
363 | 'type' => CRM_Utils_Type::T_INT, | |
364 | ); | |
365 | $statistics['counts']['amount'] = array( | |
366 | 'value' => $dao->amount, | |
367 | 'title' => 'Total Income', | |
368 | 'type' => CRM_Utils_Type::T_MONEY, | |
369 | ); | |
2f4c2f5d | 370 | $statistics['counts']['avg '] = array( |
6a488035 TO |
371 | 'value' => $avg, |
372 | 'title' => 'Average', | |
373 | 'type' => CRM_Utils_Type::T_MONEY, | |
374 | ); | |
375 | } | |
376 | ||
377 | return $statistics; | |
378 | } | |
379 | ||
00be9182 | 380 | public function select() { |
6a488035 TO |
381 | $select = array(); |
382 | $this->_columnHeaders = array(); | |
383 | ||
384 | //add blank column at the Start | |
9d72cede EM |
385 | if (array_key_exists('options', $this->_params) && |
386 | !empty($this->_params['options']['blank_column_begin']) | |
387 | ) { | |
6a488035 TO |
388 | $select[] = " '' as blankColumnBegin"; |
389 | $this->_columnHeaders['blankColumnBegin']['title'] = '_ _ _ _'; | |
390 | } | |
391 | foreach ($this->_columns as $tableName => $table) { | |
392 | if (array_key_exists('fields', $table)) { | |
393 | foreach ($table['fields'] as $fieldName => $field) { | |
9d72cede EM |
394 | if (!empty($field['required']) || |
395 | !empty($this->_params['fields'][$fieldName]) | |
396 | ) { | |
a7488080 | 397 | if (!empty($field['statistics'])) { |
6a488035 TO |
398 | foreach ($field['statistics'] as $stat => $label) { |
399 | switch (strtolower($stat)) { | |
400 | case 'sum': | |
401 | $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}_{$stat}"; | |
402 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT; | |
403 | $this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label; | |
404 | $this->_statFields[] = "{$tableName}_{$fieldName}_{$stat}"; | |
405 | break; | |
406 | } | |
407 | } | |
408 | } | |
409 | else { | |
410 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; | |
411 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); | |
412 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
413 | } | |
414 | } | |
415 | } | |
416 | } | |
417 | } | |
418 | //add blank column at the end | |
419 | if ($blankcols = CRM_Utils_Array::value('blank_column_end', $this->_params)) { | |
420 | for ($i = 1; $i <= $blankcols; $i++) { | |
421 | $select[] = " '' as blankColumnEnd_{$i}"; | |
422 | $this->_columnHeaders["blank_{$i}"]['title'] = "_ _ _ _"; | |
423 | } | |
424 | } | |
425 | $this->_select = "SELECT " . implode(', ', $select) . " "; | |
426 | } | |
427 | ||
74cf4551 EM |
428 | /** |
429 | * @param $fields | |
430 | * @param $files | |
431 | * @param $self | |
432 | * | |
433 | * @return array | |
434 | */ | |
00be9182 | 435 | public static function formRule($fields, $files, $self) { |
6a488035 TO |
436 | $errors = $grouping = array(); |
437 | return $errors; | |
438 | } | |
439 | ||
00be9182 | 440 | public function from() { |
6a488035 | 441 | $this->_from = " |
f813f78e | 442 | FROM civicrm_participant {$this->_aliases['civicrm_participant']} |
443 | LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']} | |
99f13d8d | 444 | ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND {$this->_aliases['civicrm_event']}.is_template = 0 |
f813f78e | 445 | LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']} |
446 | ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id ) | |
447 | {$this->_aclFrom} | |
448 | LEFT JOIN civicrm_contact {$this->_aliases['civicrm_employer']} | |
449 | ON ({$this->_aliases['civicrm_employer']}.id = {$this->_aliases['civicrm_contact']}.employer_id ) | |
450 | LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} | |
451 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND | |
452 | {$this->_aliases['civicrm_address']}.is_primary = 1 | |
453 | LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} | |
454 | ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND | |
455 | {$this->_aliases['civicrm_email']}.is_primary = 1) | |
2f4c2f5d | 456 | LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} |
6a488035 TO |
457 | ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND |
458 | {$this->_aliases['civicrm_phone']}.is_primary = 1 | |
2f4c2f5d | 459 | LEFT JOIN civicrm_line_item {$this->_aliases['civicrm_line_item']} |
5fa8e57d | 460 | 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 |
461 | } |
462 | ||
00be9182 | 463 | public function storeWhereHavingClauseArray() { |
e8b2628d DS |
464 | parent::storeWhereHavingClauseArray(); |
465 | $this->_whereClauses[] = "{$this->_aliases['civicrm_participant']}.is_test = 0"; | |
6a488035 TO |
466 | } |
467 | ||
00be9182 | 468 | public function groupBy() { |
6a488035 | 469 | $this->_groupBy = ""; |
a7488080 | 470 | if (!empty($this->_params['group_bys']) && |
6a488035 TO |
471 | is_array($this->_params['group_bys']) && |
472 | !empty($this->_params['group_bys']) | |
473 | ) { | |
474 | foreach ($this->_columns as $tableName => $table) { | |
475 | if (array_key_exists('group_bys', $table)) { | |
476 | foreach ($table['group_bys'] as $fieldName => $field) { | |
a7488080 | 477 | if (!empty($this->_params['group_bys'][$fieldName])) { |
6a488035 TO |
478 | $this->_groupBy[] = $field['dbAlias']; |
479 | } | |
480 | } | |
481 | } | |
482 | } | |
483 | } | |
484 | ||
485 | if (!empty($this->_groupBy)) { | |
9d72cede EM |
486 | $this->_groupBy = "ORDER BY " . implode(', ', $this->_groupBy) . |
487 | ", {$this->_aliases['civicrm_contact']}.sort_name"; | |
6a488035 | 488 | } |
9d72cede EM |
489 | $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_participant']}.id " . |
490 | $this->_groupBy; | |
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 | } |