Convert remaining Authorize.net test to use guzzle
[civicrm-core.git] / CRM / Report / Form / Event / ParticipantListing.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form {
18
19 protected $_summary = NULL;
20
21 protected $_contribField = FALSE;
22 protected $_groupFilter = TRUE;
23 protected $_tagFilter = TRUE;
24 protected $_balance = FALSE;
25 protected $campaigns;
26
27 protected $_customGroupExtends = array(
28 'Participant',
29 'Contact',
30 'Individual',
31 'Event',
32 );
33
34 public $_drilldownReport = array('event/income' => 'Link to Detail Report');
35
36 /**
37 * Class constructor.
38 */
39 public function __construct() {
40 $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
41
42 $this->_columns = array(
43 'civicrm_contact' => array(
44 'dao' => 'CRM_Contact_DAO_Contact',
45 'fields' => array_merge(array(
46 // CRM-17115 - to avoid changing report output at this stage re-instate
47 // old field name for sort name
48 'sort_name_linked' => array(
49 'title' => ts('Participant Name'),
50 'required' => TRUE,
51 'no_repeat' => TRUE,
52 'dbAlias' => 'contact_civireport.sort_name',
53 ),
54 ),
55 $this->getBasicContactFields(),
56 array(
57 'age_at_event' => array(
58 'title' => ts('Age at Event'),
59 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, event_civireport.start_date)',
60 ),
61 )
62 ),
63 'grouping' => 'contact-fields',
64 'order_bys' => array(
65 'sort_name' => array(
66 'title' => ts('Last Name, First Name'),
67 'default' => '1',
68 'default_weight' => '0',
69 'default_order' => 'ASC',
70 ),
71 'first_name' => array(
72 'name' => 'first_name',
73 'title' => ts('First Name'),
74 ),
75 'gender_id' => array(
76 'name' => 'gender_id',
77 'title' => ts('Gender'),
78 ),
79 'birth_date' => array(
80 'name' => 'birth_date',
81 'title' => ts('Birth Date'),
82 ),
83 'age_at_event' => array(
84 'name' => 'age_at_event',
85 'title' => ts('Age at Event'),
86 ),
87 'contact_type' => array(
88 'title' => ts('Contact Type'),
89 ),
90 'contact_sub_type' => array(
91 'title' => ts('Contact Subtype'),
92 ),
93 ),
94 'filters' => CRM_Report_Form::getBasicContactFilters(),
95 ),
96 'civicrm_email' => array(
97 'dao' => 'CRM_Core_DAO_Email',
98 'fields' => array(
99 'email' => array(
100 'title' => ts('Email'),
101 'no_repeat' => TRUE,
102 ),
103 ),
104 'grouping' => 'contact-fields',
105 'filters' => array(
106 'email' => array(
107 'title' => ts('Participant E-mail'),
108 'operator' => 'like',
109 ),
110 ),
111 ),
112 );
113 $this->_columns += $this->getAddressColumns();
114 $this->_columns += array(
115 'civicrm_participant' => array(
116 'dao' => 'CRM_Event_DAO_Participant',
117 'fields' => array(
118 'participant_id' => array('title' => ts('Participant ID')),
119 'participant_record' => array(
120 'name' => 'id',
121 'no_display' => TRUE,
122 'required' => TRUE,
123 ),
124 'event_id' => array(
125 'default' => TRUE,
126 'type' => CRM_Utils_Type::T_STRING,
127 ),
128 'status_id' => array(
129 'title' => ts('Status'),
130 'default' => TRUE,
131 ),
132 'role_id' => array(
133 'title' => ts('Role'),
134 'default' => TRUE,
135 ),
136 'fee_currency' => array(
137 'required' => TRUE,
138 'no_display' => TRUE,
139 ),
140 'registered_by_id' => array(
141 'title' => ts('Registered by Participant ID'),
142 ),
143 'registered_by_name' => array(
144 'title' => ts('Registered by Participant Name'),
145 'name' => 'registered_by_id',
146 ),
147 'source' => array(
148 'title' => ts('Source'),
149 ),
150 'participant_fee_level' => NULL,
151 'participant_fee_amount' => array('title' => ts('Participant Fee')),
152 'participant_register_date' => array('title' => ts('Registration Date')),
153 'total_paid' => array(
154 'title' => ts('Total Paid'),
155 'dbAlias' => 'IFNULL(SUM(ft.total_amount), 0)',
156 'type' => 1024,
157 ),
158 'balance' => array(
159 'title' => ts('Balance'),
160 'dbAlias' => 'participant_civireport.fee_amount - IFNULL(SUM(ft.total_amount), 0)',
161 'type' => 1024,
162 ),
163 ),
164 'grouping' => 'event-fields',
165 'filters' => array(
166 'event_id' => array(
167 'name' => 'event_id',
168 'title' => ts('Event'),
169 'operatorType' => CRM_Report_Form::OP_ENTITYREF,
170 'type' => CRM_Utils_Type::T_INT,
171 'attributes' => array(
172 'entity' => 'Event',
173 'select' => array('minimumInputLength' => 0),
174 ),
175 ),
176 'sid' => array(
177 'name' => 'status_id',
178 'title' => ts('Participant Status'),
179 'type' => CRM_Utils_Type::T_INT,
180 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
181 'options' => CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'),
182 ),
183 'rid' => array(
184 'name' => 'role_id',
185 'title' => ts('Participant Role'),
186 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
187 'options' => CRM_Event_PseudoConstant::participantRole(),
188 ),
189 'participant_register_date' => array(
190 'title' => ts('Registration Date'),
191 'operatorType' => CRM_Report_Form::OP_DATE,
192 ),
193 'fee_currency' => array(
194 'title' => ts('Fee Currency'),
195 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
196 'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
197 'default' => NULL,
198 'type' => CRM_Utils_Type::T_STRING,
199 ),
200 'registered_by_id' => array(
201 'title' => ts('Registered by Participant ID'),
202 'type' => CRM_Utils_Type::T_STRING,
203 'operator' => 'like',
204 ),
205 'source' => array(
206 'title' => ts('Source'),
207 'type' => CRM_Utils_Type::T_STRING,
208 'operator' => 'like',
209 ),
210 ),
211 'order_bys' => array(
212 'participant_register_date' => array(
213 'title' => ts('Registration Date'),
214 'default_weight' => '1',
215 'default_order' => 'ASC',
216 ),
217 'event_id' => array(
218 'title' => ts('Event'),
219 'default_weight' => '1',
220 'default_order' => 'ASC',
221 ),
222 ),
223 ),
224 'civicrm_phone' => array(
225 'dao' => 'CRM_Core_DAO_Phone',
226 'fields' => array(
227 'phone' => array(
228 'title' => ts('Phone'),
229 'default' => TRUE,
230 'no_repeat' => TRUE,
231 ),
232 ),
233 'grouping' => 'contact-fields',
234 ),
235 'civicrm_event' => array(
236 'dao' => 'CRM_Event_DAO_Event',
237 'fields' => array(
238 'event_type_id' => array(
239 'title' => ts('Event Type'),
240 ),
241 'event_start_date' => array(
242 'title' => ts('Event Start Date'),
243 ),
244 'event_end_date' => array(
245 'title' => ts('Event End Date'),
246 ),
247 ),
248 'grouping' => 'event-fields',
249 'filters' => array(
250 'eid' => array(
251 'name' => 'event_type_id',
252 'title' => ts('Event Type'),
253 'type' => CRM_Utils_Type::T_INT,
254 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
255 'options' => CRM_Core_OptionGroup::values('event_type'),
256 ),
257 'event_start_date' => array(
258 'title' => ts('Event Start Date'),
259 'operatorType' => CRM_Report_Form::OP_DATE,
260 ),
261 'event_end_date' => array(
262 'title' => ts('Event End Date'),
263 'operatorType' => CRM_Report_Form::OP_DATE,
264 ),
265 ),
266 'order_bys' => array(
267 'event_type_id' => array(
268 'title' => ts('Event Type'),
269 'default_weight' => '2',
270 'default_order' => 'ASC',
271 ),
272 'event_start_date' => array(
273 'title' => ts('Event Start Date'),
274 ),
275 ),
276 ),
277 'civicrm_note' => array(
278 'dao' => 'CRM_Core_DAO_Note',
279 'fields' => array(
280 'participant_note' => array(
281 'name' => 'note',
282 'title' => ts('Participant Note'),
283 ),
284 ),
285 ),
286 'civicrm_contribution' => array(
287 'dao' => 'CRM_Contribute_DAO_Contribution',
288 'fields' => array(
289 'contribution_id' => array(
290 'name' => 'id',
291 'no_display' => TRUE,
292 'required' => TRUE,
293 'csv_display' => TRUE,
294 'title' => ts('Contribution ID'),
295 ),
296 'financial_type_id' => array('title' => ts('Financial Type')),
297 'receive_date' => array('title' => ts('Payment Date')),
298 'contribution_status_id' => array('title' => ts('Contribution Status')),
299 'payment_instrument_id' => array('title' => ts('Payment Type')),
300 'contribution_source' => array(
301 'name' => 'source',
302 'title' => ts('Contribution Source'),
303 ),
304 'currency' => array(
305 'required' => TRUE,
306 'no_display' => TRUE,
307 ),
308 'trxn_id' => NULL,
309 'fee_amount' => array('title' => ts('Transaction Fee')),
310 'net_amount' => NULL,
311 ),
312 'grouping' => 'contrib-fields',
313 'filters' => array(
314 'receive_date' => array(
315 'title' => ts('Payment Date'),
316 'operatorType' => CRM_Report_Form::OP_DATE,
317 ),
318 'financial_type_id' => array(
319 'title' => ts('Financial Type'),
320 'type' => CRM_Utils_Type::T_INT,
321 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
322 'options' => CRM_Contribute_PseudoConstant::financialType(),
323 ),
324 'currency' => array(
325 'title' => ts('Contribution Currency'),
326 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
327 'options' => CRM_Core_OptionGroup::values('currencies_enabled'),
328 'default' => NULL,
329 'type' => CRM_Utils_Type::T_STRING,
330 ),
331 'payment_instrument_id' => array(
332 'title' => ts('Payment Type'),
333 'type' => CRM_Utils_Type::T_INT,
334 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
335 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(),
336 ),
337 'contribution_status_id' => array(
338 'title' => ts('Contribution Status'),
339 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
340 'options' => CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'search'),
341 'default' => NULL,
342 ),
343 ),
344 ),
345 'civicrm_line_item' => array(
346 'dao' => 'CRM_Price_DAO_LineItem',
347 'grouping' => 'priceset-fields',
348 'filters' => array(
349 'price_field_value_id' => array(
350 'name' => 'price_field_value_id',
351 'title' => ts('Fee Level'),
352 'type' => CRM_Utils_Type::T_INT,
353 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
354 'options' => $this->getPriceLevels(),
355 ),
356 ),
357 ),
358 );
359
360 $this->_options = array(
361 'blank_column_begin' => array(
362 'title' => ts('Blank column at the Begining'),
363 'type' => 'checkbox',
364 ),
365 'blank_column_end' => array(
366 'title' => ts('Blank column at the End'),
367 'type' => 'select',
368 'options' => array(
369 '' => ts('-select-'),
370 1 => ts('One'),
371 2 => ts('Two'),
372 3 => ts('Three'),
373 ),
374 ),
375 );
376
377 // CRM-17115 avoid duplication of sort_name - would be better to standardise name
378 // & behaviour across reports but trying for no change at this point.
379 $this->_columns['civicrm_contact']['fields']['sort_name']['no_display'] = TRUE;
380
381 // If we have campaigns enabled, add those elements to both the fields, filters and sorting
382 $this->addCampaignFields('civicrm_participant', FALSE, TRUE);
383
384 $this->_currencyColumn = 'civicrm_participant_fee_currency';
385 parent::__construct();
386 }
387
388 /**
389 * Searches database for priceset values.
390 *
391 * @return array
392 */
393 public function getPriceLevels() {
394 $query = "
395 SELECT CONCAT(cv.label, ' (', ps.title, ' - ', cf.label , ')') label, cv.id
396 FROM civicrm_price_field_value cv
397 LEFT JOIN civicrm_price_field cf
398 ON cv.price_field_id = cf.id
399 LEFT JOIN civicrm_price_set_entity ce
400 ON ce.price_set_id = cf.price_set_id
401 LEFT JOIN civicrm_price_set ps
402 ON ce.price_set_id = ps.id
403 WHERE ce.entity_table = 'civicrm_event'
404 ORDER BY cv.label
405 ";
406 $dao = CRM_Core_DAO::executeQuery($query);
407 $elements = array();
408 while ($dao->fetch()) {
409 $elements[$dao->id] = "$dao->label\n";
410 }
411
412 return $elements;
413 }
414
415 public function preProcess() {
416 parent::preProcess();
417 }
418
419 public function select() {
420 $select = array();
421 $this->_columnHeaders = array();
422
423 //add blank column at the Start
424 if (array_key_exists('options', $this->_params) &&
425 !empty($this->_params['options']['blank_column_begin'])
426 ) {
427 $select[] = " '' as blankColumnBegin";
428 $this->_columnHeaders['blankColumnBegin']['title'] = '_ _ _ _';
429 }
430 foreach ($this->_columns as $tableName => $table) {
431 if (array_key_exists('fields', $table)) {
432 foreach ($table['fields'] as $fieldName => $field) {
433 if (!empty($field['required']) ||
434 !empty($this->_params['fields'][$fieldName])
435 ) {
436 if ($tableName == 'civicrm_contribution') {
437 $this->_contribField = TRUE;
438 }
439 if ($fieldName == 'total_paid' || $fieldName == 'balance') {
440 $this->_balance = TRUE;
441 // modify the select if filtered by fee_level as the from clause
442 // already selects the total_amount from civicrm_contribution table
443 if (!empty($this->_params['price_field_value_id_value'])) {
444 $field['dbAlias'] = str_replace('SUM(ft.total_amount)', 'ft.total_amount', $field['dbAlias']);
445 }
446 }
447 $alias = "{$tableName}_{$fieldName}";
448 $select[] = "{$field['dbAlias']} as $alias";
449 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = $field['type'] ?? NULL;
450 $this->_columnHeaders["{$tableName}_{$fieldName}"]['no_display'] = $field['no_display'] ?? NULL;
451 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'] ?? NULL;
452 $this->_selectAliases[] = $alias;
453 }
454 }
455 }
456 }
457 //add blank column at the end
458 $blankcols = $this->_params['blank_column_end'] ?? NULL;
459 if ($blankcols) {
460 for ($i = 1; $i <= $blankcols; $i++) {
461 $select[] = " '' as blankColumnEnd_{$i}";
462 $this->_columnHeaders["blank_{$i}"]['title'] = "_ _ _ _";
463 }
464 }
465
466 $this->_selectClauses = $select;
467 $this->_select = "SELECT " . implode(', ', $select) . " ";
468 }
469
470 /**
471 * @param $fields
472 * @param $files
473 * @param $self
474 *
475 * @return array
476 */
477 public static function formRule($fields, $files, $self) {
478 $errors = $grouping = array();
479 return $errors;
480 }
481
482 public function from() {
483 $this->_from = "
484 FROM civicrm_participant {$this->_aliases['civicrm_participant']}
485 LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
486 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND
487 {$this->_aliases['civicrm_event']}.is_template = 0
488 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
489 ON ({$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id )
490 {$this->_aclFrom}
491 ";
492
493 $this->joinAddressFromContact();
494 $this->joinPhoneFromContact();
495 $this->joinEmailFromContact();
496
497 // Include participant note.
498 if ($this->isTableSelected('civicrm_note')) {
499 $this->_from .= "
500 LEFT JOIN civicrm_note {$this->_aliases['civicrm_note']}
501 ON ( {$this->_aliases['civicrm_note']}.entity_table = 'civicrm_participant' AND
502 {$this->_aliases['civicrm_participant']}.id = {$this->_aliases['civicrm_note']}.entity_id )";
503 }
504
505 if ($this->_contribField) {
506 $this->_from .= "
507 LEFT JOIN civicrm_participant_payment pp
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)
511 ";
512 }
513 if (!empty($this->_params['price_field_value_id_value'])) {
514 $this->_from .= "
515 LEFT JOIN civicrm_line_item line_item_civireport
516 ON line_item_civireport.entity_table = 'civicrm_participant' AND
517 line_item_civireport.entity_id = {$this->_aliases['civicrm_participant']}.id AND
518 line_item_civireport.qty > 0
519 ";
520 }
521 if ($this->_balance) {
522 $this->_from .= "
523 LEFT JOIN civicrm_entity_financial_trxn eft
524 ON (eft.entity_id = {$this->_aliases['civicrm_contribution']}.id)
525 LEFT JOIN civicrm_financial_trxn ft
526 ON (ft.id = eft.financial_trxn_id AND eft.entity_table = 'civicrm_contribution') AND
527 (ft.is_payment = 1)
528 ";
529 }
530 }
531
532 public 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 = $this->_params["{$fieldName}_relative"] ?? NULL;
541 $from = $this->_params["{$fieldName}_from"] ?? NULL;
542 $to = $this->_params["{$fieldName}_to"] ?? NULL;
543
544 if ($relative || $from || $to) {
545 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
546 }
547 }
548 else {
549 $op = $this->_params["{$fieldName}_op"] ?? NULL;
550
551 if ($fieldName == 'rid') {
552 $value = $this->_params["{$fieldName}_value"] ?? NULL;
553 if (!empty($value)) {
554 $operator = '';
555 if ($op == 'notin') {
556 $operator = 'NOT';
557 }
558
559 $regexp = "[[:cntrl:]]*" . implode('[[:>:]]*|[[:<:]]*', $value) . "[[:cntrl:]]*";
560 $clause = "{$field['dbAlias']} {$operator} REGEXP '{$regexp}'";
561 }
562 $op = NULL;
563 }
564
565 if ($op) {
566 $clause = $this->whereClause($field,
567 $op,
568 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
569 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
570 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
571 );
572 }
573 }
574
575 if (!empty($clause)) {
576 $clauses[] = $clause;
577 }
578 }
579 }
580 }
581 if (empty($clauses)) {
582 $this->_where = "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 ";
583 }
584 else {
585 $this->_where = "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 AND " .
586 implode(' AND ', $clauses);
587 }
588 if ($this->_aclWhere) {
589 $this->_where .= " AND {$this->_aclWhere} ";
590 }
591 }
592
593 public function groupBy() {
594 $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, "{$this->_aliases['civicrm_participant']}.id");
595 }
596
597 public function postProcess() {
598 // get the acl clauses built before we assemble the query
599 $this->buildACLClause($this->_aliases['civicrm_contact']);
600 parent::postProcess();
601 }
602
603 /**
604 * @param $rows
605 * @param $entryFound
606 * @param $row
607 * @param int $rowId
608 * @param $rowNum
609 * @param $types
610 *
611 * @return bool
612 */
613 private function _initBasicRow(&$rows, &$entryFound, $row, $rowId, $rowNum, $types) {
614 if (!array_key_exists($rowId, $row)) {
615 return FALSE;
616 }
617
618 $value = $row[$rowId];
619 if ($value) {
620 $rows[$rowNum][$rowId] = $types[$value];
621 }
622 $entryFound = TRUE;
623 }
624
625 /**
626 * Alter display of rows.
627 *
628 * Iterate through the rows retrieved via SQL and make changes for display purposes,
629 * such as rendering contacts as links.
630 *
631 * @param array $rows
632 * Rows generated by SQL, with an array for each row.
633 */
634 public function alterDisplay(&$rows) {
635 $entryFound = FALSE;
636 $eventType = CRM_Core_OptionGroup::values('event_type');
637 $financialTypes = CRM_Contribute_PseudoConstant::financialType();
638 $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'label');
639 $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
640
641 foreach ($rows as $rowNum => $row) {
642 // make count columns point to detail report
643 // convert display name to links
644 if (array_key_exists('civicrm_participant_event_id', $row)) {
645 $eventId = $row['civicrm_participant_event_id'];
646 if ($eventId) {
647 $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant::event($eventId, FALSE);
648
649 $url = CRM_Report_Utils_Report::getNextUrl('event/income',
650 'reset=1&force=1&id_op=in&id_value=' . $eventId,
651 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
652 );
653 $rows[$rowNum]['civicrm_participant_event_id_link'] = $url;
654 $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event");
655 }
656 $entryFound = TRUE;
657 }
658
659 // handle event type id
660 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_event_event_type_id', $rowNum, $eventType);
661
662 // handle participant status id
663 if (array_key_exists('civicrm_participant_status_id', $row)) {
664 $statusId = $row['civicrm_participant_status_id'];
665 if ($statusId) {
666 $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant::participantStatus($statusId, FALSE, 'label');
667 }
668 $entryFound = TRUE;
669 }
670
671 // handle participant role id
672 if (array_key_exists('civicrm_participant_role_id', $row)) {
673 $roleId = $row['civicrm_participant_role_id'];
674 if ($roleId) {
675 $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $roleId);
676 $roleId = array();
677 foreach ($roles as $role) {
678 $roleId[$role] = CRM_Event_PseudoConstant::participantRole($role, FALSE);
679 }
680 $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $roleId);
681 }
682 $entryFound = TRUE;
683 }
684
685 // Handle registered by name
686 if (array_key_exists('civicrm_participant_registered_by_name', $row)) {
687 $registeredById = $row['civicrm_participant_registered_by_name'];
688 if ($registeredById) {
689 $registeredByContactId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $registeredById, 'contact_id', 'id');
690 $rows[$rowNum]['civicrm_participant_registered_by_name'] = CRM_Contact_BAO_Contact::displayName($registeredByContactId);
691 $rows[$rowNum]['civicrm_participant_registered_by_name_link'] = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $registeredByContactId, $this->_absoluteUrl);
692 $rows[$rowNum]['civicrm_participant_registered_by_name_hover'] = ts('View Contact Summary for Contact that registered the participant.');
693 }
694 }
695
696 // Handle value seperator in Fee Level
697 if (array_key_exists('civicrm_participant_participant_fee_level', $row)) {
698 $feeLevel = $row['civicrm_participant_participant_fee_level'];
699 if ($feeLevel) {
700 CRM_Event_BAO_Participant::fixEventLevel($feeLevel);
701 $rows[$rowNum]['civicrm_participant_participant_fee_level'] = $feeLevel;
702 }
703 $entryFound = TRUE;
704 }
705
706 // Convert display name to link
707 $displayName = $row['civicrm_contact_sort_name_linked'] ?? NULL;
708 $cid = $row['civicrm_contact_id'] ?? NULL;
709 $id = $row['civicrm_participant_participant_record'] ?? NULL;
710
711 if ($displayName && $cid && $id) {
712 $url = CRM_Report_Utils_Report::getNextUrl('contact/detail',
713 "reset=1&force=1&id_op=eq&id_value=$cid",
714 $this->_absoluteUrl, $this->_id, $this->_drilldownReport
715 );
716
717 $viewUrl = CRM_Utils_System::url("civicrm/contact/view/participant",
718 "reset=1&id=$id&cid=$cid&action=view&context=participant"
719 );
720
721 $contactTitle = ts('View Contact Details');
722 $participantTitle = ts('View Participant Record');
723
724 $rows[$rowNum]['civicrm_contact_sort_name_linked'] = "<a title='$contactTitle' href=$url>$displayName</a>";
725 // Add a "View" link to the participant record if this isn't a CSV/PDF/printed document.
726 if ($this->_outputMode !== 'csv' && $this->_outputMode !== 'pdf' && $this->_outputMode !== 'print') {
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 // Convert campaign_id to campaign title
735 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_participant_campaign_id', $rowNum, $this->campaigns);
736
737 // handle contribution status
738 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_contribution_status_id', $rowNum, $contributionStatus);
739
740 // handle payment instrument
741 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_payment_instrument_id', $rowNum, $paymentInstruments);
742
743 // handle financial type
744 $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_financial_type_id', $rowNum, $financialTypes);
745
746 $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'event/participantListing', 'View Event Income Details') ? TRUE : $entryFound;
747
748 $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'event/ParticipantListing', 'List all participant(s) for this ') ? TRUE : $entryFound;
749
750 // skip looking further in rows, if first row itself doesn't
751 // have the column we need
752 if (!$entryFound) {
753 break;
754 }
755 }
756 }
757
758 }