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';
48 public function __construct() {
49 parent
::__construct();
55 public function preProcess() {
62 public function select() {
68 * From clause build where baseTable & fromClauses are defined
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'];
79 if (strstr($this->_from
, 'civicrm_contact')) {
80 $this->_from
.= $this->_aclFrom
;
86 * Define any from clauses in use (child classes to override)
90 public function fromClauses() {
94 public function groupBy() {
96 //@todo - need to re-visit this - bad behaviour from pa
97 if ($this->_groupBy
== 'GROUP BY') {
98 $this->_groupBY
= NULL;
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";
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
);
110 public function orderBy() {
119 public function statistics(&$rows) {
120 return parent
::statistics($rows);
123 public function postProcess() {
124 if (!empty($this->_aclTable
) && !empty($this->_aliases
[$this->_aclTable
])) {
125 $this->buildACLClause($this->_aliases
[$this->_aclTable
]);
127 parent
::postProcess();
133 public function alterDisplay(&$rows) {
134 parent
::alterDisplay($rows);
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)) {
144 $selectedFields = array_keys($firstRow);
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)
153 $alterfunctions[$tablename . '_' .
154 $field] = $specs['alter_display'];
155 $altermap[$tablename . '_' . $field] = $field;
160 if (empty($alterfunctions)) {
161 // - no manipulation to be done
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]);
177 public function getLineItemColumns() {
179 'civicrm_line_item' => array(
180 'dao' => 'CRM_Price_BAO_LineItem',
183 'title' => ts('Quantity'),
184 'type' => CRM_Utils_Type
::T_INT
,
185 'statistics' => array('sum' => ts('Total Quantity Selected')),
187 'unit_price' => array(
188 'title' => ts('Unit Price'),
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')),
196 'participant_count' => array(
197 'title' => ts('Participant Count'),
198 'statistics' => array('sum' => ts('Total Participants')),
202 'title' => ts('Quantity'),
203 'type' => CRM_Utils_Type
::T_INT
,
204 'operator' => CRM_Report_Form
::OP_INT
,
207 'group_bys' => array(
208 'price_field_id' => array(
209 'title' => ts('Price Field'),
211 'price_field_value_id' => array(
212 'title' => ts('Price Field Option'),
214 'line_item_id' => array(
215 'title' => ts('Individual Line Item'),
226 public function getPriceFieldValueColumns() {
228 'civicrm_price_field_value' => array(
229 'dao' => 'CRM_Price_BAO_PriceFieldValue',
231 'price_field_value_label' => array(
232 'title' => ts('Price Field Value Label'),
237 'price_field_value_label' => array(
238 'title' => ts('Price Fields Value Label'),
239 'type' => CRM_Utils_Type
::T_STRING
,
240 'operator' => 'like',
244 'order_bys' => array(
246 'title' => ts('Price Field Value Label'),
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
254 'price_field_value_label' => array(
255 'title' => ts('Price Field Value Label'),
266 public function getPriceFieldColumns() {
268 'civicrm_price_field' => array(
269 'dao' => 'CRM_Price_BAO_PriceField',
271 'price_field_label' => array(
272 'title' => ts('Price Field Label'),
277 'price_field_label' => array(
278 'title' => ts('Price Field Label'),
279 'type' => CRM_Utils_Type
::T_STRING
,
280 'operator' => 'like',
284 'order_bys' => array(
285 'price_field_label' => array(
286 'title' => ts('Price Field Label'),
290 'group_bys' => array(
291 'price_field_label' => array(
292 'title' => ts('Price Field Label'),
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');
309 'civicrm_participant' => array(
310 'dao' => 'CRM_Event_DAO_Participant',
312 'participant_id' => array('title' => 'Participant ID'),
313 'participant_record' => array(
315 'title' => ts('Participant ID'),
318 'title' => ts('Event ID'),
319 'type' => CRM_Utils_Type
::T_STRING
,
320 'alter_display' => 'alterEventID',
322 'status_id' => array(
323 'title' => ts('Status'),
324 'alter_display' => 'alterParticipantStatus',
327 'title' => ts('Role'),
328 'alter_display' => 'alterParticipantRole',
330 'participant_fee_level' => NULL,
331 'participant_fee_amount' => NULL,
332 'participant_register_date' => array('title' => ts('Registration Date')),
334 'grouping' => 'event-fields',
337 'name' => 'event_id',
338 'title' => ts('Event'),
339 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
340 'options' => $_events['all'],
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'),
350 'title' => ts('Participant Role'),
351 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
352 'options' => CRM_Event_PseudoConstant
::participantRole(),
354 'participant_register_date' => array(
355 'title' => ' Registration Date',
356 'operatorType' => CRM_Report_Form
::OP_DATE
,
359 'order_bys' => array(
361 'title' => ts('Event'),
362 'default_weight' => '1',
363 'default_order' => 'ASC',
366 'group_bys' => array(
367 'event_id' => array('title' => ts('Event')),
376 public function getMembershipColumns() {
378 'civicrm_membership' => array(
379 'dao' => 'CRM_Member_DAO_Membership',
380 'grouping' => 'member-fields',
382 'membership_type_id' => array(
383 'title' => 'Membership Type',
385 'alter_display' => 'alterMembershipTypeID',
387 'status_id' => array(
388 'title' => 'Membership Status',
390 'alter_display' => 'alterMembershipStatusID',
393 'start_date' => array(
394 'title' => ts('Current Cycle Start Date'),
397 'title' => ts('Current Membership Cycle End Date'),
400 'group_bys' => array(
401 'membership_type_id' => array(
402 'title' => ts('Membership Type'),
406 'join_date' => array(
407 'type' => CRM_Utils_Type
::T_DATE
,
408 'operatorType' => CRM_Report_Form
::OP_DATE
,
418 public function getMembershipTypeColumns() {
420 'civicrm_membership_type' => array(
421 'dao' => 'CRM_Member_DAO_MembershipType',
422 'grouping' => 'member-fields',
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(),
439 public function getEventColumns() {
441 'civicrm_event' => array(
442 'dao' => 'CRM_Event_DAO_Event',
445 'no_display' => TRUE,
449 'title' => ts('Event Title'),
452 'event_type_id' => array(
453 'title' => ts('Event Type'),
455 'alter_display' => 'alterEventType',
457 'fee_label' => array('title' => ts('Fee Label')),
458 'event_start_date' => array(
459 'title' => ts('Event Start Date'),
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
,
467 'grouping' => 'event-fields',
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'),
475 'event_title' => array(
477 'title' => ts('Event Title'),
478 'operatorType' => CRM_Report_Form
::OP_STRING
,
481 'order_bys' => array(
482 'event_type_id' => array(
483 'title' => ts('Event Type'),
484 'default_weight' => '2',
485 'default_order' => 'ASC',
488 'group_bys' => array(
489 'event_type_id' => array(
490 'title' => ts('Event Type'),
500 public function getContributionColumns() {
502 'civicrm_contribution' => array(
503 'dao' => 'CRM_Contribute_DAO_Contribution',
505 'contribution_id' => array(
508 'financial_type_id' => array(
509 'title' => ts('Financial Type'),
511 'alter_display' => 'alterContributionType',
513 'payment_instrument_id' => array(
514 'title' => ts('Payment Instrument'),
515 'alter_display' => 'alterPaymentType',
517 'source' => array('title' => 'Contribution Source'),
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
,
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(),
536 'payment_instrument_id' => array(
537 'title' => ts('Payment Type'),
538 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
539 'options' => CRM_Contribute_PseudoConstant
::paymentInstrument(),
541 'contribution_status_id' => array(
542 'title' => ts('Contribution Status'),
543 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
544 'options' => CRM_Contribute_PseudoConstant
::contributionStatus(),
546 'total_amount' => array('title' => ts('Contribution Amount')),
548 'order_bys' => array(
549 'payment_instrument_id' => array(
550 'title' => ts('Payment Instrument'),
552 'financial_type_id' => array(
553 'title' => ts('Financial Type'),
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'),
563 'source' => array('title' => 'Contribution Source'),
565 'grouping' => 'contribution-fields',
573 public function getContactColumns() {
575 'civicrm_contact' => array(
576 'dao' => 'CRM_Contact_DAO_Contact',
578 'display_name' => array(
579 'title' => ts('Contact Name'),
582 'title' => ts('Contact ID'),
583 'alter_display' => 'alterContactID',
585 'first_name' => array(
586 'title' => ts('First Name'),
588 'last_name' => array(
589 'title' => ts('Last Name'),
591 'nick_name' => array(
592 'title' => ts('Nickname'),
593 'alter_display' => 'alterNickname',
598 'title' => ts('Contact ID'),
600 'sort_name' => array(
601 'title' => ts('Contact Name'),
604 'grouping' => 'contact-fields',
605 'order_bys' => array(
606 'sort_name' => array(
607 'title' => ts('Last Name, First Name'),
609 'default_weight' => '0',
610 'default_order' => 'ASC',
620 public function getCaseColumns() {
622 'civicrm_case' => array(
623 'dao' => 'CRM_Case_DAO_Case',
626 'title' => ts('Case ID'),
630 'title' => ts('Case Subject'),
633 'status_id' => array(
634 'title' => ts('Status'),
637 'case_type_id' => array(
638 'title' => ts('Case Type'),
641 'case_start_date' => array(
642 'title' => ts('Case Start Date'),
643 'name' => 'start_date',
646 'case_end_date' => array(
647 'title' => ts('Case End Date'),
648 'name' => 'end_date',
651 'case_duration' => array(
652 'name' => 'duration',
653 'title' => ts('Duration (Days)'),
656 'case_is_deleted' => array(
657 'name' => 'is_deleted',
658 'title' => ts('Case Deleted?'),
660 'type' => CRM_Utils_Type
::T_INT
,
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',
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',
676 'case_type_id' => array(
677 'title' => ts('Case Type'),
678 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
679 'options' => $this->case_types
,
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',
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
,
693 'name' => 'is_deleted',
701 * Get address columns to add to array
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
713 * address columns definition
715 public function getAddressColumns($options = array()) {
716 $defaultOptions = array(
718 'prefix_label' => '',
723 'country_id' => TRUE,
727 $options = array_merge($defaultOptions, $options);
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',
735 $options['prefix'] . 'name' => array(
736 'title' => ts($options['prefix_label'] . 'Address Name'),
737 'default' => CRM_Utils_Array
::value('name', $options['defaults'], FALSE),
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',
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',
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',
757 $options['prefix'] . 'street_number' => array(
758 'name' => 'street_number',
759 'title' => ts($options['prefix_label'] . 'Street Number'),
761 'default' => CRM_Utils_Array
::value('street_number', $options['defaults'], FALSE),
763 $options['prefix'] . 'street_name' => array(
764 'name' => 'street_name',
765 'title' => ts($options['prefix_label'] . 'Street Name'),
767 'default' => CRM_Utils_Array
::value('street_name', $options['defaults'], FALSE),
769 $options['prefix'] . 'street_unit' => array(
770 'name' => 'street_unit',
771 'title' => ts($options['prefix_label'] . 'Street Unit'),
773 'default' => CRM_Utils_Array
::value('street_unit', $options['defaults'], FALSE),
775 $options['prefix'] . 'city' => array(
776 'title' => ts($options['prefix_label'] . 'City'),
777 'default' => CRM_Utils_Array
::value('city', $options['defaults'], FALSE),
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',
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',
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',
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',
804 'grouping' => 'location-fields',
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'),
813 'name' => 'street_number',
815 $options['prefix'] . 'street_name' => array(
816 'title' => ts($options['prefix_label'] . 'Street Name'),
817 'name' => $options['prefix'] . 'street_name',
818 'operator' => 'like',
820 $options['prefix'] . 'postal_code' => array(
821 'title' => ts($options['prefix_label'] . 'Postal Code'),
823 'name' => 'postal_code',
825 $options['prefix'] . 'city' => array(
826 'title' => ts($options['prefix_label'] . 'City'),
827 'operator' => 'like',
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(),
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(),
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(),
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',
861 $options['prefix'] . 'street_number' => array(
862 'title' => ts($options['prefix_label'] . 'Odd / Even Street Number'),
863 'name' => 'street_number',
865 $options['prefix'] . 'street_address' => array(
866 'title' => ts($options['prefix_label'] . 'Street Address'),
867 'name' => 'street_address',
869 $options['prefix'] . 'city' => array(
870 'title' => ts($options['prefix_label'] . 'City'),
873 $options['prefix'] . 'postal_code' => array(
874 'title' => ts($options['prefix_label'] . 'Post Code'),
875 'name' => 'postal_code',
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',
886 $options['prefix'] . 'city' => array(
887 'title' => ts($options['prefix_label'] . 'City'),
890 $options['prefix'] . 'postal_code' => array(
891 'title' => ts($options['prefix_label'] . 'Post Code'),
892 'name' => 'postal_code',
894 $options['prefix'] . 'state_province_id' => array(
895 'title' => ts($options['prefix_label'] . 'State/Province'),
896 'name' => 'state_province_id',
898 $options['prefix'] . 'country_id' => array(
899 'title' => ts($options['prefix_label'] . 'Country'),
900 'name' => 'country_id',
902 $options['prefix'] . 'county_id' => array(
903 'title' => ts($options['prefix_label'] . 'County'),
904 'name' => 'county_id',
908 return $addressFields;
912 * Get Information about advertised Joins
916 public function getAvailableJoins() {
918 'priceFieldValue_from_lineItem' => array(
919 'leftTable' => 'civicrm_line_item',
920 'rightTable' => 'civicrm_price_field_value',
921 'callback' => 'joinPriceFieldValueFromLineItem',
923 'priceField_from_lineItem' => array(
924 'leftTable' => 'civicrm_line_item',
925 'rightTable' => 'civicrm_price_field',
926 'callback' => 'joinPriceFieldFromLineItem',
928 'participant_from_lineItem' => array(
929 'leftTable' => 'civicrm_line_item',
930 'rightTable' => 'civicrm_participant',
931 'callback' => 'joinParticipantFromLineItem',
933 'contribution_from_lineItem' => array(
934 'leftTable' => 'civicrm_line_item',
935 'rightTable' => 'civicrm_contribution',
936 'callback' => 'joinContributionFromLineItem',
938 'membership_from_lineItem' => array(
939 'leftTable' => 'civicrm_line_item',
940 'rightTable' => 'civicrm_membership',
941 'callback' => 'joinMembershipFromLineItem',
943 'contribution_from_participant' => array(
944 'leftTable' => 'civicrm_participant',
945 'rightTable' => 'civicrm_contribution',
946 'callback' => 'joinContributionFromParticipant',
948 'contribution_from_membership' => array(
949 'leftTable' => 'civicrm_membership',
950 'rightTable' => 'civicrm_contribution',
951 'callback' => 'joinContributionFromMembership',
953 'membership_from_contribution' => array(
954 'leftTable' => 'civicrm_contribution',
955 'rightTable' => 'civicrm_membership',
956 'callback' => 'joinMembershipFromContribution',
958 'membershipType_from_membership' => array(
959 'leftTable' => 'civicrm_membership',
960 'rightTable' => 'civicrm_membership_type',
961 'callback' => 'joinMembershipTypeFromMembership',
963 'lineItem_from_contribution' => array(
964 'leftTable' => 'civicrm_contribution',
965 'rightTable' => 'civicrm_line_item',
966 'callback' => 'joinLineItemFromContribution',
968 'lineItem_from_membership' => array(
969 'leftTable' => 'civicrm_membership',
970 'rightTable' => 'civicrm_line_item',
971 'callback' => 'joinLineItemFromMembership',
973 'contact_from_participant' => array(
974 'leftTable' => 'civicrm_participant',
975 'rightTable' => 'civicrm_contact',
976 'callback' => 'joinContactFromParticipant',
978 'contact_from_membership' => array(
979 'leftTable' => 'civicrm_membership',
980 'rightTable' => 'civicrm_contact',
981 'callback' => 'joinContactFromMembership',
983 'contact_from_contribution' => array(
984 'leftTable' => 'civicrm_contribution',
985 'rightTable' => 'civicrm_contact',
986 'callback' => 'joinContactFromContribution',
988 'event_from_participant' => array(
989 'leftTable' => 'civicrm_participant',
990 'rightTable' => 'civicrm_event',
991 'callback' => 'joinEventFromParticipant',
993 'address_from_contact' => array(
994 'leftTable' => 'civicrm_contact',
995 'rightTable' => 'civicrm_address',
996 'callback' => 'joinAddressFromContact',
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
1005 * @param string $prefix
1007 public function joinAddressFromContact($prefix = '') {
1008 $this->_from
.= " LEFT JOIN civicrm_address {$this->_aliases[$prefix .
1010 ON {$this->_aliases[$prefix .
1011 'civicrm_address']}.contact_id = {$this->_aliases[$prefix .
1012 'civicrm_contact']}.id";
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";
1020 public function joinPriceFieldFromLineItem() {
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
1028 * Define join from line item table to participant table
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')
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?
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
1053 * Define join from Participant to Contribution table
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
1064 * Define join from Membership to Contribution table
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
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";
1081 public function joinMembershipFromContribution() {
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";
1089 public function joinMembershipTypeFromMembership() {
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
1096 public function joinContributionFromLineItem() {
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')
1106 WHERE contribution_civireport_direct.id IS NOT NULL
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')
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
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')
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
1132 public function joinLineItemFromContribution() {
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
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
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
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
1166 public function joinLineItemFromMembership() {
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
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')
1177 WHERE line_item_civireport.id IS NOT NULL
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
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";
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";
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";
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)";
1215 * Retrieve text for financial type from pseudoconstant
1222 public function alterNickName($value, &$row) {
1223 if (empty($row['civicrm_contact_id'])) {
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>";
1233 * Retrieve text for contribution type from pseudoconstant
1238 * @return array|string
1240 public function alterContributionType($value, &$row) {
1241 return is_string(CRM_Contribute_PseudoConstant
::financialType($value, FALSE)) ? CRM_Contribute_PseudoConstant
::financialType($value, FALSE) : '';
1245 * Retrieve text for contribution status from pseudoconstant
1252 public function alterContributionStatus($value, &$row) {
1253 return CRM_Contribute_PseudoConstant
::contributionStatus($value);
1257 * Retrieve text for payment instrument from pseudoconstant
1264 public function alterEventType($value, &$row) {
1265 return CRM_Event_PseudoConstant
::eventType($value);
1272 * @return array|string
1274 public function alterEventID($value, &$row) {
1275 return is_string(CRM_Event_PseudoConstant
::event($value, FALSE)) ? CRM_Event_PseudoConstant
::event($value, FALSE) : '';
1282 * @return array|string
1284 public function alterMembershipTypeID($value, &$row) {
1285 return is_string(CRM_Member_PseudoConstant
::membershipType($value, FALSE)) ? CRM_Member_PseudoConstant
::membershipType($value, FALSE) : '';
1292 * @return array|string
1294 public function alterMembershipStatusID($value, &$row) {
1295 return is_string(CRM_Member_PseudoConstant
::membershipStatus($value, FALSE)) ? CRM_Member_PseudoConstant
::membershipStatus($value, FALSE) : '';
1301 * @param $selectedfield
1302 * @param string $criteriaFieldName
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)) {
1320 * @param $selectedfield
1321 * @param string $criteriaFieldName
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)) {
1339 * @param $selectedfield
1340 * @param string $criteriaFieldName
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));
1350 $states = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
1351 if (!is_array($states)) {
1359 * @param string $fieldname
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
);
1374 public function alterParticipantStatus($value) {
1375 if (empty($value)) {
1378 return CRM_Event_PseudoConstant
::participantStatus($value, FALSE, 'label');
1384 * @return string|void
1386 public function alterParticipantRole($value) {
1387 if (empty($value)) {
1390 $roles = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $value);
1392 foreach ($roles as $role) {
1393 $value[$role] = CRM_Event_PseudoConstant
::participantRole($role, FALSE);
1395 return implode(', ', $value);
1403 public function alterPaymentType($value) {
1404 $paymentInstruments = CRM_Contribute_PseudoConstant
::paymentInstrument();
1405 return $paymentInstruments[$value];