Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-01-19-15-14-40
[civicrm-core.git] / CRM / Report / Form / Extended.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_Extended extends CRM_Report_Form {
36 protected $_addressField = FALSE;
37
38 protected $_emailField = FALSE;
39
40 protected $_summary = NULL;
41
42 protected $_customGroupExtends = array();
43 protected $_baseTable = 'civicrm_contact';
44
45 /**
46 *
47 */
48 public function __construct() {
49 parent::__construct();
50 }
51
52 /**
53 *
54 */
55 public function preProcess() {
56 parent::preProcess();
57 }
58
59 /**
60 *
61 */
62 public function select() {
63 parent::select();
64 }
65
66
67 /**
68 * From clause build where baseTable & fromClauses are defined
69 */
70 public function from() {
71 if (!empty($this->_baseTable)) {
72 $this->buildACLClause($this->_aliases['civicrm_contact']);
73 $this->_from = "FROM {$this->_baseTable} {$this->_aliases[$this->_baseTable]}";
74 $availableClauses = $this->getAvailableJoins();
75 foreach ($this->fromClauses() as $fromClause) {
76 $fn = $availableClauses[$fromClause]['callback'];
77 $this->$fn();
78 }
79 if (strstr($this->_from, 'civicrm_contact')) {
80 $this->_from .= $this->_aclFrom;
81 }
82 }
83 }
84
85 /**
86 * Define any from clauses in use (child classes to override)
87 *
88 * @return array
89 */
90 public function fromClauses() {
91 return array();
92 }
93
94 public function groupBy() {
95 parent::groupBy();
96 //@todo - need to re-visit this - bad behaviour from pa
97 if ($this->_groupBy == 'GROUP BY') {
98 $this->_groupBY = NULL;
99 }
100 // if a stat field has been selected the do a group by
101 if (!empty($this->_statFields) && empty($this->_groupBy)) {
102 $this->_groupBy[] = $this->_aliases[$this->_baseTable] . ".id";
103 }
104 //@todo - this should be in the parent function or at parent level - perhaps build query should do this?
105 if (!empty($this->_groupBy) && is_array($this->_groupBy)) {
106 $this->_groupBy = 'GROUP BY ' . implode(',', $this->_groupBy);
107 }
108 }
109
110 public function orderBy() {
111 parent::orderBy();
112 }
113
114 /**
115 * @param array $rows
116 *
117 * @return array
118 */
119 public function statistics(&$rows) {
120 return parent::statistics($rows);
121 }
122
123 public function postProcess() {
124 if (!empty($this->_aclTable) && !empty($this->_aliases[$this->_aclTable])) {
125 $this->buildACLClause($this->_aliases[$this->_aclTable]);
126 }
127 parent::postProcess();
128 }
129
130 /**
131 * @param array $rows
132 */
133 public function alterDisplay(&$rows) {
134 parent::alterDisplay($rows);
135
136 //THis is all generic functionality which can hopefully go into the parent class
137 // it introduces the option of defining an alter display function as part of the column definition
138 // @tod tidy up the iteration so it happens in this function
139 list($firstRow) = $rows;
140 // no result to alter
141 if (empty($firstRow)) {
142 return;
143 }
144 $selectedFields = array_keys($firstRow);
145
146 $alterfunctions = $altermap = array();
147 foreach ($this->_columns as $tablename => $table) {
148 if (array_key_exists('fields', $table)) {
149 foreach ($table['fields'] as $field => $specs) {
150 if (in_array($tablename . '_' . $field, $selectedFields) &&
151 array_key_exists('alter_display', $specs)
152 ) {
153 $alterfunctions[$tablename . '_' .
154 $field] = $specs['alter_display'];
155 $altermap[$tablename . '_' . $field] = $field;
156 }
157 }
158 }
159 }
160 if (empty($alterfunctions)) {
161 // - no manipulation to be done
162 return;
163 }
164
165 foreach ($rows as $index => & $row) {
166 foreach ($row as $selectedfield => $value) {
167 if (array_key_exists($selectedfield, $alterfunctions)) {
168 $rows[$index][$selectedfield] = $this->$alterfunctions[$selectedfield]($value, $row, $selectedfield, $altermap[$selectedfield]);
169 }
170 }
171 }
172 }
173
174 /**
175 * @return array
176 */
177 public function getLineItemColumns() {
178 return array(
179 'civicrm_line_item' => array(
180 'dao' => 'CRM_Price_BAO_LineItem',
181 'fields' => array(
182 'qty' => array(
183 'title' => ts('Quantity'),
184 'type' => CRM_Utils_Type::T_INT,
185 'statistics' => array('sum' => ts('Total Quantity Selected')),
186 ),
187 'unit_price' => array(
188 'title' => ts('Unit Price'),
189 ),
190 'line_total' => array(
191 'title' => ts('Line Total'),
192 'type' => CRM_Utils_Type::T_MONEY,
193 'statistics' => array('sum' => ts('Total of Line Items')),
194 ),
195 ),
196 'participant_count' => array(
197 'title' => ts('Participant Count'),
198 'statistics' => array('sum' => ts('Total Participants')),
199 ),
200 'filters' => array(
201 'qty' => array(
202 'title' => ts('Quantity'),
203 'type' => CRM_Utils_Type::T_INT,
204 'operator' => CRM_Report_Form::OP_INT,
205 ),
206 ),
207 'group_bys' => array(
208 'price_field_id' => array(
209 'title' => ts('Price Field'),
210 ),
211 'price_field_value_id' => array(
212 'title' => ts('Price Field Option'),
213 ),
214 'line_item_id' => array(
215 'title' => ts('Individual Line Item'),
216 'name' => 'id',
217 ),
218 ),
219 ),
220 );
221 }
222
223 /**
224 * @return array
225 */
226 public function getPriceFieldValueColumns() {
227 return array(
228 'civicrm_price_field_value' => array(
229 'dao' => 'CRM_Price_BAO_PriceFieldValue',
230 'fields' => array(
231 'price_field_value_label' => array(
232 'title' => ts('Price Field Value Label'),
233 'name' => 'label',
234 ),
235 ),
236 'filters' => array(
237 'price_field_value_label' => array(
238 'title' => ts('Price Fields Value Label'),
239 'type' => CRM_Utils_Type::T_STRING,
240 'operator' => 'like',
241 'name' => 'label',
242 ),
243 ),
244 'order_bys' => array(
245 'label' => array(
246 'title' => ts('Price Field Value Label'),
247 ),
248 ),
249 'group_bys' => //note that we have a requirement to group by label such that all 'Promo book' lines
250 // are grouped together across price sets but there may be a separate need to group
251 // by id so that entries in one price set are distinct from others. Not quite sure what
252 // to call the distinction for end users benefit
253 array(
254 'price_field_value_label' => array(
255 'title' => ts('Price Field Value Label'),
256 'name' => 'label',
257 ),
258 ),
259 ),
260 );
261 }
262
263 /**
264 * @return array
265 */
266 public function getPriceFieldColumns() {
267 return array(
268 'civicrm_price_field' => array(
269 'dao' => 'CRM_Price_BAO_PriceField',
270 'fields' => array(
271 'price_field_label' => array(
272 'title' => ts('Price Field Label'),
273 'name' => 'label',
274 ),
275 ),
276 'filters' => array(
277 'price_field_label' => array(
278 'title' => ts('Price Field Label'),
279 'type' => CRM_Utils_Type::T_STRING,
280 'operator' => 'like',
281 'name' => 'label',
282 ),
283 ),
284 'order_bys' => array(
285 'price_field_label' => array(
286 'title' => ts('Price Field Label'),
287 'name' => 'label',
288 ),
289 ),
290 'group_bys' => array(
291 'price_field_label' => array(
292 'title' => ts('Price Field Label'),
293 'name' => 'label',
294 ),
295 ),
296 ),
297 );
298 }
299
300 /**
301 * @return array
302 */
303 public function getParticipantColumns() {
304 static $_events = array();
305 if (!isset($_events['all'])) {
306 CRM_Core_PseudoConstant::populate($_events['all'], 'CRM_Event_DAO_Event', FALSE, 'title', 'is_active', "is_template IS NULL OR is_template = 0", 'end_date DESC');
307 }
308 return array(
309 'civicrm_participant' => array(
310 'dao' => 'CRM_Event_DAO_Participant',
311 'fields' => array(
312 'participant_id' => array('title' => 'Participant ID'),
313 'participant_record' => array(
314 'name' => 'id',
315 'title' => ts('Participant ID'),
316 ),
317 'event_id' => array(
318 'title' => ts('Event ID'),
319 'type' => CRM_Utils_Type::T_STRING,
320 'alter_display' => 'alterEventID',
321 ),
322 'status_id' => array(
323 'title' => ts('Status'),
324 'alter_display' => 'alterParticipantStatus',
325 ),
326 'role_id' => array(
327 'title' => ts('Role'),
328 'alter_display' => 'alterParticipantRole',
329 ),
330 'participant_fee_level' => NULL,
331 'participant_fee_amount' => NULL,
332 'participant_register_date' => array('title' => ts('Registration Date')),
333 ),
334 'grouping' => 'event-fields',
335 'filters' => array(
336 'event_id' => array(
337 'name' => 'event_id',
338 'title' => ts('Event'),
339 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
340 'options' => $_events['all'],
341 ),
342 'sid' => array(
343 'name' => 'status_id',
344 'title' => ts('Participant Status'),
345 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
346 'options' => CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'),
347 ),
348 'rid' => array(
349 'name' => 'role_id',
350 'title' => ts('Participant Role'),
351 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
352 'options' => CRM_Event_PseudoConstant::participantRole(),
353 ),
354 'participant_register_date' => array(
355 'title' => ' Registration Date',
356 'operatorType' => CRM_Report_Form::OP_DATE,
357 ),
358 ),
359 'order_bys' => array(
360 'event_id' => array(
361 'title' => ts('Event'),
362 'default_weight' => '1',
363 'default_order' => 'ASC',
364 ),
365 ),
366 'group_bys' => array(
367 'event_id' => array('title' => ts('Event')),
368 ),
369 ),
370 );
371 }
372
373 /**
374 * @return array
375 */
376 public function getMembershipColumns() {
377 return array(
378 'civicrm_membership' => array(
379 'dao' => 'CRM_Member_DAO_Membership',
380 'grouping' => 'member-fields',
381 'fields' => array(
382 'membership_type_id' => array(
383 'title' => 'Membership Type',
384 'required' => TRUE,
385 'alter_display' => 'alterMembershipTypeID',
386 ),
387 'status_id' => array(
388 'title' => 'Membership Status',
389 'required' => TRUE,
390 'alter_display' => 'alterMembershipStatusID',
391 ),
392 'join_date' => NULL,
393 'start_date' => array(
394 'title' => ts('Current Cycle Start Date'),
395 ),
396 'end_date' => array(
397 'title' => ts('Current Membership Cycle End Date'),
398 ),
399 ),
400 'group_bys' => array(
401 'membership_type_id' => array(
402 'title' => ts('Membership Type'),
403 ),
404 ),
405 'filters' => array(
406 'join_date' => array(
407 'type' => CRM_Utils_Type::T_DATE,
408 'operatorType' => CRM_Report_Form::OP_DATE,
409 ),
410 ),
411 ),
412 );
413 }
414
415 /**
416 * @return array
417 */
418 public function getMembershipTypeColumns() {
419 return array(
420 'civicrm_membership_type' => array(
421 'dao' => 'CRM_Member_DAO_MembershipType',
422 'grouping' => 'member-fields',
423 'filters' => array(
424 'gid' => array(
425 'name' => 'id',
426 'title' => ts('Membership Types'),
427 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
428 'type' => CRM_Utils_Type::T_INT + CRM_Utils_Type::T_ENUM,
429 'options' => CRM_Member_PseudoConstant::membershipType(),
430 ),
431 ),
432 ),
433 );
434 }
435
436 /**
437 * @return array
438 */
439 public function getEventColumns() {
440 return array(
441 'civicrm_event' => array(
442 'dao' => 'CRM_Event_DAO_Event',
443 'fields' => array(
444 'id' => array(
445 'no_display' => TRUE,
446 'required' => TRUE,
447 ),
448 'title' => array(
449 'title' => ts('Event Title'),
450 'required' => TRUE,
451 ),
452 'event_type_id' => array(
453 'title' => ts('Event Type'),
454 'required' => TRUE,
455 'alter_display' => 'alterEventType',
456 ),
457 'fee_label' => array('title' => ts('Fee Label')),
458 'event_start_date' => array(
459 'title' => ts('Event Start Date'),
460 ),
461 'event_end_date' => array('title' => ts('Event End Date')),
462 'max_participants' => array(
463 'title' => ts('Capacity'),
464 'type' => CRM_Utils_Type::T_INT,
465 ),
466 ),
467 'grouping' => 'event-fields',
468 'filters' => array(
469 'event_type_id' => array(
470 'name' => 'event_type_id',
471 'title' => ts('Event Type'),
472 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
473 'options' => CRM_Core_OptionGroup::values('event_type'),
474 ),
475 'event_title' => array(
476 'name' => 'title',
477 'title' => ts('Event Title'),
478 'operatorType' => CRM_Report_Form::OP_STRING,
479 ),
480 ),
481 'order_bys' => array(
482 'event_type_id' => array(
483 'title' => ts('Event Type'),
484 'default_weight' => '2',
485 'default_order' => 'ASC',
486 ),
487 ),
488 'group_bys' => array(
489 'event_type_id' => array(
490 'title' => ts('Event Type'),
491 ),
492 ),
493 ),
494 );
495 }
496
497 /**
498 * @return array
499 */
500 public function getContributionColumns() {
501 return array(
502 'civicrm_contribution' => array(
503 'dao' => 'CRM_Contribute_DAO_Contribution',
504 'fields' => array(
505 'contribution_id' => array(
506 'name' => 'id',
507 ),
508 'financial_type_id' => array(
509 'title' => ts('Financial Type'),
510 'default' => TRUE,
511 'alter_display' => 'alterContributionType',
512 ),
513 'payment_instrument_id' => array(
514 'title' => ts('Payment Instrument'),
515 'alter_display' => 'alterPaymentType',
516 ),
517 'source' => array('title' => 'Contribution Source'),
518 'trxn_id' => NULL,
519 'receive_date' => array('default' => TRUE),
520 'receipt_date' => NULL,
521 'fee_amount' => NULL,
522 'net_amount' => NULL,
523 'total_amount' => array(
524 'title' => ts('Amount'),
525 'statistics' => array('sum' => ts('Total Amount')),
526 'type' => CRM_Utils_Type::T_MONEY,
527 ),
528 ),
529 'filters' => array(
530 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE),
531 'financial_type_id' => array(
532 'title' => ts('Financial Type'),
533 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
534 'options' => CRM_Contribute_PseudoConstant::financialType(),
535 ),
536 'payment_instrument_id' => array(
537 'title' => ts('Payment Type'),
538 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
539 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(),
540 ),
541 'contribution_status_id' => array(
542 'title' => ts('Contribution Status'),
543 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
544 'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
545 ),
546 'total_amount' => array('title' => ts('Contribution Amount')),
547 ),
548 'order_bys' => array(
549 'payment_instrument_id' => array(
550 'title' => ts('Payment Instrument'),
551 ),
552 'financial_type_id' => array(
553 'title' => ts('Financial Type'),
554 ),
555 ),
556 'group_bys' => array(
557 'financial_type_id' => array('title' => ts('Financial Type')),
558 'payment_instrument_id' => array('title' => ts('Payment Instrument')),
559 'contribution_id' => array(
560 'title' => ts('Individual Contribution'),
561 'name' => 'id',
562 ),
563 'source' => array('title' => 'Contribution Source'),
564 ),
565 'grouping' => 'contribution-fields',
566 ),
567 );
568 }
569
570 /**
571 * @return array
572 */
573 public function getContactColumns() {
574 return array(
575 'civicrm_contact' => array(
576 'dao' => 'CRM_Contact_DAO_Contact',
577 'fields' => array(
578 'display_name' => array(
579 'title' => ts('Contact Name'),
580 ),
581 'id' => array(
582 'title' => ts('Contact ID'),
583 'alter_display' => 'alterContactID',
584 ),
585 'first_name' => array(
586 'title' => ts('First Name'),
587 ),
588 'last_name' => array(
589 'title' => ts('Last Name'),
590 ),
591 'nick_name' => array(
592 'title' => ts('Nickname'),
593 'alter_display' => 'alterNickname',
594 ),
595 ),
596 'filters' => array(
597 'id' => array(
598 'title' => ts('Contact ID'),
599 ),
600 'sort_name' => array(
601 'title' => ts('Contact Name'),
602 ),
603 ),
604 'grouping' => 'contact-fields',
605 'order_bys' => array(
606 'sort_name' => array(
607 'title' => ts('Last Name, First Name'),
608 'default' => '1',
609 'default_weight' => '0',
610 'default_order' => 'ASC',
611 ),
612 ),
613 ),
614 );
615 }
616
617 /**
618 * @return array
619 */
620 public function getCaseColumns() {
621 return array(
622 'civicrm_case' => array(
623 'dao' => 'CRM_Case_DAO_Case',
624 'fields' => array(
625 'id' => array(
626 'title' => ts('Case ID'),
627 'required' => FALSE,
628 ),
629 'subject' => array(
630 'title' => ts('Case Subject'),
631 'default' => TRUE,
632 ),
633 'status_id' => array(
634 'title' => ts('Status'),
635 'default' => TRUE,
636 ),
637 'case_type_id' => array(
638 'title' => ts('Case Type'),
639 'default' => TRUE,
640 ),
641 'case_start_date' => array(
642 'title' => ts('Case Start Date'),
643 'name' => 'start_date',
644 'default' => TRUE,
645 ),
646 'case_end_date' => array(
647 'title' => ts('Case End Date'),
648 'name' => 'end_date',
649 'default' => TRUE,
650 ),
651 'case_duration' => array(
652 'name' => 'duration',
653 'title' => ts('Duration (Days)'),
654 'default' => FALSE,
655 ),
656 'case_is_deleted' => array(
657 'name' => 'is_deleted',
658 'title' => ts('Case Deleted?'),
659 'default' => FALSE,
660 'type' => CRM_Utils_Type::T_INT,
661 ),
662 ),
663 'filters' => array(
664 'case_start_date' => array(
665 'title' => ts('Case Start Date'),
666 'operatorType' => CRM_Report_Form::OP_DATE,
667 'type' => CRM_Utils_Type::T_DATE,
668 'name' => 'start_date',
669 ),
670 'case_end_date' => array(
671 'title' => ts('Case End Date'),
672 'operatorType' => CRM_Report_Form::OP_DATE,
673 'type' => CRM_Utils_Type::T_DATE,
674 'name' => 'end_date',
675 ),
676 'case_type_id' => array(
677 'title' => ts('Case Type'),
678 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
679 'options' => $this->case_types,
680 ),
681 'case_status_id' => array(
682 'title' => ts('Case Status'),
683 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
684 'options' => $this->case_statuses,
685 'name' => 'status_id',
686 ),
687 'case_is_deleted' => array(
688 'title' => ts('Case Deleted?'),
689 'type' => CRM_Report_Form::OP_INT,
690 'operatorType' => CRM_Report_Form::OP_SELECT,
691 'options' => $this->deleted_labels,
692 'default' => 0,
693 'name' => 'is_deleted',
694 ),
695 ),
696 ),
697 );
698 }
699
700 /**
701 * Get address columns to add to array
702 *
703 * @param array $options
704 * Options for the report.
705 * - prefix prefix to add (e.g. 'honor' when getting address details for honor contact
706 * - prefix_label optional prefix lable eg. "Honoree " for front end
707 * - group_by enable these fields for group by - default false
708 * - order_by enable these fields for order by
709 * - filters enable these fields for filtering
710 * - defaults - (is this working?) values to pre-populate
711 *
712 * @return array
713 * address columns definition
714 */
715 public function getAddressColumns($options = array()) {
716 $defaultOptions = array(
717 'prefix' => '',
718 'prefix_label' => '',
719 'group_by' => FALSE,
720 'order_by' => TRUE,
721 'filters' => TRUE,
722 'defaults' => array(
723 'country_id' => TRUE,
724 ),
725 );
726
727 $options = array_merge($defaultOptions, $options);
728
729 $addressFields = array(
730 $options['prefix'] . 'civicrm_address' => array(
731 'dao' => 'CRM_Core_DAO_Address',
732 'name' => 'civicrm_address',
733 'alias' => $options['prefix'] . 'civicrm_address',
734 'fields' => array(
735 $options['prefix'] . 'name' => array(
736 'title' => ts($options['prefix_label'] . 'Address Name'),
737 'default' => CRM_Utils_Array::value('name', $options['defaults'], FALSE),
738 'name' => 'name',
739 ),
740 $options['prefix'] . 'street_address' => array(
741 'title' => ts($options['prefix_label'] . 'Street Address'),
742 'default' => CRM_Utils_Array::value('street_address', $options['defaults'], FALSE),
743 'name' => 'street_address',
744 ),
745 $options['prefix'] . 'supplemental_address_1' => array(
746 'title' => ts($options['prefix_label'] .
747 'Supplementary Address Field 1'),
748 'default' => CRM_Utils_Array::value('supplemental_address_1', $options['defaults'], FALSE),
749 'name' => 'supplemental_address_1',
750 ),
751 $options['prefix'] . 'supplemental_address_2' => array(
752 'title' => ts($options['prefix_label'] .
753 'Supplementary Address Field 2'),
754 'default' => CRM_Utils_Array::value('supplemental_address_2', $options['defaults'], FALSE),
755 'name' => 'supplemental_address_2',
756 ),
757 $options['prefix'] . 'street_number' => array(
758 'name' => 'street_number',
759 'title' => ts($options['prefix_label'] . 'Street Number'),
760 'type' => 1,
761 'default' => CRM_Utils_Array::value('street_number', $options['defaults'], FALSE),
762 ),
763 $options['prefix'] . 'street_name' => array(
764 'name' => 'street_name',
765 'title' => ts($options['prefix_label'] . 'Street Name'),
766 'type' => 1,
767 'default' => CRM_Utils_Array::value('street_name', $options['defaults'], FALSE),
768 ),
769 $options['prefix'] . 'street_unit' => array(
770 'name' => 'street_unit',
771 'title' => ts($options['prefix_label'] . 'Street Unit'),
772 'type' => 1,
773 'default' => CRM_Utils_Array::value('street_unit', $options['defaults'], FALSE),
774 ),
775 $options['prefix'] . 'city' => array(
776 'title' => ts($options['prefix_label'] . 'City'),
777 'default' => CRM_Utils_Array::value('city', $options['defaults'], FALSE),
778 'name' => 'city',
779 ),
780 $options['prefix'] . 'postal_code' => array(
781 'title' => ts($options['prefix_label'] . 'Postal Code'),
782 'default' => CRM_Utils_Array::value('postal_code', $options['defaults'], FALSE),
783 'name' => 'postal_code',
784 ),
785 $options['prefix'] . 'county_id' => array(
786 'title' => ts($options['prefix_label'] . 'County'),
787 'default' => CRM_Utils_Array::value('county_id', $options['defaults'], FALSE),
788 'alter_display' => 'alterCountyID',
789 'name' => 'county_id',
790 ),
791 $options['prefix'] . 'state_province_id' => array(
792 'title' => ts($options['prefix_label'] . 'State/Province'),
793 'default' => CRM_Utils_Array::value('state_province_id', $options['defaults'], FALSE),
794 'alter_display' => 'alterStateProvinceID',
795 'name' => 'state_province_id',
796 ),
797 $options['prefix'] . 'country_id' => array(
798 'title' => ts($options['prefix_label'] . 'Country'),
799 'default' => CRM_Utils_Array::value('country_id', $options['defaults'], FALSE),
800 'alter_display' => 'alterCountryID',
801 'name' => 'country_id',
802 ),
803 ),
804 'grouping' => 'location-fields',
805 ),
806 );
807
808 if ($options['filters']) {
809 $addressFields[$options['prefix'] . 'civicrm_address']['filters'] = array(
810 $options['prefix'] . 'street_number' => array(
811 'title' => ts($options['prefix_label'] . 'Street Number'),
812 'type' => 1,
813 'name' => 'street_number',
814 ),
815 $options['prefix'] . 'street_name' => array(
816 'title' => ts($options['prefix_label'] . 'Street Name'),
817 'name' => $options['prefix'] . 'street_name',
818 'operator' => 'like',
819 ),
820 $options['prefix'] . 'postal_code' => array(
821 'title' => ts($options['prefix_label'] . 'Postal Code'),
822 'type' => 1,
823 'name' => 'postal_code',
824 ),
825 $options['prefix'] . 'city' => array(
826 'title' => ts($options['prefix_label'] . 'City'),
827 'operator' => 'like',
828 'name' => 'city',
829 ),
830 $options['prefix'] . 'county_id' => array(
831 'name' => 'county_id',
832 'title' => ts($options['prefix_label'] . 'County'),
833 'type' => CRM_Utils_Type::T_INT,
834 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
835 'options' => CRM_Core_PseudoConstant::county(),
836 ),
837 $options['prefix'] . 'state_province_id' => array(
838 'name' => 'state_province_id',
839 'title' => ts($options['prefix_label'] . 'State/Province'),
840 'type' => CRM_Utils_Type::T_INT,
841 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
842 'options' => CRM_Core_PseudoConstant::stateProvince(),
843 ),
844 $options['prefix'] . 'country_id' => array(
845 'name' => 'country_id',
846 'title' => ts($options['prefix_label'] . 'Country'),
847 'type' => CRM_Utils_Type::T_INT,
848 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
849 'options' => CRM_Core_PseudoConstant::country(),
850 ),
851 );
852 }
853
854 if ($options['order_by']) {
855 $addressFields[$options['prefix'] .
856 'civicrm_address']['order_bys'] = array(
857 $options['prefix'] . 'street_name' => array(
858 'title' => ts($options['prefix_label'] . 'Street Name'),
859 'name' => 'street_name',
860 ),
861 $options['prefix'] . 'street_number' => array(
862 'title' => ts($options['prefix_label'] . 'Odd / Even Street Number'),
863 'name' => 'street_number',
864 ),
865 $options['prefix'] . 'street_address' => array(
866 'title' => ts($options['prefix_label'] . 'Street Address'),
867 'name' => 'street_address',
868 ),
869 $options['prefix'] . 'city' => array(
870 'title' => ts($options['prefix_label'] . 'City'),
871 'name' => 'city',
872 ),
873 $options['prefix'] . 'postal_code' => array(
874 'title' => ts($options['prefix_label'] . 'Post Code'),
875 'name' => 'postal_code',
876 ),
877 );
878 }
879
880 if ($options['group_by']) {
881 $addressFields['civicrm_address']['group_bys'] = array(
882 $options['prefix'] . 'street_address' => array(
883 'title' => ts($options['prefix_label'] . 'Street Address'),
884 'name' => 'street_address',
885 ),
886 $options['prefix'] . 'city' => array(
887 'title' => ts($options['prefix_label'] . 'City'),
888 'name' => 'city',
889 ),
890 $options['prefix'] . 'postal_code' => array(
891 'title' => ts($options['prefix_label'] . 'Post Code'),
892 'name' => 'postal_code',
893 ),
894 $options['prefix'] . 'state_province_id' => array(
895 'title' => ts($options['prefix_label'] . 'State/Province'),
896 'name' => 'state_province_id',
897 ),
898 $options['prefix'] . 'country_id' => array(
899 'title' => ts($options['prefix_label'] . 'Country'),
900 'name' => 'country_id',
901 ),
902 $options['prefix'] . 'county_id' => array(
903 'title' => ts($options['prefix_label'] . 'County'),
904 'name' => 'county_id',
905 ),
906 );
907 }
908 return $addressFields;
909 }
910
911 /**
912 * Get Information about advertised Joins
913 *
914 * @return array
915 */
916 public function getAvailableJoins() {
917 return array(
918 'priceFieldValue_from_lineItem' => array(
919 'leftTable' => 'civicrm_line_item',
920 'rightTable' => 'civicrm_price_field_value',
921 'callback' => 'joinPriceFieldValueFromLineItem',
922 ),
923 'priceField_from_lineItem' => array(
924 'leftTable' => 'civicrm_line_item',
925 'rightTable' => 'civicrm_price_field',
926 'callback' => 'joinPriceFieldFromLineItem',
927 ),
928 'participant_from_lineItem' => array(
929 'leftTable' => 'civicrm_line_item',
930 'rightTable' => 'civicrm_participant',
931 'callback' => 'joinParticipantFromLineItem',
932 ),
933 'contribution_from_lineItem' => array(
934 'leftTable' => 'civicrm_line_item',
935 'rightTable' => 'civicrm_contribution',
936 'callback' => 'joinContributionFromLineItem',
937 ),
938 'membership_from_lineItem' => array(
939 'leftTable' => 'civicrm_line_item',
940 'rightTable' => 'civicrm_membership',
941 'callback' => 'joinMembershipFromLineItem',
942 ),
943 'contribution_from_participant' => array(
944 'leftTable' => 'civicrm_participant',
945 'rightTable' => 'civicrm_contribution',
946 'callback' => 'joinContributionFromParticipant',
947 ),
948 'contribution_from_membership' => array(
949 'leftTable' => 'civicrm_membership',
950 'rightTable' => 'civicrm_contribution',
951 'callback' => 'joinContributionFromMembership',
952 ),
953 'membership_from_contribution' => array(
954 'leftTable' => 'civicrm_contribution',
955 'rightTable' => 'civicrm_membership',
956 'callback' => 'joinMembershipFromContribution',
957 ),
958 'membershipType_from_membership' => array(
959 'leftTable' => 'civicrm_membership',
960 'rightTable' => 'civicrm_membership_type',
961 'callback' => 'joinMembershipTypeFromMembership',
962 ),
963 'lineItem_from_contribution' => array(
964 'leftTable' => 'civicrm_contribution',
965 'rightTable' => 'civicrm_line_item',
966 'callback' => 'joinLineItemFromContribution',
967 ),
968 'lineItem_from_membership' => array(
969 'leftTable' => 'civicrm_membership',
970 'rightTable' => 'civicrm_line_item',
971 'callback' => 'joinLineItemFromMembership',
972 ),
973 'contact_from_participant' => array(
974 'leftTable' => 'civicrm_participant',
975 'rightTable' => 'civicrm_contact',
976 'callback' => 'joinContactFromParticipant',
977 ),
978 'contact_from_membership' => array(
979 'leftTable' => 'civicrm_membership',
980 'rightTable' => 'civicrm_contact',
981 'callback' => 'joinContactFromMembership',
982 ),
983 'contact_from_contribution' => array(
984 'leftTable' => 'civicrm_contribution',
985 'rightTable' => 'civicrm_contact',
986 'callback' => 'joinContactFromContribution',
987 ),
988 'event_from_participant' => array(
989 'leftTable' => 'civicrm_participant',
990 'rightTable' => 'civicrm_event',
991 'callback' => 'joinEventFromParticipant',
992 ),
993 'address_from_contact' => array(
994 'leftTable' => 'civicrm_contact',
995 'rightTable' => 'civicrm_address',
996 'callback' => 'joinAddressFromContact',
997 ),
998 );
999 }
1000
1001 /**
1002 * Add join from contact table to address. Prefix will be added to both tables
1003 * as it's assumed you are using it to get address of a secondary contact
1004 *
1005 * @param string $prefix
1006 */
1007 public function joinAddressFromContact($prefix = '') {
1008 $this->_from .= " LEFT JOIN civicrm_address {$this->_aliases[$prefix .
1009 'civicrm_address']}
1010 ON {$this->_aliases[$prefix .
1011 'civicrm_address']}.contact_id = {$this->_aliases[$prefix .
1012 'civicrm_contact']}.id";
1013 }
1014
1015 public function joinPriceFieldValueFromLineItem() {
1016 $this->_from .= " LEFT JOIN civicrm_price_field_value {$this->_aliases['civicrm_price_field_value']}
1017 ON {$this->_aliases['civicrm_line_item']}.price_field_value_id = {$this->_aliases['civicrm_price_field_value']}.id";
1018 }
1019
1020 public function joinPriceFieldFromLineItem() {
1021 $this->_from .= "
1022 LEFT JOIN civicrm_price_field {$this->_aliases['civicrm_price_field']}
1023 ON {$this->_aliases['civicrm_line_item']}.price_field_id = {$this->_aliases['civicrm_price_field']}.id
1024 ";
1025 }
1026
1027 /**
1028 * Define join from line item table to participant table
1029 */
1030 public function joinParticipantFromLineItem() {
1031 $this->_from .= " LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
1032 ON ( {$this->_aliases['civicrm_line_item']}.entity_id = {$this->_aliases['civicrm_participant']}.id
1033 AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant')
1034 ";
1035 }
1036
1037 /**
1038 * Define join from line item table to Membership table. Seems to be still via contribution
1039 * as the entity. Have made 'inner' to restrict does that make sense?
1040 */
1041 public function joinMembershipFromLineItem() {
1042 $this->_from .= " INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
1043 ON ( {$this->_aliases['civicrm_line_item']}.entity_id = {$this->_aliases['civicrm_contribution']}.id
1044 AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_contribution')
1045 LEFT JOIN civicrm_membership_payment pp
1046 ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id
1047 LEFT JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
1048 ON pp.membership_id = {$this->_aliases['civicrm_membership']}.id
1049 ";
1050 }
1051
1052 /**
1053 * Define join from Participant to Contribution table
1054 */
1055 public function joinContributionFromParticipant() {
1056 $this->_from .= " LEFT JOIN civicrm_participant_payment pp
1057 ON {$this->_aliases['civicrm_participant']}.id = pp.participant_id
1058 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
1059 ON pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id
1060 ";
1061 }
1062
1063 /**
1064 * Define join from Membership to Contribution table
1065 */
1066 public function joinContributionFromMembership() {
1067 $this->_from .= " LEFT JOIN civicrm_membership_payment pp
1068 ON {$this->_aliases['civicrm_membership']}.id = pp.membership_id
1069 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
1070 ON pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id
1071 ";
1072 }
1073
1074 public function joinParticipantFromContribution() {
1075 $this->_from .= " LEFT JOIN civicrm_participant_payment pp
1076 ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id
1077 LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
1078 ON pp.participant_id = {$this->_aliases['civicrm_participant']}.id";
1079 }
1080
1081 public function joinMembershipFromContribution() {
1082 $this->_from .= "
1083 LEFT JOIN civicrm_membership_payment pp
1084 ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id
1085 LEFT JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
1086 ON pp.membership_id = {$this->_aliases['civicrm_membership']}.id";
1087 }
1088
1089 public function joinMembershipTypeFromMembership() {
1090 $this->_from .= "
1091 LEFT JOIN civicrm_membership_type {$this->_aliases['civicrm_membership_type']}
1092 ON {$this->_aliases['civicrm_membership']}.membership_type_id = {$this->_aliases['civicrm_membership_type']}.id
1093 ";
1094 }
1095
1096 public function joinContributionFromLineItem() {
1097
1098 // this can be stored as a temp table & indexed for more speed. Not done at this state.
1099 // another option is to cache it but I haven't tried to put that code in yet (have used it before for one hour caching
1100 $this->_from .= " LEFT JOIN (SELECT line_item_civireport.id as lid, contribution_civireport_direct.*
1101 FROM civicrm_line_item line_item_civireport
1102 LEFT JOIN civicrm_contribution contribution_civireport_direct
1103 ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = contribution_civireport_direct.id AND line_item_civireport.entity_table = 'civicrm_contribution')
1104
1105
1106 WHERE contribution_civireport_direct.id IS NOT NULL
1107
1108 UNION SELECT line_item_civireport.id as lid, contribution_civireport.*
1109 FROM civicrm_line_item line_item_civireport
1110 LEFT JOIN civicrm_participant participant_civireport
1111 ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = participant_civireport.id AND line_item_civireport.entity_table = 'civicrm_participant')
1112
1113 LEFT JOIN civicrm_participant_payment pp
1114 ON participant_civireport.id = pp.participant_id
1115 LEFT JOIN civicrm_contribution contribution_civireport
1116 ON pp.contribution_id = contribution_civireport.id
1117
1118 UNION SELECT line_item_civireport.id as lid,contribution_civireport.*
1119 FROM civicrm_line_item line_item_civireport
1120 LEFT JOIN civicrm_membership membership_civireport
1121 ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id =membership_civireport.id AND line_item_civireport.entity_table = 'civicrm_membership')
1122
1123 LEFT JOIN civicrm_membership_payment pp
1124 ON membership_civireport.id = pp.membership_id
1125 LEFT JOIN civicrm_contribution contribution_civireport
1126 ON pp.contribution_id = contribution_civireport.id
1127 ) as {$this->_aliases['civicrm_contribution']}
1128 ON {$this->_aliases['civicrm_contribution']}.lid = {$this->_aliases['civicrm_line_item']}.id
1129 ";
1130 }
1131
1132 public function joinLineItemFromContribution() {
1133
1134 // this can be stored as a temp table & indexed for more speed. Not done at this stage.
1135 // another option is to cache it but I haven't tried to put that code in yet (have used it before for one hour caching
1136 $this->_from .= "
1137 LEFT JOIN (
1138 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1139 FROM civicrm_contribution contribution_civireport_direct
1140 LEFT JOIN civicrm_line_item line_item_civireport ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = contribution_civireport_direct.id AND line_item_civireport.entity_table = 'civicrm_contribution')
1141 WHERE line_item_civireport.id IS NOT NULL
1142
1143 UNION
1144 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1145 FROM civicrm_contribution contribution_civireport_direct
1146 LEFT JOIN civicrm_participant_payment pp ON contribution_civireport_direct.id = pp.contribution_id
1147 LEFT JOIN civicrm_participant p ON pp.participant_id = p.id
1148 LEFT JOIN civicrm_line_item line_item_civireport ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = p.id AND line_item_civireport.entity_table = 'civicrm_participant')
1149 WHERE line_item_civireport.id IS NOT NULL
1150
1151 UNION
1152
1153 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1154 FROM civicrm_contribution contribution_civireport_direct
1155 LEFT JOIN civicrm_membership_payment pp ON contribution_civireport_direct.id = pp.contribution_id
1156 LEFT JOIN civicrm_membership p ON pp.membership_id = p.id
1157 LEFT JOIN civicrm_line_item line_item_civireport ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = p.id AND line_item_civireport.entity_table = 'civicrm_membership')
1158 WHERE line_item_civireport.id IS NOT NULL
1159 ) as {$this->_aliases['civicrm_line_item']}
1160 ON {$this->_aliases['civicrm_line_item']}.contid = {$this->_aliases['civicrm_contribution']}.id
1161
1162
1163 ";
1164 }
1165
1166 public function joinLineItemFromMembership() {
1167
1168 // this can be stored as a temp table & indexed for more speed. Not done at this stage.
1169 // another option is to cache it but I haven't tried to put that code in yet (have used it before for one hour caching
1170 $this->_from .= "
1171 LEFT JOIN (
1172 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1173 FROM civicrm_contribution contribution_civireport_direct
1174 LEFT JOIN civicrm_line_item line_item_civireport
1175 ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = contribution_civireport_direct.id AND line_item_civireport.entity_table = 'civicrm_contribution')
1176
1177 WHERE line_item_civireport.id IS NOT NULL
1178
1179 UNION
1180
1181 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1182 FROM civicrm_contribution contribution_civireport_direct
1183 LEFT JOIN civicrm_membership_payment pp ON contribution_civireport_direct.id = pp.contribution_id
1184 LEFT JOIN civicrm_membership p ON pp.membership_id = p.id
1185 LEFT JOIN civicrm_line_item line_item_civireport ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = p.id AND line_item_civireport.entity_table = 'civicrm_membership')
1186 WHERE line_item_civireport.id IS NOT NULL
1187 ) as {$this->_aliases['civicrm_line_item']}
1188 ON {$this->_aliases['civicrm_line_item']}.contid = {$this->_aliases['civicrm_contribution']}.id
1189 ";
1190 }
1191
1192 public function joinContactFromParticipant() {
1193 $this->_from .= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
1194 ON {$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
1195 }
1196
1197 public function joinContactFromMembership() {
1198 $this->_from .= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
1199 ON {$this->_aliases['civicrm_membership']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
1200 }
1201
1202 public function joinContactFromContribution() {
1203 $this->_from .= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
1204 ON {$this->_aliases['civicrm_contribution']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
1205 }
1206
1207 public function joinEventFromParticipant() {
1208 $this->_from .= " LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
1209 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND
1210 ({$this->_aliases['civicrm_event']}.is_template IS NULL OR
1211 {$this->_aliases['civicrm_event']}.is_template = 0)";
1212 }
1213
1214 /**
1215 * Retrieve text for financial type from pseudoconstant
1216 *
1217 * @param $value
1218 * @param array $row
1219 *
1220 * @return string
1221 */
1222 public function alterNickName($value, &$row) {
1223 if (empty($row['civicrm_contact_id'])) {
1224 return NULL;
1225 }
1226 $contactID = $row['civicrm_contact_id'];
1227 return "<div id=contact-{$contactID} class='crm-entity'>
1228 <span class='crm-editable crmf-nick_name crm-editable-enabled' data-action='create'>
1229 " . $value . "</span></div>";
1230 }
1231
1232 /**
1233 * Retrieve text for contribution type from pseudoconstant
1234 *
1235 * @param $value
1236 * @param array $row
1237 *
1238 * @return array|string
1239 */
1240 public function alterContributionType($value, &$row) {
1241 return is_string(CRM_Contribute_PseudoConstant::financialType($value, FALSE)) ? CRM_Contribute_PseudoConstant::financialType($value, FALSE) : '';
1242 }
1243
1244 /**
1245 * Retrieve text for contribution status from pseudoconstant
1246 *
1247 * @param $value
1248 * @param array $row
1249 *
1250 * @return array
1251 */
1252 public function alterContributionStatus($value, &$row) {
1253 return CRM_Contribute_PseudoConstant::contributionStatus($value);
1254 }
1255
1256 /**
1257 * Retrieve text for payment instrument from pseudoconstant
1258 *
1259 * @param $value
1260 * @param array $row
1261 *
1262 * @return array
1263 */
1264 public function alterEventType($value, &$row) {
1265 return CRM_Event_PseudoConstant::eventType($value);
1266 }
1267
1268 /**
1269 * @param $value
1270 * @param array $row
1271 *
1272 * @return array|string
1273 */
1274 public function alterEventID($value, &$row) {
1275 return is_string(CRM_Event_PseudoConstant::event($value, FALSE)) ? CRM_Event_PseudoConstant::event($value, FALSE) : '';
1276 }
1277
1278 /**
1279 * @param $value
1280 * @param array $row
1281 *
1282 * @return array|string
1283 */
1284 public function alterMembershipTypeID($value, &$row) {
1285 return is_string(CRM_Member_PseudoConstant::membershipType($value, FALSE)) ? CRM_Member_PseudoConstant::membershipType($value, FALSE) : '';
1286 }
1287
1288 /**
1289 * @param $value
1290 * @param array $row
1291 *
1292 * @return array|string
1293 */
1294 public function alterMembershipStatusID($value, &$row) {
1295 return is_string(CRM_Member_PseudoConstant::membershipStatus($value, FALSE)) ? CRM_Member_PseudoConstant::membershipStatus($value, FALSE) : '';
1296 }
1297
1298 /**
1299 * @param $value
1300 * @param array $row
1301 * @param $selectedfield
1302 * @param string $criteriaFieldName
1303 *
1304 * @return array
1305 */
1306 public function alterCountryID($value, &$row, $selectedfield, $criteriaFieldName) {
1307 $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl);
1308 $row[$selectedfield . '_link'] = $url;
1309 $row[$selectedfield .
1310 '_hover'] = ts("%1 for this country.", array(1 => $value));
1311 $countries = CRM_Core_PseudoConstant::country($value, FALSE);
1312 if (!is_array($countries)) {
1313 return $countries;
1314 }
1315 }
1316
1317 /**
1318 * @param $value
1319 * @param array $row
1320 * @param $selectedfield
1321 * @param string $criteriaFieldName
1322 *
1323 * @return array
1324 */
1325 public function alterCountyID($value, &$row, $selectedfield, $criteriaFieldName) {
1326 $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl);
1327 $row[$selectedfield . '_link'] = $url;
1328 $row[$selectedfield .
1329 '_hover'] = ts("%1 for this county.", array(1 => $value));
1330 $counties = CRM_Core_PseudoConstant::county($value, FALSE);
1331 if (!is_array($counties)) {
1332 return $counties;
1333 }
1334 }
1335
1336 /**
1337 * @param $value
1338 * @param array $row
1339 * @param $selectedfield
1340 * @param string $criteriaFieldName
1341 *
1342 * @return array
1343 */
1344 public function alterStateProvinceID($value, &$row, $selectedfield, $criteriaFieldName) {
1345 $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl);
1346 $row[$selectedfield . '_link'] = $url;
1347 $row[$selectedfield .
1348 '_hover'] = ts("%1 for this state.", array(1 => $value));
1349
1350 $states = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
1351 if (!is_array($states)) {
1352 return $states;
1353 }
1354 }
1355
1356 /**
1357 * @param $value
1358 * @param array $row
1359 * @param string $fieldname
1360 *
1361 * @return mixed
1362 */
1363 public function alterContactID($value, &$row, $fieldname) {
1364 $row[$fieldname . '_link'] = CRM_Utils_System::url("civicrm/contact/view",
1365 'reset=1&cid=' . $value, $this->_absoluteUrl);
1366 return $value;
1367 }
1368
1369 /**
1370 * @param $value
1371 *
1372 * @return array
1373 */
1374 public function alterParticipantStatus($value) {
1375 if (empty($value)) {
1376 return NULL;
1377 }
1378 return CRM_Event_PseudoConstant::participantStatus($value, FALSE, 'label');
1379 }
1380
1381 /**
1382 * @param $value
1383 *
1384 * @return string|void
1385 */
1386 public function alterParticipantRole($value) {
1387 if (empty($value)) {
1388 return NULL;
1389 }
1390 $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
1391 $value = array();
1392 foreach ($roles as $role) {
1393 $value[$role] = CRM_Event_PseudoConstant::participantRole($role, FALSE);
1394 }
1395 return implode(', ', $value);
1396 }
1397
1398 /**
1399 * @param $value
1400 *
1401 * @return mixed
1402 */
1403 public function alterPaymentType($value) {
1404 $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
1405 return $paymentInstruments[$value];
1406 }
1407 }