Merge pull request #3614 from eileenmcnaughton/CRM-14951
[civicrm-core.git] / CRM / Report / Form / Event / ParticipantListing.php
CommitLineData
6a488035 1<?php
16654cd4 2
6a488035 3/*
16654cd4 4 +--------------------------------------------------------------------+
06b69b18 5 | CiviCRM version 4.5 |
16654cd4 6 +--------------------------------------------------------------------+
06b69b18 7 | Copyright CiviCRM LLC (c) 2004-2014 |
16654cd4
DL
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 +--------------------------------------------------------------------+
6a488035
TO
27*/
28
29/**
30 *
31 * @package CRM
06b69b18 32 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
33 * $Id$
34 *
35 */
36class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form_Event {
37
38 protected $_summary = NULL;
9b34c9e3 39
e8e008f5 40 protected $_contribField = FALSE;
16654cd4 41 protected $_lineitemField = FALSE;
26dcc739
E
42 protected $_groupFilter = TRUE;
43 protected $_tagFilter = TRUE;
6a488035 44
0f18adb9 45 protected $_customGroupExtends = array('Participant', 'Contact', 'Individual', 'Event');
28ac0bbe 46
6a488035
TO
47 public $_drilldownReport = array('event/income' => 'Link to Detail Report');
48
74cf4551
EM
49 /**
50 *
51 */
52 /**
53 *
54 */
f813f78e 55 function __construct() {
28ac0bbe 56 $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
f813f78e 57
58 // Check if CiviCampaign is a) enabled and b) has active campaigns
9b34c9e3 59 $config = CRM_Core_Config::singleton();
4fabb77b
CD
60 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
61 if ($campaignEnabled) {
62 $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
63 $this->activeCampaigns = $getCampaigns['campaigns'];
64 asort($this->activeCampaigns);
65 }
f813f78e 66
6a488035
TO
67 $this->_columns = array(
68 'civicrm_contact' =>
69 array(
70 'dao' => 'CRM_Contact_DAO_Contact',
71 'fields' =>
72 array(
73 'sort_name_linked' =>
74 array('title' => ts('Participant Name'),
75 'required' => TRUE,
76 'no_repeat' => TRUE,
77 'dbAlias' => 'contact_civireport.sort_name',
78 ),
9b34c9e3 79 'first_name' => array('title' => ts('First Name'),
6a488035 80 ),
9b34c9e3 81 'last_name' => array('title' => ts('Last Name'),
6a488035
TO
82 ),
83 'id' =>
84 array(
85 'no_display' => TRUE,
86 'required' => TRUE,
87 ),
28ac0bbe
DG
88 'gender_id' =>
89 array('title' => ts('Gender'),
90 ),
439fc6fe
DG
91 'birth_date' =>
92 array('title' => ts('Birth Date'),
93 ),
28ac0bbe
DG
94 'age' => array(
95 'title' => ts('Age'),
96 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())',
97 ),
98 'age_at_event' => array(
99 'title' => ts('Age at Event'),
100 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, event_civireport.start_date)',
439fc6fe 101 ),
6a488035
TO
102 'employer_id' =>
103 array('title' => ts('Organization'),
104 ),
105 ),
106 'grouping' => 'contact-fields',
4fabb77b 107 'order_bys' =>
6a488035
TO
108 array(
109 'sort_name' =>
f813f78e 110 array('title' => ts('Last Name, First Name'),
9b34c9e3
PJ
111 'default' => '1',
112 'default_weight' => '0',
113 'default_order' => 'ASC',
6a488035 114 ),
28ac0bbe
DG
115 'gender_id' =>
116 array(
117 'name' => 'gender_id',
118 'title' => ts('Gender'),
119 ),
120 'birth_date' =>
121 array(
122 'name' => 'birth_date',
123 'title' => ts('Birth Date'),
124 ),
125 'age_at_event' =>
126 array(
127 'name' => 'age_at_event',
128 'title' => ts('Age at Event'),
129 ),
6a488035 130 ),
4fabb77b 131 'filters' =>
6a488035
TO
132 array(
133 'sort_name' =>
4fabb77b
CD
134 array('title' => ts('Participant Name'),
135 'operator' => 'like',
136 ),
28ac0bbe
DG
137 'gender_id' =>
138 array('title' => ts('Gender'),
139 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
140 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'),
141 ),
142 'birth_date' => array(
143 'title' => 'Birth Date',
144 'operatorType' => CRM_Report_Form::OP_DATE,
145 'type' => CRM_Utils_Type::T_DATE
146 ),
6a488035
TO
147 ),
148 ),
149 'civicrm_email' =>
150 array(
151 'dao' => 'CRM_Core_DAO_Email',
152 'fields' =>
153 array(
154 'email' =>
155 array('title' => ts('Email'),
156 'no_repeat' => TRUE,
157 ),
158 ),
159 'grouping' => 'contact-fields',
160 'filters' =>
161 array(
162 'email' =>
163 array('title' => ts('Participant E-mail'),
164 'operator' => 'like',
165 ),
166 ),
167 ),
168 'civicrm_address' =>
169 array(
170 'dao' => 'CRM_Core_DAO_Address',
171 'fields' =>
172 array(
173 'street_address' => NULL,
174 'city' => NULL,
175 'postal_code' => NULL,
176 'state_province_id' =>
177 array('title' => ts('State/Province'),
178 ),
179 'country_id' =>
180 array('title' => ts('Country'),
181 ),
182 ),
183 'grouping' => 'contact-fields',
184 ),
185 'civicrm_participant' =>
186 array(
187 'dao' => 'CRM_Event_DAO_Participant',
188 'fields' =>
189 array('participant_id' => array('title' => 'Participant ID'),
190 'participant_record' => array(
191 'name' => 'id',
192 'no_display' => TRUE,
193 'required' => TRUE,
194 ),
195 'event_id' => array(
196 'default' => TRUE,
197 'type' => CRM_Utils_Type::T_STRING,
198 ),
199 'status_id' => array('title' => ts('Status'),
16654cd4 200 'default' => TRUE,
6a488035
TO
201 ),
202 'role_id' => array('title' => ts('Role'),
16654cd4 203 'default' => TRUE,
6a488035 204 ),
9bf1940a 205 'fee_currency' => array(
16654cd4
DL
206 'required' => TRUE,
207 'no_display' => TRUE,
9bf1940a 208 ),
6a488035
TO
209 'participant_fee_level' => NULL,
210 'participant_fee_amount' => NULL,
211 'participant_register_date' => array('title' => ts('Registration Date')),
212 ),
213 'grouping' => 'event-fields',
214 'filters' =>
215 array(
216 'event_id' => array('name' => 'event_id',
16654cd4
DL
217 'title' => ts('Event'),
218 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
219 'options' => $this->getEventFilterOptions(),
6a488035
TO
220 ),
221 'sid' => array(
222 'name' => 'status_id',
223 'title' => ts('Participant Status'),
224 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
225 'options' => CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'),
226 ),
227 'rid' => array(
228 'name' => 'role_id',
229 'title' => ts('Participant Role'),
230 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
231 'options' => CRM_Event_PseudoConstant::participantRole(),
232 ),
233 'participant_register_date' => array(
439fc6fe 234 'title' => 'Registration Date',
6a488035
TO
235 'operatorType' => CRM_Report_Form::OP_DATE,
236 ),
9bf1940a 237 'fee_currency' =>
9b34c9e3 238 array('title' => ts('Fee Currency'),
9bf1940a 239 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
240 'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
d1b0931b 241 'default' => NULL,
9bf1940a 242 'type' => CRM_Utils_Type::T_STRING,
243 ),
244
6a488035
TO
245 ),
246 'order_bys' =>
247 array(
08ef564e
DG
248 'participant_register_date' =>
249 array('title' => ts('Registration Date'),
250 'default_weight' => '1',
251 'default_order' => 'ASC',
252 ),
6a488035
TO
253 'event_id' =>
254 array('title' => ts('Event'), 'default_weight' => '1', 'default_order' => 'ASC'),
255 ),
256 ),
257 'civicrm_phone' =>
258 array(
259 'dao' => 'CRM_Core_DAO_Phone',
260 'fields' =>
261 array(
262 'phone' =>
263 array('title' => ts('Phone'),
264 'default' => TRUE,
265 'no_repeat' => TRUE,
266 ),
267 ),
268 'grouping' => 'contact-fields',
269 ),
270 'civicrm_event' =>
271 array(
272 'dao' => 'CRM_Event_DAO_Event',
e1a1a24e 273 'fields' => array(
6a488035 274 'event_type_id' => array('title' => ts('Event Type')),
e1a1a24e 275 'event_start_date' => array('title' => ts('Event Start Date')),
6a488035
TO
276 ),
277 'grouping' => 'event-fields',
278 'filters' =>
279 array(
280 'eid' => array(
281 'name' => 'event_type_id',
282 'title' => ts('Event Type'),
283 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
284 'options' => CRM_Core_OptionGroup::values('event_type'),
285 ),
e1a1a24e
AH
286 'event_start_date' => array(
287 'title' => ts('Event Start Date'),
288 'operatorType' => CRM_Report_Form::OP_DATE,
289 ),
6a488035
TO
290 ),
291 'order_bys' =>
292 array(
293 'event_type_id' =>
294 array('title' => ts('Event Type'), 'default_weight' => '2', 'default_order' => 'ASC'),
295 ),
296 ),
42e9d54f
AH
297 'civicrm_contribution' => array(
298 'dao' => 'CRM_Contribute_DAO_Contribution',
299 'fields' => array(
300 'contribution_id' => array(
301 'name' => 'id',
9b34c9e3
PJ
302 'no_display' => TRUE,
303 'required' => TRUE,
42e9d54f
AH
304 'csv_display' => TRUE,
305 'title' => ts('Contribution ID'),
306 ),
307 'financial_type_id' => array('title' => ts('Financial Type')),
308 'receive_date' => array('title' => ts('Payment Date')),
309 'contribution_status_id' => array('title' => ts('Contribution Status')),
310 'payment_instrument_id' => array('title' => ts('Payment Type')),
311 'contribution_source' => array(
312 'name' => 'source',
313 'title' => ts('Contribution Source'),
314 ),
315 'currency' => array(
316 'required' => TRUE,
9b34c9e3 317 'no_display' => TRUE
42e9d54f
AH
318 ),
319 'trxn_id' => NULL,
42e9d54f 320 'fee_amount' => array('title' => ts('Transaction Fee')),
9b34c9e3
PJ
321 'net_amount' => NULL
322 ),
42e9d54f
AH
323 'grouping' => 'contrib-fields',
324 'filters' => array(
325 'receive_date' => array(
326 'title' => 'Payment Date',
327 'operatorType' => CRM_Report_Form::OP_DATE,
328 ),
d79a8b5c 329 'financial_type_id' => array('title' => ts('Financial Type'),
16654cd4
DL
330 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
331 'options' => CRM_Contribute_PseudoConstant::financialType(),
d79a8b5c 332 ),
9b34c9e3 333 'currency' => array('title' => ts('Contribution Currency'),
16654cd4
DL
334 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
335 'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
336 'default' => NULL,
337 'type' => CRM_Utils_Type::T_STRING,
d79a8b5c
AH
338 ),
339 'payment_instrument_id' => array('title' => ts('Payment Type'),
16654cd4
DL
340 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
341 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(),
d79a8b5c
AH
342 ),
343 'contribution_status_id' => array('title' => ts('Contribution Status'),
16654cd4
DL
344 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
345 'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
346 'default' => NULL
347 ),
348 ),
349 ),
350
351 'civicrm_line_item' => array(
352 'dao' => 'CRM_Price_DAO_LineItem',
353 'grouping' => 'priceset-fields',
354 'filters' => array(
355 'price_field_value_id' => array(
356 'name' => 'price_field_value_id',
357 'title' => ts('Fee Level'),
d79a8b5c 358 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
16654cd4 359 'options' => $this->getPriceLevels(),
d79a8b5c 360 ),
42e9d54f
AH
361 ),
362 ),
6a488035 363 );
16654cd4
DL
364
365
366 $this->_options = array(
367 'blank_column_begin' => array(
368 'title' => ts('Blank column at the Begining'),
6a488035
TO
369 'type' => 'checkbox',
370 ),
16654cd4
DL
371 'blank_column_end' => array(
372 'title' => ts('Blank column at the End'),
6a488035
TO
373 'type' => 'select',
374 'options' => array(
375 '' => '-select-',
376 1 => ts('One'),
377 2 => ts('Two'),
378 3 => ts('Three'),
379 ),
380 ),
381 );
f813f78e 382
4fabb77b
CD
383 // If we have active campaigns add those elements to both the fields and filters
384 if ($campaignEnabled && !empty($this->activeCampaigns)) {
16654cd4
DL
385 $this->_columns['civicrm_participant']['fields']['campaign_id'] =
386 array(
387 'title' => ts('Campaign'),
388 'default' => 'false',
389 );
390 $this->_columns['civicrm_participant']['filters']['campaign_id'] =
391 array(
392 'title' => ts('Campaign'),
393 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
394 'options' => $this->activeCampaigns,
395 );
396 $this->_columns['civicrm_participant']['order_bys']['campaign_id'] =
397 array('title' => ts('Campaign'));
4fabb77b
CD
398
399 }
f813f78e 400
9bf1940a 401 $this->_currencyColumn = 'civicrm_participant_fee_currency';
6a488035
TO
402 parent::__construct();
403 }
f813f78e 404
74cf4551
EM
405 /**
406 * @return array
407 */
16654cd4
DL
408 function getPriceLevels() {
409 $query = "
410SELECT DISTINCT cv.label, cv.id
411FROM civicrm_price_field_value cv
412LEFT JOIN civicrm_price_field cf ON cv.price_field_id = cf.id
413LEFT JOIN civicrm_price_set_entity ce ON ce.price_set_id = cf.price_set_id
414WHERE ce.entity_table = 'civicrm_event'
415GROUP BY cv.label
416";
417 $dao = CRM_Core_DAO::executeQuery($query);
418 $elements = array();
419 while ($dao->fetch()) {
420 $elements[$dao->id] = "$dao->label\n";
421 }
422
423 return $elements;
424 } //searches database for priceset values
425
6a488035
TO
426
427 function preProcess() {
428 parent::preProcess();
429 }
430
431 function select() {
432 $select = array();
433 $this->_columnHeaders = array();
434
435 //add blank column at the Start
8cc574cf 436 if (array_key_exists('options', $this->_params) && !empty($this->_params['options']['blank_column_begin'])) {
6a488035
TO
437 $select[] = " '' as blankColumnBegin";
438 $this->_columnHeaders['blankColumnBegin']['title'] = '_ _ _ _';
439 }
440 foreach ($this->_columns as $tableName => $table) {
16654cd4
DL
441 if ($tableName == 'civicrm_line_item'){
442 $this->_lineitemField = TRUE;
443 }
6a488035
TO
444 if (array_key_exists('fields', $table)) {
445 foreach ($table['fields'] as $fieldName => $field) {
8cc574cf 446 if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
e8e008f5
AH
447 if ($tableName == 'civicrm_contribution') {
448 $this->_contribField = TRUE;
449 }
6a488035
TO
450
451 $alias = "{$tableName}_{$fieldName}";
452 $select[] = "{$field['dbAlias']} as $alias";
453 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
454 $this->_columnHeaders["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array::value('no_display', $field);
455 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
456 $this->_selectAliases[] = $alias;
457 }
458 }
459 }
460 }
461 //add blank column at the end
462 if ($blankcols = CRM_Utils_Array::value('blank_column_end', $this->_params)) {
463 for ($i = 1; $i <= $blankcols; $i++) {
464 $select[] = " '' as blankColumnEnd_{$i}";
465 $this->_columnHeaders["blank_{$i}"]['title'] = "_ _ _ _";
466 }
467 }
468
469 $this->_select = "SELECT " . implode(', ', $select) . " ";
470 }
471
74cf4551
EM
472 /**
473 * @param $fields
474 * @param $files
475 * @param $self
476 *
477 * @return array
478 */
6a488035
TO
479 static function formRule($fields, $files, $self) {
480 $errors = $grouping = array();
481 return $errors;
482 }
483
484 function from() {
485 $this->_from = "
486 FROM civicrm_participant {$this->_aliases['civicrm_participant']}
f813f78e 487 LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
488 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND
99f13d8d 489 {$this->_aliases['civicrm_event']}.is_template = 0
f813f78e 490 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
6a488035
TO
491 ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
492 {$this->_aclFrom}
493 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
f813f78e 494 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
495 {$this->_aliases['civicrm_address']}.is_primary = 1
496 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
6a488035 497 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
f813f78e 498 {$this->_aliases['civicrm_email']}.is_primary = 1)
499 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
6a488035 500 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
f813f78e 501 {$this->_aliases['civicrm_phone']}.is_primary = 1
e8e008f5
AH
502 ";
503 if ($this->_contribField) {
504 $this->_from .= "
42e9d54f 505 LEFT JOIN civicrm_participant_payment pp
9b34c9e3
PJ
506 ON ({$this->_aliases['civicrm_participant']}.id = pp.participant_id)
507 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
508 ON (pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id)
f813f78e 509 ";
e8e008f5 510 }
16654cd4
DL
511 if ($this->_lineitemField){
512 $this->_from .= "
513 LEFT JOIN civicrm_line_item line_item_civireport
5fa8e57d 514 ON line_item_civireport.entity_table = 'civicrm_participant' AND
515 line_item_civireport.entity_id = {$this->_aliases['civicrm_participant']}.id
16654cd4
DL
516 ";
517 }
6a488035
TO
518 }
519
520 function where() {
521 $clauses = array();
522 foreach ($this->_columns as $tableName => $table) {
523 if (array_key_exists('filters', $table)) {
524 foreach ($table['filters'] as $fieldName => $field) {
525 $clause = NULL;
526
527 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
528 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
529 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
530 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
531
532 if ($relative || $from || $to) {
533 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
534 }
535 }
536 else {
537 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
538
539 if ($fieldName == 'rid') {
540 $value = CRM_Utils_Array::value("{$fieldName}_value", $this->_params);
541 if (!empty($value)) {
542 $clause = "( {$field['dbAlias']} REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', $value) . "[[:>:]]' )";
543 }
544 $op = NULL;
545 }
546
547 if ($op) {
548 $clause = $this->whereClause($field,
16654cd4
DL
549 $op,
550 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
551 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
552 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
6a488035
TO
553 );
554 }
555 }
556
557 if (!empty($clause)) {
558 $clauses[] = $clause;
559 }
560 }
561 }
562 }
563 if (empty($clauses)) {
564 $this->_where = "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 ";
565 }
566 else {
567 $this->_where = "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 AND " . implode(' AND ', $clauses);
568 }
569 if ($this->_aclWhere) {
570 $this->_where .= " AND {$this->_aclWhere} ";
571 }
572 }
573
1bfb7a7e
DS
574 function groupBy(){
575 $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_participant']}.id";
576 }
577
6a488035
TO
578 function postProcess() {
579
580 // get ready with post process params
581 $this->beginPostProcess();
582
583 // get the acl clauses built before we assemble the query
584 $this->buildACLClause($this->_aliases['civicrm_contact']);
585 // build query
586 $sql = $this->buildQuery(TRUE);
587
16654cd4 588
6a488035
TO
589 // build array of result based on column headers. This method also allows
590 // modifying column headers before using it to build result set i.e $rows.
638e7498 591 $rows = array();
6a488035
TO
592 $this->buildRows($sql, $rows);
593
594 // format result set.
595 $this->formatDisplay($rows);
596
597 // assign variables to templates
598 $this->doTemplateAssignment($rows);
599
600 // do print / pdf / instance stuff if needed
601 $this->endPostProcess($rows);
602 }
603
74cf4551
EM
604 /**
605 * @param $rows
606 */
6a488035
TO
607 function alterDisplay(&$rows) {
608 // custom code to alter rows
609
610 $entryFound = FALSE;
611 $eventType = CRM_Core_OptionGroup::values('event_type');
612
9b34c9e3
PJ
613 $financialTypes = CRM_Contribute_PseudoConstant::financialType();
614 $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
615 $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
439fc6fe 616 $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE));
9b34c9e3 617
6a488035
TO
618 foreach ($rows as $rowNum => $row) {
619 // make count columns point to detail report
620 // convert display name to links
621 if (array_key_exists('civicrm_participant_event_id', $row)) {
622 if ($value = $row['civicrm_participant_event_id']) {
623 $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant::event($value, FALSE);
9b34c9e3 624
6a488035 625 $url = CRM_Report_Utils_Report::getNextUrl('event/income',
16654cd4
DL
626 'reset=1&force=1&id_op=in&id_value=' . $value,
627 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
6a488035
TO
628 );
629 $rows[$rowNum]['civicrm_participant_event_id_link'] = $url;
630 $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event");
631 }
632 $entryFound = TRUE;
633 }
634
635 // handle event type id
636 if (array_key_exists('civicrm_event_event_type_id', $row)) {
637 if ($value = $row['civicrm_event_event_type_id']) {
638 $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];
639 }
640 $entryFound = TRUE;
641 }
642
643 // handle participant status id
644 if (array_key_exists('civicrm_participant_status_id', $row)) {
645 if ($value = $row['civicrm_participant_status_id']) {
646 $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant::participantStatus($value, FALSE, 'label');
647 }
648 $entryFound = TRUE;
649 }
650
651 // handle participant role id
652 if (array_key_exists('civicrm_participant_role_id', $row)) {
653 if ($value = $row['civicrm_participant_role_id']) {
654 $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
655 $value = array();
656 foreach ($roles as $role) {
657 $value[$role] = CRM_Event_PseudoConstant::participantRole($role, FALSE);
658 }
659 $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $value);
660 }
661 $entryFound = TRUE;
662 }
663
664 // Handel value seperator in Fee Level
665 if (array_key_exists('civicrm_participant_participant_fee_level', $row)) {
666 if ($value = $row['civicrm_participant_participant_fee_level']) {
667 CRM_Event_BAO_Participant::fixEventLevel($value);
668 $rows[$rowNum]['civicrm_participant_participant_fee_level'] = $value;
669 }
670 $entryFound = TRUE;
671 }
672
673 // Convert display name to link
674 if (($displayName = CRM_Utils_Array::value('civicrm_contact_sort_name_linked', $row)) &&
675 ($cid = CRM_Utils_Array::value('civicrm_contact_id', $row)) &&
676 ($id = CRM_Utils_Array::value('civicrm_participant_participant_record', $row))
677 ) {
678 $url = CRM_Report_Utils_Report::getNextUrl('contact/detail',
16654cd4
DL
679 "reset=1&force=1&id_op=eq&id_value=$cid",
680 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
6a488035
TO
681 );
682
683 $viewUrl = CRM_Utils_System::url("civicrm/contact/view/participant",
16654cd4 684 "reset=1&id=$id&cid=$cid&action=view&context=participant"
6a488035
TO
685 );
686
687 $contactTitle = ts('View Contact Details');
688 $participantTitle = ts('View Participant Record');
689
690 $rows[$rowNum]['civicrm_contact_sort_name_linked'] = "<a title='$contactTitle' href=$url>$displayName</a>";
691 if ($this->_outputMode !== 'csv') {
692 $rows[$rowNum]['civicrm_contact_sort_name_linked'] .= "<span style='float: right;'><a title='$participantTitle' href=$viewUrl>" . ts('View') . "</a></span>";
693 }
694 $entryFound = TRUE;
695 }
696
697 // Handle country id
698 if (array_key_exists('civicrm_address_country_id', $row)) {
699 if ($value = $row['civicrm_address_country_id']) {
700 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, TRUE);
701 }
702 $entryFound = TRUE;
703 }
704
705 // Handle state/province id
706 if (array_key_exists('civicrm_address_state_province_id', $row)) {
707 if ($value = $row['civicrm_address_state_province_id']) {
708 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, TRUE);
709 }
710 $entryFound = TRUE;
711 }
712
713 // Handle employer id
714 if (array_key_exists('civicrm_contact_employer_id', $row)) {
715 if ($value = $row['civicrm_contact_employer_id']) {
716 $rows[$rowNum]['civicrm_contact_employer_id'] = CRM_Contact_BAO_Contact::displayName($value);
717 $url = CRM_Utils_System::url('civicrm/contact/view',
16654cd4 718 'reset=1&cid=' . $value, $this->_absoluteUrl
6a488035
TO
719 );
720 $rows[$rowNum]['civicrm_contact_employer_id_link'] = $url;
721 $rows[$rowNum]['civicrm_contact_employer_id_hover'] = ts('View Contact Summary for this Contact.');
722 }
723 }
724
4fabb77b
CD
725 // Convert campaign_id to campaign title
726 if (array_key_exists('civicrm_participant_campaign_id', $row)) {
727 if ($value = $row['civicrm_participant_campaign_id']) {
728 $rows[$rowNum]['civicrm_participant_campaign_id'] = $this->activeCampaigns[$value];
729 $entryFound = TRUE;
730 }
731 }
732
9b34c9e3
PJ
733 // handle contribution status
734 if (array_key_exists('civicrm_contribution_contribution_status_id', $row)) {
735 if ($value = $row['civicrm_contribution_contribution_status_id']) {
736 $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value];
737 }
738 $entryFound = TRUE;
739 }
740
741 // handle payment instrument
742 if (array_key_exists('civicrm_contribution_payment_instrument_id', $row)) {
743 if ($value = $row['civicrm_contribution_payment_instrument_id']) {
744 $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value];
745 }
746 $entryFound = TRUE;
747 }
748
749 // handle financial type
750 if (array_key_exists('civicrm_contribution_financial_type_id', $row)) {
751 if ($value = $row['civicrm_contribution_financial_type_id']) {
752 $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $financialTypes[$value];
753 }
754 $entryFound = TRUE;
755 }
756
439fc6fe
DG
757 if (array_key_exists('civicrm_contact_gender_id', $row)) {
758 if ($value = $row['civicrm_contact_gender_id']) {
759 $rows[$rowNum]['civicrm_contact_gender_id'] = $genders[$value];
760 }
761 $entryFound = TRUE;
762 }
9b34c9e3 763
28ac0bbe
DG
764 // display birthday in the configured custom format
765 if (array_key_exists('civicrm_contact_birth_date', $row)) {
766 if ($value = $row['civicrm_contact_birth_date']) {
16654cd4 767 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($row['civicrm_contact_birth_date'], '%Y%m%d');
28ac0bbe
DG
768 }
769 $entryFound = TRUE;
770 }
771
6a488035
TO
772 // skip looking further in rows, if first row itself doesn't
773 // have the column we need
774 if (!$entryFound) {
775 break;
776 }
777 }
778 }
16654cd4 779}