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