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