3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 public function __construct() {
52 parent
::__construct();
55 public function preProcess() {
59 public function select() {
65 * From clause build where baseTable & fromClauses are defined
67 public function from() {
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 public function fromClauses() {
92 public function groupBy() {
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
);
108 public function orderBy() {
117 public function statistics(&$rows) {
118 return parent
::statistics($rows);
121 public function postProcess() {
122 if (!empty($this->_aclTable
) && !empty($this->_aliases
[$this->_aclTable
])) {
123 $this->buildACLClause($this->_aliases
[$this->_aclTable
]);
125 parent
::postProcess();
131 public 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 public 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 public 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 public 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 public 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 public 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 public 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 public 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 public 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 public 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 public 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
702 * Options for the report.
703 * - prefix prefix to add (e.g. 'honor' when getting address details for honor contact
704 * - prefix_label optional prefix lable eg. "Honoree " for front end
705 * - group_by enable these fields for group by - default false
706 * - order_by enable these fields for order by
707 * - filters enable these fields for filtering
708 * - defaults - (is this working?) values to pre-populate
709 * @return array address fields for construct clause
712 * Get address columns to add to array
714 * @param array $options
715 * - prefix Prefix to add to table (in case of more than one instance of the table)
716 * - prefix_label Label to give columns from this address table instance
718 * @return array address columns definition
721 * @param array $options
725 public function getAddressColumns($options = array()) {
726 $defaultOptions = array(
728 'prefix_label' => '',
737 $options = array_merge($defaultOptions, $options);
739 $addressFields = array(
740 $options['prefix'] . 'civicrm_address' => array(
741 'dao' => 'CRM_Core_DAO_Address',
742 'name' => 'civicrm_address',
743 'alias' => $options['prefix'] . 'civicrm_address',
745 $options['prefix'] . 'name' => array(
746 'title' => ts($options['prefix_label'] . 'Address Name'),
747 'default' => CRM_Utils_Array
::value('name', $options['defaults'], FALSE),
750 $options['prefix'] . 'street_address' => array(
751 'title' => ts($options['prefix_label'] . 'Street Address'),
752 'default' => CRM_Utils_Array
::value('street_address', $options['defaults'], FALSE),
753 'name' => 'street_address',
755 $options['prefix'] . 'supplemental_address_1' => array(
756 'title' => ts($options['prefix_label'] .
757 'Supplementary Address Field 1'),
758 'default' => CRM_Utils_Array
::value('supplemental_address_1', $options['defaults'], FALSE),
759 'name' => 'supplemental_address_1',
761 $options['prefix'] . 'supplemental_address_2' => array(
762 'title' => ts($options['prefix_label'] .
763 'Supplementary Address Field 2'),
764 'default' => CRM_Utils_Array
::value('supplemental_address_2', $options['defaults'], FALSE),
765 'name' => 'supplemental_address_2',
767 $options['prefix'] . 'street_number' => array(
768 'name' => 'street_number',
769 'title' => ts($options['prefix_label'] . 'Street Number'),
771 'default' => CRM_Utils_Array
::value('street_number', $options['defaults'], FALSE),
772 'name' => 'street_number',
774 $options['prefix'] . 'street_name' => array(
775 'name' => 'street_name',
776 'title' => ts($options['prefix_label'] . 'Street Name'),
778 'default' => CRM_Utils_Array
::value('street_name', $options['defaults'], FALSE),
779 'name' => 'street_name',
781 $options['prefix'] . 'street_unit' => array(
782 'name' => 'street_unit',
783 'title' => ts($options['prefix_label'] . 'Street Unit'),
785 'default' => CRM_Utils_Array
::value('street_unit', $options['defaults'], FALSE),
786 'name' => 'street_unit',
788 $options['prefix'] . 'city' => array(
789 'title' => ts($options['prefix_label'] . 'City'),
790 'default' => CRM_Utils_Array
::value('city', $options['defaults'], FALSE),
793 $options['prefix'] . 'postal_code' => array(
794 'title' => ts($options['prefix_label'] . 'Postal Code'),
795 'default' => CRM_Utils_Array
::value('postal_code', $options['defaults'], FALSE),
796 'name' => 'postal_code',
798 $options['prefix'] . 'county_id' => array(
799 'title' => ts($options['prefix_label'] . 'County'),
800 'default' => CRM_Utils_Array
::value('county_id', $options['defaults'], FALSE),
801 'alter_display' => 'alterCountyID',
802 'name' => 'county_id',
804 $options['prefix'] . 'state_province_id' => array(
805 'title' => ts($options['prefix_label'] . 'State/Province'),
806 'default' => CRM_Utils_Array
::value('state_province_id', $options['defaults'], FALSE),
807 'alter_display' => 'alterStateProvinceID',
808 'name' => 'state_province_id',
810 $options['prefix'] . 'country_id' => array(
811 'title' => ts($options['prefix_label'] . 'Country'),
812 'default' => CRM_Utils_Array
::value('country_id', $options['defaults'], FALSE),
813 'alter_display' => 'alterCountryID',
814 'name' => 'country_id',
817 'grouping' => 'location-fields',
821 if ($options['filters']) {
822 $addressFields[$options['prefix'] . 'civicrm_address']['filters'] = array(
823 $options['prefix'] . 'street_number' => array(
824 'title' => ts($options['prefix_label'] . 'Street Number'),
826 'name' => 'street_number',
828 $options['prefix'] . 'street_name' => array(
829 'title' => ts($options['prefix_label'] . 'Street Name'),
830 'name' => $options['prefix'] . 'street_name',
831 'operator' => 'like',
833 $options['prefix'] . 'postal_code' => array(
834 'title' => ts($options['prefix_label'] . 'Postal Code'),
836 'name' => 'postal_code',
838 $options['prefix'] . 'city' => array(
839 'title' => ts($options['prefix_label'] . 'City'),
840 'operator' => 'like',
843 $options['prefix'] . 'county_id' => array(
844 'name' => 'county_id',
845 'title' => ts($options['prefix_label'] . 'County'),
846 'type' => CRM_Utils_Type
::T_INT
,
847 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
848 'options' => CRM_Core_PseudoConstant
::county(),
850 $options['prefix'] . 'state_province_id' => array(
851 'name' => 'state_province_id',
852 'title' => ts($options['prefix_label'] . 'State/Province'),
853 'type' => CRM_Utils_Type
::T_INT
,
854 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
855 'options' => CRM_Core_PseudoConstant
::stateProvince(),
857 $options['prefix'] . 'country_id' => array(
858 'name' => 'country_id',
859 'title' => ts($options['prefix_label'] . 'Country'),
860 'type' => CRM_Utils_Type
::T_INT
,
861 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
862 'options' => CRM_Core_PseudoConstant
::country(),
867 if ($options['order_by']) {
868 $addressFields[$options['prefix'] .
869 'civicrm_address']['order_bys'] = array(
870 $options['prefix'] . 'street_name' => array(
871 'title' => ts($options['prefix_label'] . 'Street Name'),
872 'name' => 'street_name',
874 $options['prefix'] . 'street_number' => array(
875 'title' => ts($options['prefix_label'] . 'Odd / Even Street Number'),
876 'name' => 'street_number',
878 $options['prefix'] . 'street_address' => array(
879 'title' => ts($options['prefix_label'] . 'Street Address'),
880 'name' => 'street_address',
882 $options['prefix'] . 'city' => array(
883 'title' => ts($options['prefix_label'] . 'City'),
886 $options['prefix'] . 'postal_code' => array(
887 'title' => ts($options['prefix_label'] . 'Post Code'),
888 'name' => 'postal_code',
893 if ($options['group_by']) {
894 $addressFields['civicrm_address']['group_bys'] = array(
895 $options['prefix'] . 'street_address' => array(
896 'title' => ts($options['prefix_label'] . 'Street Address'),
897 'name' => 'street_address',
899 $options['prefix'] . 'city' => array(
900 'title' => ts($options['prefix_label'] . 'City'),
903 $options['prefix'] . 'postal_code' => array(
904 'title' => ts($options['prefix_label'] . 'Post Code'),
905 'name' => 'postal_code',
907 $options['prefix'] . 'state_province_id' => array(
908 'title' => ts($options['prefix_label'] . 'State/Province'),
909 'name' => 'state_province_id',
911 $options['prefix'] . 'country_id' => array(
912 'title' => ts($options['prefix_label'] . 'Country'),
913 'name' => 'country_id',
915 $options['prefix'] . 'county_id' => array(
916 'title' => ts($options['prefix_label'] . 'County'),
917 'name' => 'county_id',
921 return $addressFields;
925 * Get Information about advertised Joins
930 public function getAvailableJoins() {
932 'priceFieldValue_from_lineItem' => array(
933 'leftTable' => 'civicrm_line_item',
934 'rightTable' => 'civicrm_price_field_value',
935 'callback' => 'joinPriceFieldValueFromLineItem',
937 'priceField_from_lineItem' => array(
938 'leftTable' => 'civicrm_line_item',
939 'rightTable' => 'civicrm_price_field',
940 'callback' => 'joinPriceFieldFromLineItem',
942 'participant_from_lineItem' => array(
943 'leftTable' => 'civicrm_line_item',
944 'rightTable' => 'civicrm_participant',
945 'callback' => 'joinParticipantFromLineItem',
947 'contribution_from_lineItem' => array(
948 'leftTable' => 'civicrm_line_item',
949 'rightTable' => 'civicrm_contribution',
950 'callback' => 'joinContributionFromLineItem',
952 'membership_from_lineItem' => array(
953 'leftTable' => 'civicrm_line_item',
954 'rightTable' => 'civicrm_membership',
955 'callback' => 'joinMembershipFromLineItem',
957 'contribution_from_participant' => array(
958 'leftTable' => 'civicrm_participant',
959 'rightTable' => 'civicrm_contribution',
960 'callback' => 'joinContributionFromParticipant',
962 'contribution_from_membership' => array(
963 'leftTable' => 'civicrm_membership',
964 'rightTable' => 'civicrm_contribution',
965 'callback' => 'joinContributionFromMembership',
967 'membership_from_contribution' => array(
968 'leftTable' => 'civicrm_contribution',
969 'rightTable' => 'civicrm_membership',
970 'callback' => 'joinMembershipFromContribution',
972 'membershipType_from_membership' => array(
973 'leftTable' => 'civicrm_membership',
974 'rightTable' => 'civicrm_membership_type',
975 'callback' => 'joinMembershipTypeFromMembership',
977 'lineItem_from_contribution' => array(
978 'leftTable' => 'civicrm_contribution',
979 'rightTable' => 'civicrm_line_item',
980 'callback' => 'joinLineItemFromContribution',
982 'lineItem_from_membership' => array(
983 'leftTable' => 'civicrm_membership',
984 'rightTable' => 'civicrm_line_item',
985 'callback' => 'joinLineItemFromMembership',
987 'contact_from_participant' => array(
988 'leftTable' => 'civicrm_participant',
989 'rightTable' => 'civicrm_contact',
990 'callback' => 'joinContactFromParticipant',
992 'contact_from_membership' => array(
993 'leftTable' => 'civicrm_membership',
994 'rightTable' => 'civicrm_contact',
995 'callback' => 'joinContactFromMembership',
997 'contact_from_contribution' => array(
998 'leftTable' => 'civicrm_contribution',
999 'rightTable' => 'civicrm_contact',
1000 'callback' => 'joinContactFromContribution',
1002 'event_from_participant' => array(
1003 'leftTable' => 'civicrm_participant',
1004 'rightTable' => 'civicrm_event',
1005 'callback' => 'joinEventFromParticipant',
1007 'address_from_contact' => array(
1008 'leftTable' => 'civicrm_contact',
1009 'rightTable' => 'civicrm_address',
1010 'callback' => 'joinAddressFromContact',
1016 * Add join from contact table to address. Prefix will be added to both tables
1017 * as it's assumed you are using it to get address of a secondary contact
1020 * @param string $prefix
1022 public function joinAddressFromContact($prefix = '') {
1023 $this->_from
.= " LEFT JOIN civicrm_address {$this->_aliases[$prefix .
1025 ON {$this->_aliases[$prefix .
1026 'civicrm_address']}.contact_id = {$this->_aliases[$prefix .
1027 'civicrm_contact']}.id";
1030 public function joinPriceFieldValueFromLineItem() {
1031 $this->_from
.= " LEFT JOIN civicrm_price_field_value {$this->_aliases['civicrm_price_field_value']}
1032 ON {$this->_aliases['civicrm_line_item']}.price_field_value_id = {$this->_aliases['civicrm_price_field_value']}.id";
1035 public function joinPriceFieldFromLineItem() {
1037 LEFT JOIN civicrm_price_field {$this->_aliases['civicrm_price_field']}
1038 ON {$this->_aliases['civicrm_line_item']}.price_field_id = {$this->_aliases['civicrm_price_field']}.id
1043 * Define join from line item table to participant table
1045 public function joinParticipantFromLineItem() {
1046 $this->_from
.= " LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
1047 ON ( {$this->_aliases['civicrm_line_item']}.entity_id = {$this->_aliases['civicrm_participant']}.id
1048 AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_participant')
1053 * Define join from line item table to Membership table. Seems to be still via contribution
1054 * as the entity. Have made 'inner' to restrict does that make sense?
1056 public function joinMembershipFromLineItem() {
1057 $this->_from
.= " INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
1058 ON ( {$this->_aliases['civicrm_line_item']}.entity_id = {$this->_aliases['civicrm_contribution']}.id
1059 AND {$this->_aliases['civicrm_line_item']}.entity_table = 'civicrm_contribution')
1060 LEFT JOIN civicrm_membership_payment pp
1061 ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id
1062 LEFT JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
1063 ON pp.membership_id = {$this->_aliases['civicrm_membership']}.id
1068 * Define join from Participant to Contribution table
1070 public function joinContributionFromParticipant() {
1071 $this->_from
.= " LEFT JOIN civicrm_participant_payment pp
1072 ON {$this->_aliases['civicrm_participant']}.id = pp.participant_id
1073 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
1074 ON pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id
1079 * Define join from Membership to Contribution table
1081 public function joinContributionFromMembership() {
1082 $this->_from
.= " LEFT JOIN civicrm_membership_payment pp
1083 ON {$this->_aliases['civicrm_membership']}.id = pp.membership_id
1084 LEFT JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
1085 ON pp.contribution_id = {$this->_aliases['civicrm_contribution']}.id
1089 public function joinParticipantFromContribution() {
1090 $this->_from
.= " LEFT JOIN civicrm_participant_payment pp
1091 ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id
1092 LEFT JOIN civicrm_participant {$this->_aliases['civicrm_participant']}
1093 ON pp.participant_id = {$this->_aliases['civicrm_participant']}.id";
1096 public function joinMembershipFromContribution() {
1098 LEFT JOIN civicrm_membership_payment pp
1099 ON {$this->_aliases['civicrm_contribution']}.id = pp.contribution_id
1100 LEFT JOIN civicrm_membership {$this->_aliases['civicrm_membership']}
1101 ON pp.membership_id = {$this->_aliases['civicrm_membership']}.id";
1104 public function joinMembershipTypeFromMembership() {
1106 LEFT JOIN civicrm_membership_type {$this->_aliases['civicrm_membership_type']}
1107 ON {$this->_aliases['civicrm_membership']}.membership_type_id = {$this->_aliases['civicrm_membership_type']}.id
1111 public function joinContributionFromLineItem() {
1113 // this can be stored as a temp table & indexed for more speed. Not done at this state.
1114 // 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
1115 $this->_from
.= " LEFT JOIN (SELECT line_item_civireport.id as lid, contribution_civireport_direct.*
1116 FROM civicrm_line_item line_item_civireport
1117 LEFT JOIN civicrm_contribution contribution_civireport_direct
1118 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')
1121 WHERE contribution_civireport_direct.id IS NOT NULL
1123 UNION SELECT line_item_civireport.id as lid, contribution_civireport.*
1124 FROM civicrm_line_item line_item_civireport
1125 LEFT JOIN civicrm_participant participant_civireport
1126 ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id = participant_civireport.id AND line_item_civireport.entity_table = 'civicrm_participant')
1128 LEFT JOIN civicrm_participant_payment pp
1129 ON participant_civireport.id = pp.participant_id
1130 LEFT JOIN civicrm_contribution contribution_civireport
1131 ON pp.contribution_id = contribution_civireport.id
1133 UNION SELECT line_item_civireport.id as lid,contribution_civireport.*
1134 FROM civicrm_line_item line_item_civireport
1135 LEFT JOIN civicrm_membership membership_civireport
1136 ON (line_item_civireport.line_total > 0 AND line_item_civireport.entity_id =membership_civireport.id AND line_item_civireport.entity_table = 'civicrm_membership')
1138 LEFT JOIN civicrm_membership_payment pp
1139 ON membership_civireport.id = pp.membership_id
1140 LEFT JOIN civicrm_contribution contribution_civireport
1141 ON pp.contribution_id = contribution_civireport.id
1142 ) as {$this->_aliases['civicrm_contribution']}
1143 ON {$this->_aliases['civicrm_contribution']}.lid = {$this->_aliases['civicrm_line_item']}.id
1147 public function joinLineItemFromContribution() {
1149 // this can be stored as a temp table & indexed for more speed. Not done at this stage.
1150 // 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
1153 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1154 FROM civicrm_contribution contribution_civireport_direct
1155 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')
1156 WHERE line_item_civireport.id IS NOT NULL
1159 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1160 FROM civicrm_contribution contribution_civireport_direct
1161 LEFT JOIN civicrm_participant_payment pp ON contribution_civireport_direct.id = pp.contribution_id
1162 LEFT JOIN civicrm_participant p ON pp.participant_id = p.id
1163 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')
1164 WHERE line_item_civireport.id IS NOT NULL
1168 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1169 FROM civicrm_contribution contribution_civireport_direct
1170 LEFT JOIN civicrm_membership_payment pp ON contribution_civireport_direct.id = pp.contribution_id
1171 LEFT JOIN civicrm_membership p ON pp.membership_id = p.id
1172 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')
1173 WHERE line_item_civireport.id IS NOT NULL
1174 ) as {$this->_aliases['civicrm_line_item']}
1175 ON {$this->_aliases['civicrm_line_item']}.contid = {$this->_aliases['civicrm_contribution']}.id
1181 public function joinLineItemFromMembership() {
1183 // this can be stored as a temp table & indexed for more speed. Not done at this stage.
1184 // 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
1187 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1188 FROM civicrm_contribution contribution_civireport_direct
1189 LEFT JOIN civicrm_line_item line_item_civireport
1190 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')
1192 WHERE line_item_civireport.id IS NOT NULL
1196 SELECT contribution_civireport_direct.id AS contid, line_item_civireport.*
1197 FROM civicrm_contribution contribution_civireport_direct
1198 LEFT JOIN civicrm_membership_payment pp ON contribution_civireport_direct.id = pp.contribution_id
1199 LEFT JOIN civicrm_membership p ON pp.membership_id = p.id
1200 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')
1201 WHERE line_item_civireport.id IS NOT NULL
1202 ) as {$this->_aliases['civicrm_line_item']}
1203 ON {$this->_aliases['civicrm_line_item']}.contid = {$this->_aliases['civicrm_contribution']}.id
1207 public function joinContactFromParticipant() {
1208 $this->_from
.= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
1209 ON {$this->_aliases['civicrm_participant']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
1212 public function joinContactFromMembership() {
1213 $this->_from
.= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
1214 ON {$this->_aliases['civicrm_membership']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
1217 public function joinContactFromContribution() {
1218 $this->_from
.= " LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
1219 ON {$this->_aliases['civicrm_contribution']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
1222 public function joinEventFromParticipant() {
1223 $this->_from
.= " LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
1224 ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND
1225 ({$this->_aliases['civicrm_event']}.is_template IS NULL OR
1226 {$this->_aliases['civicrm_event']}.is_template = 0)";
1230 * Retrieve text for financial type from pseudoconstant
1238 public function alterNickName($value, &$row) {
1239 if (empty($row['civicrm_contact_id'])) {
1242 $contactID = $row['civicrm_contact_id'];
1243 return "<div id=contact-{$contactID} class='crm-entity'>
1244 <span class='crm-editable crmf-nick_name crm-editable-enabled' data-action='create'>
1245 " . $value . "</span></div>";
1249 * Retrieve text for contribution type from pseudoconstant
1255 * @return array|string
1257 public function alterContributionType($value, &$row) {
1258 return is_string(CRM_Contribute_PseudoConstant
::financialType($value, FALSE)) ? CRM_Contribute_PseudoConstant
::financialType($value, FALSE) : '';
1262 * Retrieve text for contribution status from pseudoconstant
1270 public function alterContributionStatus($value, &$row) {
1271 return CRM_Contribute_PseudoConstant
::contributionStatus($value);
1275 * Retrieve text for payment instrument from pseudoconstant
1283 public function alterEventType($value, &$row) {
1284 return CRM_Event_PseudoConstant
::eventType($value);
1291 * @return array|string
1293 public function alterEventID($value, &$row) {
1294 return is_string(CRM_Event_PseudoConstant
::event($value, FALSE)) ? CRM_Event_PseudoConstant
::event($value, FALSE) : '';
1301 * @return array|string
1303 public function alterMembershipTypeID($value, &$row) {
1304 return is_string(CRM_Member_PseudoConstant
::membershipType($value, FALSE)) ? CRM_Member_PseudoConstant
::membershipType($value, FALSE) : '';
1311 * @return array|string
1313 public function alterMembershipStatusID($value, &$row) {
1314 return is_string(CRM_Member_PseudoConstant
::membershipStatus($value, FALSE)) ? CRM_Member_PseudoConstant
::membershipStatus($value, FALSE) : '';
1320 * @param $selectedfield
1321 * @param string $criteriaFieldName
1325 public function alterCountryID($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 country.", array(1 => $value));
1330 $countries = CRM_Core_PseudoConstant
::country($value, FALSE);
1331 if (!is_array($countries)) {
1339 * @param $selectedfield
1340 * @param string $criteriaFieldName
1344 public function alterCountyID($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 county.", array(1 => $value));
1349 $counties = CRM_Core_PseudoConstant
::county($value, FALSE);
1350 if (!is_array($counties)) {
1358 * @param $selectedfield
1359 * @param string $criteriaFieldName
1363 public function alterStateProvinceID($value, &$row, $selectedfield, $criteriaFieldName) {
1364 $url = CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl
);
1365 $row[$selectedfield . '_link'] = $url;
1366 $row[$selectedfield .
1367 '_hover'] = ts("%1 for this state.", array(1 => $value));
1369 $states = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
1370 if (!is_array($states)) {
1378 * @param string $fieldname
1382 public function alterContactID($value, &$row, $fieldname) {
1383 $row[$fieldname . '_link'] = CRM_Utils_System
::url("civicrm/contact/view",
1384 'reset=1&cid=' . $value, $this->_absoluteUrl
);
1393 public function alterParticipantStatus($value) {
1394 if (empty($value)) {
1397 return CRM_Event_PseudoConstant
::participantStatus($value, FALSE, 'label');
1405 public function alterParticipantRole($value) {
1406 if (empty($value)) {
1409 $roles = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $value);
1411 foreach ($roles as $role) {
1412 $value[$role] = CRM_Event_PseudoConstant
::participantRole($role, FALSE);
1414 return implode(', ', $value);
1422 public function alterPaymentType($value) {
1423 $paymentInstruments = CRM_Contribute_PseudoConstant
::paymentInstrument();
1424 return $paymentInstruments[$value];