From 850e464042607a2efc3382862a2aebb33b2aaa80 Mon Sep 17 00:00:00 2001 From: Eileen Date: Sun, 19 May 2013 19:47:16 -0400 Subject: [PATCH] CRM-12659 add phone fields to pledge detail report. Also make inclusion of phone join conditional in Contribution detail report --- CRM/Report/Form.php | 76 ++++++++++++++++++++++++++- CRM/Report/Form/Contribute/Detail.php | 5 +- CRM/Report/Form/Pledge/Detail.php | 28 ++++------ 3 files changed, 87 insertions(+), 22 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 361e2bc6fa..c34e864072 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -2966,7 +2966,10 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a return $this->_selectedTables; } - /* + /** + * @deprecated - use getAddressColumns which is a more accurate description + * and also accepts an array of options rather than a long list + * * function for adding address fields to construct function in reports * @param bool $groupBy Add GroupBy? Not appropriate for detail report * @param bool $orderBy Add GroupBy? Not appropriate for detail report @@ -3206,6 +3209,77 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a } } + /** + * Add Phone into From Table if required + */ + function addPhoneFromClause() { + // include address field if address column is to be included + if ($this->isTableSelected('civicrm_phone') + ) { + $this->_from .= " + LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} + ON ({$this->_aliases['civicrm_contact']}.id = + {$this->_aliases['civicrm_phone']}.contact_id) AND + {$this->_aliases['civicrm_phone']}.is_primary = 1\n"; + } + } + + /** + * Get phone columns to add to array + * @param array $options + * - prefix Prefix to add to table (in case of more than one instance of the table) + * - prefix_label Label to give columns from this phone table instance + * @return array phone columns definition + */ + function getPhoneColumns($options = array()){ + $defaultOptions = array( + 'prefix' => '', + 'prefix_label' => '', + ); + + $options = array_merge($defaultOptions,$options); + + $fields = array( + $options['prefix'] . 'civicrm_phone' => array( + 'dao' => 'CRM_Core_DAO_Phone', + 'fields' => array( + $options['prefix'] . 'phone' => array( + 'title' => ts($options['prefix_label'] . 'Phone'), + 'name' => 'phone' + ), + ), + ), + ); + return $fields; + } + + /** + * Get address columns to add to array + * @param array $options + * - prefix Prefix to add to table (in case of more than one instance of the table) + * - prefix_label Label to give columns from this address table instance + * @return array address columns definition + */ + function getAddressColumns($options = array()){ + $defaultOptions = array( + 'prefix' => '', + 'prefix_label' => '', + 'group_by' => TRUE, + 'order_by' => TRUE, + 'filters' => TRUE, + 'defaults' => array( + ), + ); + $options = array_merge($defaultOptions,$options); + return $this->addAddressFields( + $options['group_by'], + $options['order_by'], + $options['filters'], + $options['defaults'] + ); + + } + function add2group($groupID) { if (is_numeric($groupID) && isset($this->_aliases['civicrm_contact'])) { $select = "SELECT DISTINCT {$this->_aliases['civicrm_contact']}.id AS addtogroup_contact_id, "; diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index 782b57729f..f6e5f5bbd2 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -466,10 +466,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form { ON {$this->_aliases['civicrm_contribution_ordinality']}.id = {$this->_aliases['civicrm_contribution']}.id"; } - $this->_from .= " - LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} - ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND - {$this->_aliases['civicrm_phone']}.is_primary = 1)"; + $this->addPhoneFromClause(); if ($this->_addressField OR (!empty($this->_params['state_province_id_value']) OR !empty($this->_params['country_id_value']))) { $this->_from .= " diff --git a/CRM/Report/Form/Pledge/Detail.php b/CRM/Report/Form/Pledge/Detail.php index c8a9374b8e..c3f9ebface 100644 --- a/CRM/Report/Form/Pledge/Detail.php +++ b/CRM/Report/Form/Pledge/Detail.php @@ -27,7 +27,7 @@ +--------------------------------------------------------------------+ */ - + /* * !!!!!!!!!!!!!!!!!!!! * NB: this is named detail but behaves like a summary report. @@ -54,7 +54,7 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { 'Individual' ); function __construct() { - + // Check if CiviCampaign is a) enabled and b) has active campaigns $config = CRM_Core_Config::singleton(); $campaignEnabled = in_array("CiviCampaign", $config->enableComponents); @@ -167,7 +167,7 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('contribution_status'), ), - + ), ), 'civicrm_pledge_payment' => @@ -186,7 +186,7 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { 'default' => TRUE, 'type' => CRM_Utils_Type::T_MONEY, ), - + ), ), 'civicrm_group' => @@ -204,9 +204,10 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { 'options' => CRM_Core_PseudoConstant::group(), ), ), - ), - ) + $this->addAddressFields(FALSE, FALSE); - + ) + ) + + $this->getAddressColumns(array('group_by' => FALSE)) + + $this->getPhoneColumns(); // If we have a campaign, build out the relevant elements $this->_tagFilter = TRUE; if ($campaignEnabled && !empty($this->activeCampaigns)) { @@ -280,15 +281,8 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { "; } - // include address field if address column is to be included - if ($this->_addressField) { - $this->_from .= " - LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} - ON ({$this->_aliases['civicrm_contact']}.id = - {$this->_aliases['civicrm_address']}.contact_id) AND - {$this->_aliases['civicrm_address']}.is_primary = 1\n"; - } - + $this->addPhoneFromClause(); + $this->addAddressFromClause(); // include email field if email column is to be included if ($this->_emailField) { $this->_from .= " @@ -319,7 +313,7 @@ class CRM_Report_Form_Pledge_Detail extends CRM_Report_Form { while ($dao->fetch()) { $totalAmount[] = CRM_Utils_Money::format($dao->amount, $dao->currency)."(".$dao->count.")"; $average[] = CRM_Utils_Money::format($dao->avg, $dao->currency); - $count += $dao->count; + $count += $dao->count; } $statistics['counts']['amount'] = array( -- 2.25.1