3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Report_Form_Extended
extends CRM_Report_Form
{
36 protected $_addressField = FALSE;
38 protected $_emailField = FALSE;
40 protected $_summary = NULL;
42 protected $_customGroupExtends = array();
43 protected $_baseTable = 'civicrm_contact';
51 function __construct() {
52 parent
::__construct();
55 function preProcess() {
65 * From clause build where baseTable & fromClauses are defined
68 if (!empty($this->_baseTable
)) {
69 $this->buildACLClause($this->_aliases
['civicrm_contact']);
70 $this->_from
= "FROM {$this->_baseTable} {$this->_aliases[$this->_baseTable]}";
71 $availableClauses = $this->getAvailableJoins();
72 foreach ($this->fromClauses() as $fromClause) {
73 $fn = $availableClauses[$fromClause]['callback'];
76 if (strstr($this->_from
, 'civicrm_contact')) {
77 $this->_from
.= $this->_aclFrom
;
83 * Define any from clauses in use (child classes to override)
88 function fromClauses() {
94 //@todo - need to re-visit this - bad behaviour from pa
95 if ($this->_groupBy
== 'GROUP BY') {
96 $this->_groupBY
= NULL;
98 // if a stat field has been selected the do a group by
99 if (!empty($this->_statFields
) && empty($this->_groupBy
)) {
100 $this->_groupBy
[] = $this->_aliases
[$this->_baseTable
] . ".id";
102 //@todo - this should be in the parent function or at parent level - perhaps build query should do this?
103 if (!empty($this->_groupBy
) && is_array($this->_groupBy
)) {
104 $this->_groupBy
= 'GROUP BY ' . implode(',', $this->_groupBy
);
117 function statistics(&$rows) {
118 return parent
::statistics($rows);
121 function postProcess() {
122 if (!empty($this->_aclTable
) && !empty($this->_aliases
[$this->_aclTable
])) {
123 $this->buildACLClause($this->_aliases
[$this->_aclTable
]);
125 parent
::postProcess();
131 function alterDisplay(&$rows) {
132 parent
::alterDisplay($rows);
134 //THis is all generic functionality which can hopefully go into the parent class
135 // it introduces the option of defining an alter display function as part of the column definition
136 // @tod tidy up the iteration so it happens in this function
137 list($firstRow) = $rows;
138 // no result to alter
139 if (empty($firstRow)) {
142 $selectedFields = array_keys($firstRow);
144 $alterfunctions = $altermap = array();
145 foreach ($this->_columns
as $tablename => $table) {
146 if (array_key_exists('fields', $table)) {
147 foreach ($table['fields'] as $field => $specs) {
148 if (in_array($tablename . '_' . $field, $selectedFields) &&
149 array_key_exists('alter_display', $specs)
151 $alterfunctions[$tablename . '_' .
152 $field] = $specs['alter_display'];
153 $altermap[$tablename . '_' . $field] = $field;
158 if (empty($alterfunctions)) {
159 // - no manipulation to be done
163 foreach ($rows as $index => & $row) {
164 foreach ($row as $selectedfield => $value) {
165 if (array_key_exists($selectedfield, $alterfunctions)) {
166 $rows[$index][$selectedfield] = $this->$alterfunctions[$selectedfield]($value, $row, $selectedfield, $altermap[$selectedfield]);
175 function getLineItemColumns() {
177 'civicrm_line_item' => array(
178 'dao' => 'CRM_Price_BAO_LineItem',
181 'title' => ts('Quantity'),
182 'type' => CRM_Utils_Type
::T_INT
,
183 'statistics' => array('sum' => ts('Total Quantity Selected')),
185 'unit_price' => array(
186 'title' => ts('Unit Price'),
188 'line_total' => array(
189 'title' => ts('Line Total'),
190 'type' => CRM_Utils_Type
::T_MONEY
,
191 'statistics' => array('sum' => ts('Total of Line Items')),
194 'participant_count' => array(
195 'title' => ts('Participant Count'),
196 'statistics' => array('sum' => ts('Total Participants')),
200 'title' => ts('Quantity'),
201 'type' => CRM_Utils_Type
::T_INT
,
202 'operator' => CRM_Report_Form
::OP_INT
,
205 'group_bys' => array(
206 'price_field_id' => array(
207 'title' => ts('Price Field'),
209 'price_field_value_id' => array(
210 'title' => ts('Price Field Option'),
212 'line_item_id' => array(
213 'title' => ts('Individual Line Item'),
224 function getPriceFieldValueColumns() {
226 'civicrm_price_field_value' => array(
227 'dao' => 'CRM_Price_BAO_PriceFieldValue',
229 'price_field_value_label' => array(
230 'title' => ts('Price Field Value Label'),
235 'price_field_value_label' => array(
236 'title' => ts('Price Fields Value Label'),
237 'type' => CRM_Utils_Type
::T_STRING
,
238 'operator' => 'like',
242 'order_bys' => array(
244 'title' => ts('Price Field Value Label'),
247 'group_bys' => //note that we have a requirement to group by label such that all 'Promo book' lines
248 // are grouped together across price sets but there may be a separate need to group
249 // by id so that entries in one price set are distinct from others. Not quite sure what
250 // to call the distinction for end users benefit
252 'price_field_value_label' => array(
253 'title' => ts('Price Field Value Label'),
264 function getPriceFieldColumns() {
266 'civicrm_price_field' => array(
267 'dao' => 'CRM_Price_BAO_PriceField',
269 'price_field_label' => array(
270 'title' => ts('Price Field Label'),
275 'price_field_label' => array(
276 'title' => ts('Price Field Label'),
277 'type' => CRM_Utils_Type
::T_STRING
,
278 'operator' => 'like',
282 'order_bys' => array(
283 'price_field_label' => array(
284 'title' => ts('Price Field Label'),
288 'group_bys' => array(
289 'price_field_label' => array(
290 'title' => ts('Price Field Label'),
301 function getParticipantColumns() {
302 static $_events = array();
303 if (!isset($_events['all'])) {
304 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 'civicrm_participant' => array(
308 'dao' => 'CRM_Event_DAO_Participant',
310 'participant_id' => array('title' => 'Participant ID'),
311 'participant_record' => array(
313 'title' => ts('Participant ID'),
316 'title' => ts('Event ID'),
317 'type' => CRM_Utils_Type
::T_STRING
,
318 'alter_display' => 'alterEventID',
320 'status_id' => array(
321 'title' => ts('Status'),
322 'alter_display' => 'alterParticipantStatus',
325 'title' => ts('Role'),
326 'alter_display' => 'alterParticipantRole',
328 'participant_fee_level' => NULL,
329 'participant_fee_amount' => NULL,
330 'participant_register_date' => array('title' => ts('Registration Date')),
332 'grouping' => 'event-fields',
335 'name' => 'event_id',
336 'title' => ts('Event'),
337 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
338 'options' => $_events['all'],
341 'name' => 'status_id',
342 'title' => ts('Participant Status'),
343 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
344 'options' => CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label'),
348 'title' => ts('Participant Role'),
349 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
350 'options' => CRM_Event_PseudoConstant
::participantRole(),
352 'participant_register_date' => array(
353 'title' => ' Registration Date',
354 'operatorType' => CRM_Report_Form
::OP_DATE
,
357 'order_bys' => array(
359 'title' => ts('Event'),
360 'default_weight' => '1',
361 'default_order' => 'ASC'
364 'group_bys' => array(
365 'event_id' => array('title' => ts('Event')),
374 function getMembershipColumns() {
376 'civicrm_membership' => array(
377 'dao' => 'CRM_Member_DAO_Membership',
378 'grouping' => 'member-fields',
380 'membership_type_id' => array(
381 'title' => 'Membership Type',
383 'alter_display' => 'alterMembershipTypeID',
385 'status_id' => array(
386 'title' => 'Membership Status',
388 'alter_display' => 'alterMembershipStatusID',
391 'start_date' => array(
392 'title' => ts('Current Cycle Start Date'),
395 'title' => ts('Current Membership Cycle End Date'),
398 'group_bys' => array(
399 'membership_type_id' => array(
400 'title' => ts('Membership Type'),
404 'join_date' => array(
405 'type' => CRM_Utils_Type
::T_DATE
,
406 'operatorType' => CRM_Report_Form
::OP_DATE
,
416 function getMembershipTypeColumns() {
418 'civicrm_membership_type' => array(
419 'dao' => 'CRM_Member_DAO_MembershipType',
420 'grouping' => 'member-fields',
424 'title' => ts('Membership Types'),
425 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
426 'type' => CRM_Utils_Type
::T_INT + CRM_Utils_Type
::T_ENUM
,
427 'options' => CRM_Member_PseudoConstant
::membershipType(),
437 function getEventColumns() {
439 'civicrm_event' => array(
440 'dao' => 'CRM_Event_DAO_Event',
443 'no_display' => TRUE,
447 'title' => ts('Event Title'),
450 'event_type_id' => array(
451 'title' => ts('Event Type'),
453 'alter_display' => 'alterEventType',
455 'fee_label' => array('title' => ts('Fee Label')),
456 'event_start_date' => array(
457 'title' => ts('Event Start Date'),
459 'event_end_date' => array('title' => ts('Event End Date')),
460 'max_participants' => array(
461 'title' => ts('Capacity'),
462 'type' => CRM_Utils_Type
::T_INT
,
465 'grouping' => 'event-fields',
467 'event_type_id' => array(
468 'name' => 'event_type_id',
469 'title' => ts('Event Type'),
470 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
471 'options' => CRM_Core_OptionGroup
::values('event_type'),
473 'event_title' => array(
475 'title' => ts('Event Title'),
476 'operatorType' => CRM_Report_Form
::OP_STRING
,
479 'order_bys' => array(
480 'event_type_id' => array(
481 'title' => ts('Event Type'),
482 'default_weight' => '2',
483 'default_order' => 'ASC',
486 'group_bys' => array(
487 'event_type_id' => array(
488 'title' => ts('Event Type'),
498 function getContributionColumns() {
500 'civicrm_contribution' => array(
501 'dao' => 'CRM_Contribute_DAO_Contribution',
503 'contribution_id' => array(
506 'financial_type_id' => array(
507 'title' => ts('Financial Type'),
509 'alter_display' => 'alterContributionType',
511 'payment_instrument_id' => array(
512 'title' => ts('Payment Instrument'),
513 'alter_display' => 'alterPaymentType',
515 'source' => array('title' => 'Contribution Source'),
517 'receive_date' => array('default' => TRUE),
518 'receipt_date' => NULL,
519 'fee_amount' => NULL,
520 'net_amount' => NULL,
521 'total_amount' => array(
522 'title' => ts('Amount'),
523 'statistics' => array('sum' => ts('Total Amount')),
524 'type' => CRM_Utils_Type
::T_MONEY
,
528 'receive_date' => array('operatorType' => CRM_Report_Form
::OP_DATE
),
529 'financial_type_id' => array(
530 'title' => ts('Financial Type'),
531 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
532 'options' => CRM_Contribute_PseudoConstant
::financialType(),
534 'payment_instrument_id' => array(
535 'title' => ts('Payment Type'),
536 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
537 'options' => CRM_Contribute_PseudoConstant
::paymentInstrument(),
539 'contribution_status_id' => array(
540 'title' => ts('Contribution Status'),
541 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
542 'options' => CRM_Contribute_PseudoConstant
::contributionStatus(),
544 'total_amount' => array('title' => ts('Contribution Amount')),
546 'order_bys' => array(
547 'payment_instrument_id' => array(
548 'title' => ts('Payment Instrument'),
550 'financial_type_id' => array(
551 'title' => ts('Financial Type'),
554 'group_bys' => array(
555 'financial_type_id' => array('title' => ts('Financial Type')),
556 'payment_instrument_id' => array('title' => ts('Payment Instrument')),
557 'contribution_id' => array(
558 'title' => ts('Individual Contribution'),
561 'source' => array('title' => 'Contribution Source'),
563 'grouping' => 'contribution-fields',
571 function getContactColumns() {
573 'civicrm_contact' => array(
574 'dao' => 'CRM_Contact_DAO_Contact',
576 'display_name' => array(
577 'title' => ts('Contact Name'),
580 'title' => ts('Contact ID'),
581 'alter_display' => 'alterContactID',
583 'first_name' => array(
584 'title' => ts('First Name'),
586 'last_name' => array(
587 'title' => ts('Last Name'),
589 'nick_name' => array(
590 'title' => ts('Nickname'),
591 'alter_display' => 'alterNickname',
596 'title' => ts('Contact ID'),
599 'sort_name' => array(
600 'title' => ts('Contact Name'),
603 'grouping' => 'contact-fields',
604 'order_bys' => array(
605 'sort_name' => array(
606 'title' => ts('Last Name, First Name'),
608 'default_weight' => '0',
609 'default_order' => 'ASC',
619 function getCaseColumns() {
621 'civicrm_case' => array(
622 'dao' => 'CRM_Case_DAO_Case',
625 'title' => ts('Case ID'),
629 'title' => ts('Case Subject'),
632 'status_id' => array(
633 'title' => ts('Status'),
636 'case_type_id' => array(
637 'title' => ts('Case Type'),
640 'case_start_date' => array(
641 'title' => ts('Case Start Date'),
642 'name' => 'start_date',
645 'case_end_date' => array(
646 'title' => ts('Case End Date'),
647 'name' => 'end_date',
650 'case_duration' => array(
651 'name' => 'duration',
652 'title' => ts('Duration (Days)'),
655 'case_is_deleted' => array(
656 'name' => 'is_deleted',
657 'title' => ts('Case Deleted?'),
659 'type' => CRM_Utils_Type
::T_INT
663 'case_start_date' => array(
664 'title' => ts('Case Start Date'),
665 'operatorType' => CRM_Report_Form
::OP_DATE
,
666 'type' => CRM_Utils_Type
::T_DATE
,
667 'name' => 'start_date',
669 'case_end_date' => array(
670 'title' => ts('Case End Date'),
671 'operatorType' => CRM_Report_Form
::OP_DATE
,
672 'type' => CRM_Utils_Type
::T_DATE
,
675 'case_type_id' => array(
676 'title' => ts('Case Type'),
677 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
678 'options' => $this->case_types
680 'case_status_id' => array(
681 'title' => ts('Case Status'),
682 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
683 'options' => $this->case_statuses
,
684 'name' => 'status_id'
686 'case_is_deleted' => array(
687 'title' => ts('Case Deleted?'),
688 'type' => CRM_Report_Form
::OP_INT
,
689 'operatorType' => CRM_Report_Form
::OP_SELECT
,
690 'options' => $this->deleted_labels
,
692 'name' => 'is_deleted'
700 * adding address fields to construct function in reports
701 * @param array $options Options for the report
702 * - prefix prefix to add (e.g. 'honor' when getting address details for honor contact
703 * - prefix_label optional prefix lable eg. "Honoree " for front end
704 * - group_by enable these fields for group by - default false
705 * - order_by enable these fields for order by
706 * - filters enable these fields for filtering
707 * - defaults - (is this working?) values to pre-populate
708 * @return array address fields for construct clause
711 * Get address columns to add to array
713 * @param array $options
714 * - prefix Prefix to add to table (in case of more than one instance of the table)
715 * - prefix_label Label to give columns from this address table instance
717 * @return array address columns definition
720 * @param array $options
724 function getAddressColumns($options = array()) {
725 $defaultOptions = array(
727 'prefix_label' => '',
736 $options = array_merge($defaultOptions, $options);
738 $addressFields = array(
739 $options['prefix'] . 'civicrm_address' => array(
740 'dao' => 'CRM_Core_DAO_Address',
741 'name' => 'civicrm_address',
742 'alias' => $options['prefix'] . 'civicrm_address',
744 $options['prefix'] . 'name' => array(
745 'title' => ts($options['prefix_label'] . 'Address Name'),
746 'default' => CRM_Utils_Array
::value('name', $options['defaults'], FALSE),
749 $options['prefix'] . 'street_address' => array(
750 'title' => ts($options['prefix_label'] . 'Street Address'),
751 'default' => CRM_Utils_Array
::value('street_address', $options['defaults'], FALSE),
752 'name' => 'street_address',
754 $options['prefix'] . 'supplemental_address_1' => array(
755 'title' => ts($options['prefix_label'] .
756 'Supplementary Address Field 1'),
757 'default' => CRM_Utils_Array
::value('supplemental_address_1', $options['defaults'], FALSE),
758 'name' => 'supplemental_address_1',
760 $options['prefix'] . 'supplemental_address_2' => array(
761 'title' => ts($options['prefix_label'] .
762 'Supplementary Address Field 2'),
763 'default' => CRM_Utils_Array
::value('supplemental_address_2', $options['defaults'], FALSE),
764 'name' => 'supplemental_address_2',
766 $options['prefix'] . 'street_number' => array(
767 'name' => 'street_number',
768 'title' => ts($options['prefix_label'] . 'Street Number'),
770 'default' => CRM_Utils_Array
::value('street_number', $options['defaults'], FALSE),
771 'name' => 'street_number',
773 $options['prefix'] . 'street_name' => array(
774 'name' => 'street_name',
775 'title' => ts($options['prefix_label'] . 'Street Name'),
777 'default' => CRM_Utils_Array
::value('street_name', $options['defaults'], FALSE),
778 'name' => 'street_name',
780 $options['prefix'] . 'street_unit' => array(
781 'name' => 'street_unit',
782 'title' => ts($options['prefix_label'] . 'Street Unit'),
784 'default' => CRM_Utils_Array
::value('street_unit', $options['defaults'], FALSE),
785 'name' => 'street_unit',
787 $options['prefix'] . 'city' => array(
788 'title' => ts($options['prefix_label'] . 'City'),
789 'default' => CRM_Utils_Array
::value('city', $options['defaults'], FALSE),
792 $options['prefix'] . 'postal_code' => array(
793 'title' => ts($options['prefix_label'] . 'Postal Code'),
794 'default' => CRM_Utils_Array
::value('postal_code', $options['defaults'], FALSE),
795 'name' => 'postal_code',
797 $options['prefix'] . 'county_id' => array(
798 'title' => ts($options['prefix_label'] . 'County'),
799 'default' => CRM_Utils_Array
::value('county_id', $options['defaults'], FALSE),
800 'alter_display' => 'alterCountyID',
801 'name' => 'county_id',
803 $options['prefix'] . 'state_province_id' => array(
804 'title' => ts($options['prefix_label'] . 'State/Province'),
805 'default' => CRM_Utils_Array
::value('state_province_id', $options['defaults'], FALSE),
806 'alter_display' => 'alterStateProvinceID',
807 'name' => 'state_province_id',
809 $options['prefix'] . 'country_id' => array(
810 'title' => ts($options['prefix_label'] . 'Country'),
811 'default' => CRM_Utils_Array
::value('country_id', $options['defaults'], FALSE),
812 'alter_display' => 'alterCountryID',
813 'name' => 'country_id',
816 'grouping' => 'location-fields',
820 if ($options['filters']) {
821 $addressFields[$options['prefix'] . 'civicrm_address']['filters'] = array(
822 $options['prefix'] . 'street_number' => array(
823 'title' => ts($options['prefix_label'] . 'Street Number'),
825 'name' => 'street_number',
827 $options['prefix'] . 'street_name' => array(
828 'title' => ts($options['prefix_label'] . 'Street Name'),
829 'name' => $options['prefix'] . 'street_name',
830 'operator' => 'like',
832 $options['prefix'] . 'postal_code' => array(
833 'title' => ts($options['prefix_label'] . 'Postal Code'),
835 'name' => 'postal_code',
837 $options['prefix'] . 'city' => array(
838 'title' => ts($options['prefix_label'] . 'City'),
839 'operator' => 'like',
842 $options['prefix'] . 'county_id' => array(
843 'name' => 'county_id',
844 'title' => ts($options['prefix_label'] . 'County'),
845 'type' => CRM_Utils_Type
::T_INT
,
846 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
847 'options' => CRM_Core_PseudoConstant
::county(),
849 $options['prefix'] . 'state_province_id' => array(
850 'name' => 'state_province_id',
851 'title' => ts($options['prefix_label'] . 'State/Province'),
852 'type' => CRM_Utils_Type
::T_INT
,
853 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
854 'options' => CRM_Core_PseudoConstant
::stateProvince(),
856 $options['prefix'] . 'country_id' => array(
857 'name' => 'country_id',
858 'title' => ts($options['prefix_label'] . 'Country'),
859 'type' => CRM_Utils_Type
::T_INT
,
860 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
861 'options' => CRM_Core_PseudoConstant
::country(),
866 if ($options['order_by']) {
867 $addressFields[$options['prefix'] .
868 'civicrm_address']['order_bys'] = array(
869 $options['prefix'] . 'street_name' => array(
870 'title' => ts($options['prefix_label'] . 'Street Name'),
871 'name' => 'street_name',
873 $options['prefix'] . 'street_number' => array(
874 'title' => ts($options['prefix_label'] . 'Odd / Even Street Number'),
875 'name' => 'street_number',
877 $options['prefix'] . 'street_address' => array(
878 'title' => ts($options['prefix_label'] . 'Street Address'),
879 'name' => 'street_address',
881 $options['prefix'] . 'city' => array(
882 'title' => ts($options['prefix_label'] . 'City'),
885 $options['prefix'] . 'postal_code' => array(
886 'title' => ts($options['prefix_label'] . 'Post Code'),
887 'name' => 'postal_code',
892 if ($options['group_by']) {
893 $addressFields['civicrm_address']['group_bys'] = array(
894 $options['prefix'] . 'street_address' => array(
895 'title' => ts($options['prefix_label'] . 'Street Address'),
896 'name' => 'street_address',
898 $options['prefix'] . 'city' => array(
899 'title' => ts($options['prefix_label'] . 'City'),
902 $options['prefix'] . 'postal_code' => array(
903 'title' => ts($options['prefix_label'] . 'Post Code'),
904 'name' => 'postal_code',
906 $options['prefix'] . 'state_province_id' => array(
907 'title' => ts($options['prefix_label'] . 'State/Province'),
908 'name' => 'state_province_id',
910 $options['prefix'] . 'country_id' => array(
911 'title' => ts($options['prefix_label'] . 'Country'),
912 'name' => 'country_id',
914 $options['prefix'] . 'county_id' => array(
915 'title' => ts($options['prefix_label'] . 'County'),
916 'name' => 'county_id',
920 return $addressFields;
924 * Get Information about advertised Joins
929 function getAvailableJoins() {
931 'priceFieldValue_from_lineItem' => array(
932 'leftTable' => 'civicrm_line_item',
933 'rightTable' => 'civicrm_price_field_value',
934 'callback' => 'joinPriceFieldValueFromLineItem',
936 'priceField_from_lineItem' => array(
937 'leftTable' => 'civicrm_line_item',
938 'rightTable' => 'civicrm_price_field',
939 'callback' => 'joinPriceFieldFromLineItem',
941 'participant_from_lineItem' => array(
942 'leftTable' => 'civicrm_line_item',
943 'rightTable' => 'civicrm_participant',
944 'callback' => 'joinParticipantFromLineItem',
946 'contribution_from_lineItem' => array(
947 'leftTable' => 'civicrm_line_item',
948 'rightTable' => 'civicrm_contribution',
949 'callback' => 'joinContributionFromLineItem',
951 'membership_from_lineItem' => array(
952 'leftTable' => 'civicrm_line_item',
953 'rightTable' => 'civicrm_membership',
954 'callback' => 'joinMembershipFromLineItem',
956 'contribution_from_participant' => array(
957 'leftTable' => 'civicrm_participant',
958 'rightTable' => 'civicrm_contribution',
959 'callback' => 'joinContributionFromParticipant',
961 'contribution_from_membership' => array(
962 'leftTable' => 'civicrm_membership',
963 'rightTable' => 'civicrm_contribution',
964 'callback' => 'joinContributionFromMembership',
966 'membership_from_contribution' => array(
967 'leftTable' => 'civicrm_contribution',
968 'rightTable' => 'civicrm_membership',
969 'callback' => 'joinMembershipFromContribution',
971 'membershipType_from_membership' => array(
972 'leftTable' => 'civicrm_membership',
973 'rightTable' => 'civicrm_membership_type',
974 'callback' => 'joinMembershipTypeFromMembership',
976 'lineItem_from_contribution' => array(
977 'leftTable' => 'civicrm_contribution',
978 'rightTable' => 'civicrm_line_item',
979 'callback' => 'joinLineItemFromContribution',
981 'lineItem_from_membership' => array(
982 'leftTable' => 'civicrm_membership',
983 'rightTable' => 'civicrm_line_item',
984 'callback' => 'joinLineItemFromMembership',
986 'contact_from_participant' => array(
987 'leftTable' => 'civicrm_participant',
988 'rightTable' => 'civicrm_contact',
989 'callback' => 'joinContactFromParticipant',
991 'contact_from_membership' => array(
992 'leftTable' => 'civicrm_membership',
993 'rightTable' => 'civicrm_contact',
994 'callback' => 'joinContactFromMembership',
996 'contact_from_contribution' => array(
997 'leftTable' => 'civicrm_contribution',
998 'rightTable' => 'civicrm_contact',
999 'callback' => 'joinContactFromContribution',
1001 'event_from_participant' => array(
1002 'leftTable' => 'civicrm_participant',
1003 'rightTable' => 'civicrm_event',
1004 'callback' => 'joinEventFromParticipant',
1006 'address_from_contact' => array(
1007 'leftTable' => 'civicrm_contact',
1008 'rightTable' => 'civicrm_address',
1009 'callback' => 'joinAddressFromContact',
1015 * Add join from contact table to address. Prefix will be added to both tables
1016 * as it's assumed you are using it to get address of a secondary contact
1019 * @param string $prefix
1021 function joinAddressFromContact($prefix = '') {
1022 $this->_from
.= " LEFT JOIN civicrm_address {$this->_aliases[$prefix .
1024 ON {$this->_aliases[$prefix .
1025 'civicrm_address']}.contact_id = {$this->_aliases[$prefix .
1026 'civicrm_contact']}.id";
1029 function joinPriceFieldValueFromLineItem() {
1030 $this->_from
.= " LEFT JOIN civicrm_price_field_value {$this->_aliases['civicrm_price_field_value']}
1031 ON {$this->_aliases['civicrm_line_item']}.price_field_value_id = {$this->_aliases['civicrm_price_field_value']}.id";
1034 function joinPriceFieldFromLineItem() {
1036 LEFT JOIN civicrm_price_field {$this->_aliases['civicrm_price_field']}
1037 ON {$this->_aliases['civicrm_line_item']}.price_field_id = {$this->_aliases['civicrm_price_field']}.id
1042 * Define join from line item table to participant table
1044 function joinParticipantFromLineItem() {
1045 $this->_from
.= " LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
1046 ON ( {$this->_aliases['civicrm_line_item']}.entity_id = {$this->_aliases['civicrm_participant']}.id
1047 AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant')
1052 * Define join from line item table to Membership table. Seems to be still via contribution
1053 * as the entity. Have made 'inner' to restrict does that make sense?
1055 function joinMembershipFromLineItem() {
1056 $this->_from
.= " INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
1057 ON ( {$this->_aliases['civicrm_line_item']}.entity_id = {$this->_aliases['civicrm_contribution']}.id
1058 AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_contribution')
1059 LEFT JOIN civicrm_membership_payment pp
1060 ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id
1061 LEFT JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
1062 ON pp.membership_id = {$this->_aliases['civicrm_membership']}.id
1067 * Define join from Participant to Contribution table
1069 function joinContributionFromParticipant() {
1070 $this->_from
.= " LEFT JOIN civicrm_participant_payment pp
1071 ON {$this->_aliases['civicrm_participant']}.id = pp.participant_id
1072 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
1073 ON pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id
1078 * Define join from Membership to Contribution table
1080 function joinContributionFromMembership() {
1081 $this->_from
.= " LEFT JOIN civicrm_membership_payment pp
1082 ON {$this->_aliases['civicrm_membership']}.id = pp.membership_id
1083 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
1084 ON pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id
1088 function joinParticipantFromContribution() {
1089 $this->_from
.= " LEFT JOIN civicrm_participant_payment pp
1090 ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id
1091 LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
1092 ON pp.participant_id = {$this->_aliases['civicrm_participant']}.id";
1095 function joinMembershipFromContribution() {
1097 LEFT JOIN civicrm_membership_payment pp
1098 ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id
1099 LEFT JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
1100 ON pp.membership_id = {$this->_aliases['civicrm_membership']}.id";
1103 function joinMembershipTypeFromMembership() {
1105 LEFT JOIN civicrm_membership_type {$this->_aliases['civicrm_membership_type']}
1106 ON {$this->_aliases['civicrm_membership']}.membership_type_id = {$this->_aliases['civicrm_membership_type']}.id
1110 function joinContributionFromLineItem() {
1112 // this can be stored as a temp table & indexed for more speed. Not done at this state.
1113 // 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
1114 $this->_from
.= " LEFT JOIN (SELECT line_item_civireport.id as lid, contribution_civireport_direct.*
1115 FROM civicrm_line_item line_item_civireport
1116 LEFT JOIN civicrm_contribution contribution_civireport_direct
1117 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')
1120 WHERE contribution_civireport_direct.id IS NOT NULL
1122 UNION SELECT line_item_civireport.id as lid, contribution_civireport.*
1123 FROM civicrm_line_item line_item_civireport
1124 LEFT JOIN civicrm_participant participant_civireport
1125 ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = participant_civireport.id AND line_item_civireport.entity_table = 'civicrm_participant')
1127 LEFT JOIN civicrm_participant_payment pp
1128 ON participant_civireport.id = pp.participant_id
1129 LEFT JOIN civicrm_contribution contribution_civireport
1130 ON pp.contribution_id = contribution_civireport.id
1132 UNION SELECT line_item_civireport.id as lid,contribution_civireport.*
1133 FROM civicrm_line_item line_item_civireport
1134 LEFT JOIN civicrm_membership membership_civireport
1135 ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id =membership_civireport.id AND line_item_civireport.entity_table = 'civicrm_membership')
1137 LEFT JOIN civicrm_membership_payment pp
1138 ON membership_civireport.id = pp.membership_id
1139 LEFT JOIN civicrm_contribution contribution_civireport
1140 ON pp.contribution_id = contribution_civireport.id
1141 ) as {$this->_aliases['civicrm_contribution']}
1142 ON {$this->_aliases['civicrm_contribution']}.lid = {$this->_aliases['civicrm_line_item']}.id
1146 function joinLineItemFromContribution() {
1148 // this can be stored as a temp table & indexed for more speed. Not done at this stage.
1149 // 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
1152 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1153 FROM civicrm_contribution contribution_civireport_direct
1154 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')
1155 WHERE line_item_civireport.id IS NOT NULL
1158 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1159 FROM civicrm_contribution contribution_civireport_direct
1160 LEFT JOIN civicrm_participant_payment pp ON contribution_civireport_direct.id = pp.contribution_id
1161 LEFT JOIN civicrm_participant p ON pp.participant_id = p.id
1162 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')
1163 WHERE line_item_civireport.id IS NOT NULL
1167 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1168 FROM civicrm_contribution contribution_civireport_direct
1169 LEFT JOIN civicrm_membership_payment pp ON contribution_civireport_direct.id = pp.contribution_id
1170 LEFT JOIN civicrm_membership p ON pp.membership_id = p.id
1171 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')
1172 WHERE line_item_civireport.id IS NOT NULL
1173 ) as {$this->_aliases['civicrm_line_item']}
1174 ON {$this->_aliases['civicrm_line_item']}.contid = {$this->_aliases['civicrm_contribution']}.id
1180 function joinLineItemFromMembership() {
1182 // this can be stored as a temp table & indexed for more speed. Not done at this stage.
1183 // 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
1186 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1187 FROM civicrm_contribution contribution_civireport_direct
1188 LEFT JOIN civicrm_line_item line_item_civireport
1189 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')
1191 WHERE line_item_civireport.id IS NOT NULL
1195 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1196 FROM civicrm_contribution contribution_civireport_direct
1197 LEFT JOIN civicrm_membership_payment pp ON contribution_civireport_direct.id = pp.contribution_id
1198 LEFT JOIN civicrm_membership p ON pp.membership_id = p.id
1199 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')
1200 WHERE line_item_civireport.id IS NOT NULL
1201 ) as {$this->_aliases['civicrm_line_item']}
1202 ON {$this->_aliases['civicrm_line_item']}.contid = {$this->_aliases['civicrm_contribution']}.id
1206 function joinContactFromParticipant() {
1207 $this->_from
.= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
1208 ON {$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
1211 function joinContactFromMembership() {
1212 $this->_from
.= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
1213 ON {$this->_aliases['civicrm_membership']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
1216 function joinContactFromContribution() {
1217 $this->_from
.= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
1218 ON {$this->_aliases['civicrm_contribution']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
1221 function joinEventFromParticipant() {
1222 $this->_from
.= " LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
1223 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND
1224 ({$this->_aliases['civicrm_event']}.is_template IS NULL OR
1225 {$this->_aliases['civicrm_event']}.is_template = 0)";
1229 * Retrieve text for financial type from pseudoconstant
1237 function alterNickName($value, &$row) {
1238 if (empty($row['civicrm_contact_id'])) {
1241 $contactID = $row['civicrm_contact_id'];
1242 return "<div id=contact-{$contactID} class='crm-entity'>
1243 <span class='crm-editable crmf-nick_name crm-editable-enabled' data-action='create'>
1244 " . $value . "</span></div>";
1248 * Retrieve text for contribution type from pseudoconstant
1254 * @return array|string
1256 function alterContributionType($value, &$row) {
1257 return is_string(CRM_Contribute_PseudoConstant
::financialType($value, FALSE)) ? CRM_Contribute_PseudoConstant
::financialType($value, FALSE) : '';
1261 * Retrieve text for contribution status from pseudoconstant
1269 function alterContributionStatus($value, &$row) {
1270 return CRM_Contribute_PseudoConstant
::contributionStatus($value);
1274 * Retrieve text for payment instrument from pseudoconstant
1282 function alterEventType($value, &$row) {
1283 return CRM_Event_PseudoConstant
::eventType($value);
1290 * @return array|string
1292 function alterEventID($value, &$row) {
1293 return is_string(CRM_Event_PseudoConstant
::event($value, FALSE)) ? CRM_Event_PseudoConstant
::event($value, FALSE) : '';
1300 * @return array|string
1302 function alterMembershipTypeID($value, &$row) {
1303 return is_string(CRM_Member_PseudoConstant
::membershipType($value, FALSE)) ? CRM_Member_PseudoConstant
::membershipType($value, FALSE) : '';
1310 * @return array|string
1312 function alterMembershipStatusID($value, &$row) {
1313 return is_string(CRM_Member_PseudoConstant
::membershipStatus($value, FALSE)) ? CRM_Member_PseudoConstant
::membershipStatus($value, FALSE) : '';
1319 * @param $selectedfield
1320 * @param string $criteriaFieldName
1324 function alterCountryID($value, &$row, $selectedfield, $criteriaFieldName) {
1325 $url = CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl
);
1326 $row[$selectedfield . '_link'] = $url;
1327 $row[$selectedfield .
1328 '_hover'] = ts("%1 for this country.", array(1 => $value));
1329 $countries = CRM_Core_PseudoConstant
::country($value, FALSE);
1330 if (!is_array($countries)) {
1338 * @param $selectedfield
1339 * @param string $criteriaFieldName
1343 function alterCountyID($value, &$row, $selectedfield, $criteriaFieldName) {
1344 $url = CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl
);
1345 $row[$selectedfield . '_link'] = $url;
1346 $row[$selectedfield .
1347 '_hover'] = ts("%1 for this county.", array(1 => $value));
1348 $counties = CRM_Core_PseudoConstant
::county($value, FALSE);
1349 if (!is_array($counties)) {
1357 * @param $selectedfield
1358 * @param string $criteriaFieldName
1362 function alterStateProvinceID($value, &$row, $selectedfield, $criteriaFieldName) {
1363 $url = CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl
);
1364 $row[$selectedfield . '_link'] = $url;
1365 $row[$selectedfield .
1366 '_hover'] = ts("%1 for this state.", array(1 => $value));
1368 $states = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
1369 if (!is_array($states)) {
1377 * @param string $fieldname
1381 function alterContactID($value, &$row, $fieldname) {
1382 $row[$fieldname . '_link'] = CRM_Utils_System
::url("civicrm/contact/view",
1383 'reset=1&cid=' . $value, $this->_absoluteUrl
);
1392 function alterParticipantStatus($value) {
1393 if (empty($value)) {
1396 return CRM_Event_PseudoConstant
::participantStatus($value, FALSE, 'label');
1404 function alterParticipantRole($value) {
1405 if (empty($value)) {
1408 $roles = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $value);
1410 foreach ($roles as $role) {
1411 $value[$role] = CRM_Event_PseudoConstant
::participantRole($role, FALSE);
1413 return implode(', ', $value);
1421 function alterPaymentType($value) {
1422 $paymentInstruments = CRM_Contribute_PseudoConstant
::paymentInstrument();
1423 return $paymentInstruments[$value];