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