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