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