Merge pull request #4880 from totten/master-cs3
[civicrm-core.git] / CRM / Report / Form / Event / ParticipantListing.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
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 public 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 $this->_options = array(
369 'blank_column_begin' => array(
370 'title' => ts('Blank column at the Begining'),
371 'type' => 'checkbox',
372 ),
373 'blank_column_end' => array(
374 'title' => ts('Blank column at the End'),
375 'type' => 'select',
376 'options' => array(
377 '' => '-select-',
378 1 => ts('One'),
379 2 => ts('Two'),
380 3 => ts('Three'),
381 ),
382 ),
383 );
384
385 // If we have active campaigns add those elements to both the fields and filters
386 if ($campaignEnabled && !empty($this->activeCampaigns)) {
387 $this->_columns['civicrm_participant']['fields']['campaign_id'] =
388 array(
389 'title' => ts('Campaign'),
390 'default' => 'false',
391 );
392 $this->_columns['civicrm_participant']['filters']['campaign_id'] =
393 array(
394 'title' => ts('Campaign'),
395 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
396 'options' => $this->activeCampaigns,
397 );
398 $this->_columns['civicrm_participant']['order_bys']['campaign_id'] =
399 array('title' => ts('Campaign'));
400
401 }
402
403 $this->_currencyColumn = 'civicrm_participant_fee_currency';
404 parent::__construct();
405 }
406
407 /**
408 * @return array
409 */
410 public function getPriceLevels() {
411 $query = "
412 SELECT CONCAT(cv.label, ' (', ps.title, ')') label, cv.id
413 FROM civicrm_price_field_value cv
414 LEFT JOIN civicrm_price_field cf
415 ON cv.price_field_id = cf.id
416 LEFT JOIN civicrm_price_set_entity ce
417 ON ce.price_set_id = cf.price_set_id
418 LEFT JOIN civicrm_price_set ps
419 ON ce.price_set_id = ps.id
420 WHERE ce.entity_table = 'civicrm_event'
421 ORDER BY cv.label
422 ";
423 $dao = CRM_Core_DAO::executeQuery($query);
424 $elements = array();
425 while ($dao->fetch()) {
426 $elements[$dao->id] = "$dao->label\n";
427 }
428
429 return $elements;
430 } //searches database for priceset values
431
432
433 public function preProcess() {
434 parent::preProcess();
435 }
436
437 public function select() {
438 $select = array();
439 $this->_columnHeaders = array();
440
441 //add blank column at the Start
442 if (array_key_exists('options', $this->_params) &&
443 !empty($this->_params['options']['blank_column_begin'])
444 ) {
445 $select[] = " '' as blankColumnBegin";
446 $this->_columnHeaders['blankColumnBegin']['title'] = '_ _ _ _';
447 }
448 foreach ($this->_columns as $tableName => $table) {
449 if ($tableName == 'civicrm_line_item') {
450 $this->_lineitemField = TRUE;
451 }
452 if (array_key_exists('fields', $table)) {
453 foreach ($table['fields'] as $fieldName => $field) {
454 if (!empty($field['required']) ||
455 !empty($this->_params['fields'][$fieldName])
456 ) {
457 if ($tableName == 'civicrm_contribution') {
458 $this->_contribField = TRUE;
459 }
460
461 $alias = "{$tableName}_{$fieldName}";
462 $select[] = "{$field['dbAlias']} as $alias";
463 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
464 $this->_columnHeaders["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array::value('no_display', $field);
465 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
466 $this->_selectAliases[] = $alias;
467 }
468 }
469 }
470 }
471 //add blank column at the end
472 $blankcols = CRM_Utils_Array::value('blank_column_end', $this->_params);
473 if ($blankcols) {
474 for ($i = 1; $i <= $blankcols; $i++) {
475 $select[] = " '' as blankColumnEnd_{$i}";
476 $this->_columnHeaders["blank_{$i}"]['title'] = "_ _ _ _";
477 }
478 }
479
480 $this->_select = "SELECT " . implode(', ', $select) . " ";
481 }
482
483 /**
484 * @param $fields
485 * @param $files
486 * @param $self
487 *
488 * @return array
489 */
490 public static function formRule($fields, $files, $self) {
491 $errors = $grouping = array();
492 return $errors;
493 }
494
495 public function from() {
496 $this->_from = "
497 FROM civicrm_participant {$this->_aliases['civicrm_participant']}
498 LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
499 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND
500 {$this->_aliases['civicrm_event']}.is_template = 0
501 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
502 ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
503 {$this->_aclFrom}
504 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
505 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
506 {$this->_aliases['civicrm_address']}.is_primary = 1
507 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
508 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
509 {$this->_aliases['civicrm_email']}.is_primary = 1)
510 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
511 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
512 {$this->_aliases['civicrm_phone']}.is_primary = 1
513 ";
514 if ($this->_contribField) {
515 $this->_from .= "
516 LEFT JOIN civicrm_participant_payment pp
517 ON ({$this->_aliases['civicrm_participant']}.id = pp.participant_id)
518 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
519 ON (pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id)
520 ";
521 }
522 if ($this->_lineitemField) {
523 $this->_from .= "
524 LEFT JOIN civicrm_line_item line_item_civireport
525 ON line_item_civireport.entity_table = 'civicrm_participant' AND
526 line_item_civireport.entity_id = {$this->_aliases['civicrm_participant']}.id
527 ";
528 }
529 }
530
531 public function where() {
532 $clauses = array();
533 foreach ($this->_columns as $tableName => $table) {
534 if (array_key_exists('filters', $table)) {
535 foreach ($table['filters'] as $fieldName => $field) {
536 $clause = NULL;
537
538 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
539 $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
540 $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
541 $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
542
543 if ($relative || $from || $to) {
544 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
545 }
546 }
547 else {
548 $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
549
550 if ($fieldName == 'rid') {
551 $value = CRM_Utils_Array::value("{$fieldName}_value", $this->_params);
552 if (!empty($value)) {
553 $clause = "( {$field['dbAlias']} REGEXP '[[:<:]]" .
554 implode('[[:>:]]|[[:<:]]', $value) . "[[:>:]]' )";
555 }
556 $op = NULL;
557 }
558
559 if ($op) {
560 $clause = $this->whereClause($field,
561 $op,
562 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
563 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
564 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
565 );
566 }
567 }
568
569 if (!empty($clause)) {
570 $clauses[] = $clause;
571 }
572 }
573 }
574 }
575 if (empty($clauses)) {
576 $this->_where = "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 ";
577 }
578 else {
579 $this->_where =
580 "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 AND " .
581 implode(' AND ', $clauses);
582 }
583 if ($this->_aclWhere) {
584 $this->_where .= " AND {$this->_aclWhere} ";
585 }
586 }
587
588 public function groupBy() {
589 $this->_groupBy = "GROUP BY {$this->_aliases['civicrm_participant']}.id";
590 }
591
592 public function postProcess() {
593
594 // get ready with post process params
595 $this->beginPostProcess();
596
597 // get the acl clauses built before we assemble the query
598 $this->buildACLClause($this->_aliases['civicrm_contact']);
599 // build query
600 $sql = $this->buildQuery(TRUE);
601
602 // build array of result based on column headers. This method also allows
603 // modifying column headers before using it to build result set i.e $rows.
604 $rows = array();
605 $this->buildRows($sql, $rows);
606
607 // format result set.
608 $this->formatDisplay($rows);
609
610 // assign variables to templates
611 $this->doTemplateAssignment($rows);
612
613 // do print / pdf / instance stuff if needed
614 $this->endPostProcess($rows);
615 }
616
617 /**
618 * @param $rows
619 * @param $entryFound
620 * @param $row
621 * @param int $rowId
622 * @param $rowNum
623 * @param $types
624 */
625 private function _initBasicRow(&$rows, &$entryFound, $row, $rowId, $rowNum, $types) {
626 if (!array_key_exists($rowId, $row)) {
627 return FALSE;
628 }
629
630 $value = $row[$rowId];
631 if ($value) {
632 $rows[$rowNum][$rowId] = $types[$value];
633 }
634 $entryFound = TRUE;
635 }
636
637 /**
638 * @param $rows
639 */
640 public function alterDisplay(&$rows) {
641 // custom code to alter rows
642
643 $entryFound = FALSE;
644 $eventType = CRM_Core_OptionGroup::values('event_type');
645
646 $financialTypes = CRM_Contribute_PseudoConstant::financialType();
647 $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
648 $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
649 $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE));
650
651 foreach ($rows as $rowNum => $row) {
652 // make count columns point to detail report
653 // convert display name to links
654 if (array_key_exists('civicrm_participant_event_id', $row)) {
655 $eventId = $row['civicrm_participant_event_id'];
656 if ($eventId) {
657 $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant::event($eventId, FALSE);
658
659 $url = CRM_Report_Utils_Report::getNextUrl('event/income',
660 'reset=1&force=1&id_op=in&id_value=' . $eventId,
661 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
662 );
663 $rows[$rowNum]['civicrm_participant_event_id_link'] = $url;
664 $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event");
665 }
666 $entryFound = TRUE;
667 }
668
669 // handle event type id
670 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_event_event_type_id', $rowNum, $eventType);
671
672 // handle participant status id
673 if (array_key_exists('civicrm_participant_status_id', $row)) {
674 $statusId = $row['civicrm_participant_status_id'];
675 if ($statusId) {
676 $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant::participantStatus($statusId, FALSE, 'label');
677 }
678 $entryFound = TRUE;
679 }
680
681 // handle participant role id
682 if (array_key_exists('civicrm_participant_role_id', $row)) {
683 $roleId = $row['civicrm_participant_role_id'];
684 if ($roleId) {
685 $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $roleId);
686 $roleId = array();
687 foreach ($roles as $role) {
688 $roleId[$role] = CRM_Event_PseudoConstant::participantRole($role, FALSE);
689 }
690 $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $roleId);
691 }
692 $entryFound = TRUE;
693 }
694
695 // Handel value seperator in Fee Level
696 if (array_key_exists('civicrm_participant_participant_fee_level', $row)) {
697 $feeLevel = $row['civicrm_participant_participant_fee_level'];
698 if ($feeLevel) {
699 CRM_Event_BAO_Participant::fixEventLevel($feeLevel);
700 $rows[$rowNum]['civicrm_participant_participant_fee_level'] = $feeLevel;
701 }
702 $entryFound = TRUE;
703 }
704
705 // Convert display name to link
706 $displayName = CRM_Utils_Array::value('civicrm_contact_sort_name_linked', $row);
707 $cid = CRM_Utils_Array::value('civicrm_contact_id', $row);
708 $id = CRM_Utils_Array::value('civicrm_participant_participant_record', $row);
709
710 if ($displayName && $cid && $id) {
711 $url = CRM_Report_Utils_Report::getNextUrl('contact/detail',
712 "reset=1&force=1&id_op=eq&id_value=$cid",
713 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
714 );
715
716 $viewUrl = CRM_Utils_System::url("civicrm/contact/view/participant",
717 "reset=1&id=$id&cid=$cid&action=view&context=participant"
718 );
719
720 $contactTitle = ts('View Contact Details');
721 $participantTitle = ts('View Participant Record');
722
723 $rows[$rowNum]['civicrm_contact_sort_name_linked'] = "<a title='$contactTitle' href=$url>$displayName</a>";
724 if ($this->_outputMode !== 'csv') {
725 $rows[$rowNum]['civicrm_contact_sort_name_linked'] .=
726 "<span style='float: right;'><a title='$participantTitle' href=$viewUrl>" .
727 ts('View') . "</a></span>";
728 }
729 $entryFound = TRUE;
730 }
731
732 // Handle country id
733 if (array_key_exists('civicrm_address_country_id', $row)) {
734 $countryId = $row['civicrm_address_country_id'];
735 if ($countryId) {
736 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($countryId, TRUE);
737 }
738 $entryFound = TRUE;
739 }
740
741 // Handle state/province id
742 if (array_key_exists('civicrm_address_state_province_id', $row)) {
743 $provinceId = $row['civicrm_address_state_province_id'];
744 if ($provinceId) {
745 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($provinceId, TRUE);
746 }
747 $entryFound = TRUE;
748 }
749
750 // Handle employer id
751 if (array_key_exists('civicrm_contact_employer_id', $row)) {
752 $employerId = $row['civicrm_contact_employer_id'];
753 if ($employerId) {
754 $rows[$rowNum]['civicrm_contact_employer_id'] = CRM_Contact_BAO_Contact::displayName($employerId);
755 $url = CRM_Utils_System::url('civicrm/contact/view',
756 'reset=1&cid=' . $employerId, $this->_absoluteUrl
757 );
758 $rows[$rowNum]['civicrm_contact_employer_id_link'] = $url;
759 $rows[$rowNum]['civicrm_contact_employer_id_hover'] = ts('View Contact Summary for this Contact.');
760 }
761 }
762
763 // Convert campaign_id to campaign title
764 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_participant_campaign_id', $rowNum, $this->activeCampaigns);
765
766 // handle contribution status
767 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_contribution_status_id', $rowNum, $contributionStatus);
768
769 // handle payment instrument
770 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_payment_instrument_id', $rowNum, $paymentInstruments);
771
772 // handle financial type
773 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_financial_type_id', $rowNum, $financialTypes);
774
775 // handle gender id
776 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contact_gender_id', $rowNum, $genders);
777
778 // display birthday in the configured custom format
779 if (array_key_exists('civicrm_contact_birth_date', $row)) {
780 $birthDate = $row['civicrm_contact_birth_date'];
781 if ($birthDate) {
782 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d');
783 }
784 $entryFound = TRUE;
785 }
786
787 // skip looking further in rows, if first row itself doesn't
788 // have the column we need
789 if (!$entryFound) {
790 break;
791 }
792 }
793 }
794 }