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