From: eileen Date: Wed, 4 Jan 2017 02:46:49 +0000 (+1300) Subject: CRM-19815 extract soft credit fields for readability X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=686df921b8e149c32b7e542b43282c14757c216f;p=civicrm-core.git CRM-19815 extract soft credit fields for readability --- diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index e5f7c7b713..d0db6208da 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -157,80 +157,6 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { $query->_tables['civicrm_contribution'] = 1; } - // LCD 716 - $includeSoftCredits = self::isSoftCreditOptionEnabled($query->_params); - if (!empty($query->_returnProperties['contribution_soft_credit_name'])) { - if ($includeSoftCredits) { - $query->_select['contribution_soft_credit_name'] = "civicrm_contact_d.sort_name as contribution_soft_credit_name"; - // also include contact id. Will help build hyperlinks - $query->_select['contribution_soft_credit_contact_id'] = "civicrm_contact_d.id as contribution_soft_credit_contact_id"; - } - $query->_element['contribution_soft_credit_name'] = 1; - $query->_element['contribution_soft_credit_contact_id'] = 1; - - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['civicrm_contribution_soft'] = 1; - $query->_tables['civicrm_contribution_soft_contact'] = 1; - } - - if (!empty($query->_returnProperties['contribution_soft_credit_contact_id'])) { - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['civicrm_contribution_soft'] = 1; - $query->_tables['civicrm_contribution_soft_contact'] = 1; - } - - if (!empty($query->_returnProperties['contribution_soft_credit_amount'])) { - if ($includeSoftCredits) { - $query->_select['contribution_soft_credit_amount'] = "civicrm_contribution_soft.amount as contribution_soft_credit_amount"; - } - $query->_element['contribution_soft_credit_amount'] = 1; - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['civicrm_contribution_soft'] = 1; - } - - if (!empty($query->_returnProperties['contribution_soft_credit_type'])) { - if ($includeSoftCredits) { - $query->_select['contribution_soft_credit_type'] = "contribution_softcredit_type.label as contribution_soft_credit_type"; - } - $query->_element['contribution_soft_credit_type'] = 1; - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['contribution_softcredit_type'] = 1; - } - - if (!empty($query->_returnProperties['contribution_soft_credit_contribution_id'])) { - if ($includeSoftCredits) { - $query->_select['contribution_soft_credit_contribution_id'] = "civicrm_contribution_soft.contribution_id as contribution_soft_credit_contribution_id"; - } - $query->_element['contribution_soft_credit_contribution_id'] = 1; - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['civicrm_contribution_soft'] = 1; - } - - if (!empty($query->_returnProperties['contribution_soft_credit_email'])) { - $query->_select['contribution_soft_credit_email'] = "soft_email.email as contribution_soft_credit_email"; - $query->_element['contribution_soft_credit_email'] = 1; - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['civicrm_contribution_soft'] = 1; - $query->_tables['civicrm_contribution_soft_contact'] = 1; - $query->_tables['civicrm_contribution_soft_email'] = 1; - } - - if (!empty($query->_returnProperties['contribution_soft_credit_phone'])) { - $query->_select['contribution_soft_credit_email'] = "soft_phone.phone as contribution_soft_credit_phone"; - $query->_element['contribution_soft_credit_phone'] = 1; - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['civicrm_contribution_soft'] = 1; - $query->_tables['civicrm_contribution_soft_contact'] = 1; - $query->_tables['civicrm_contribution_soft_phone'] = 1; - } - - if (!empty($query->_returnProperties['contribution_soft_credit_pcp_id'])) { - $query->_select['contribution_soft_credit_pcp_id'] = "civicrm_contribution_soft.pcp_id as contribution_soft_credit_pcp_id"; - $query->_element['contribution_soft_credit_pcp_id'] = 1; - $query->_tables['civicrm_contribution'] = 1; - $query->_tables['civicrm_contribution_soft'] = 1; - } - if (!empty($query->_returnProperties['contribution_campaign_title'])) { $query->_select['contribution_campaign_title'] = "civicrm_campaign.title as contribution_campaign_title"; $query->_element['contribution_campaign_title'] = $query->_tables['civicrm_campaign'] = 1; @@ -251,6 +177,8 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { $query->_element['financial_type_id'] = $query->_tables['civicrm_contribution'] = 1; } // LCD 716 END + + self::addSoftCreditFields($query); } /** @@ -1207,4 +1135,86 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { return empty($errors) ? TRUE : $errors; } + /** + * Add the soft credit fields to the select fields. + * + * Extracted into separate function to improve readability of main select function. + * + * @param $query + */ + private static function addSoftCreditFields(&$query) { + $includeSoftCredits = self::isSoftCreditOptionEnabled($query->_params); + if (!empty($query->_returnProperties['contribution_soft_credit_name'])) { + if ($includeSoftCredits) { + $query->_select['contribution_soft_credit_name'] = "civicrm_contact_d.sort_name as contribution_soft_credit_name"; + // also include contact id. Will help build hyperlinks + $query->_select['contribution_soft_credit_contact_id'] = "civicrm_contact_d.id as contribution_soft_credit_contact_id"; + } + $query->_element['contribution_soft_credit_name'] = 1; + $query->_element['contribution_soft_credit_contact_id'] = 1; + + $query->_tables['civicrm_contribution'] = 1; + $query->_tables['civicrm_contribution_soft'] = 1; + $query->_tables['civicrm_contribution_soft_contact'] = 1; + } + + if (!empty($query->_returnProperties['contribution_soft_credit_contact_id'])) { + $query->_tables['civicrm_contribution'] = 1; + $query->_tables['civicrm_contribution_soft'] = 1; + $query->_tables['civicrm_contribution_soft_contact'] = 1; + } + + if (!empty($query->_returnProperties['contribution_soft_credit_amount'])) { + if ($includeSoftCredits) { + $query->_select['contribution_soft_credit_amount'] = "civicrm_contribution_soft.amount as contribution_soft_credit_amount"; + } + $query->_element['contribution_soft_credit_amount'] = 1; + $query->_tables['civicrm_contribution'] = 1; + $query->_tables['civicrm_contribution_soft'] = 1; + } + + if (!empty($query->_returnProperties['contribution_soft_credit_type'])) { + if ($includeSoftCredits) { + $query->_select['contribution_soft_credit_type'] = "contribution_softcredit_type.label as contribution_soft_credit_type"; + } + $query->_element['contribution_soft_credit_type'] = 1; + $query->_tables['civicrm_contribution'] = 1; + $query->_tables['contribution_softcredit_type'] = 1; + } + + if (!empty($query->_returnProperties['contribution_soft_credit_contribution_id'])) { + if ($includeSoftCredits) { + $query->_select['contribution_soft_credit_contribution_id'] = "civicrm_contribution_soft.contribution_id as contribution_soft_credit_contribution_id"; + } + $query->_element['contribution_soft_credit_contribution_id'] = 1; + $query->_tables['civicrm_contribution'] = 1; + $query->_tables['civicrm_contribution_soft'] = 1; + } + + if (!empty($query->_returnProperties['contribution_soft_credit_email'])) { + $query->_select['contribution_soft_credit_email'] = "soft_email.email as contribution_soft_credit_email"; + $query->_element['contribution_soft_credit_email'] = 1; + $query->_tables['civicrm_contribution'] = 1; + $query->_tables['civicrm_contribution_soft'] = 1; + $query->_tables['civicrm_contribution_soft_contact'] = 1; + $query->_tables['civicrm_contribution_soft_email'] = 1; + } + + if (!empty($query->_returnProperties['contribution_soft_credit_phone'])) { + $query->_select['contribution_soft_credit_email'] = "soft_phone.phone as contribution_soft_credit_phone"; + $query->_element['contribution_soft_credit_phone'] = 1; + $query->_tables['civicrm_contribution'] = 1; + $query->_tables['civicrm_contribution_soft'] = 1; + $query->_tables['civicrm_contribution_soft_contact'] = 1; + $query->_tables['civicrm_contribution_soft_phone'] = 1; + } + + if (!empty($query->_returnProperties['contribution_soft_credit_pcp_id'])) { + $query->_select['contribution_soft_credit_pcp_id'] = "civicrm_contribution_soft.pcp_id as contribution_soft_credit_pcp_id"; + $query->_element['contribution_soft_credit_pcp_id'] = 1; + $query->_tables['civicrm_contribution'] = 1; + $query->_tables['civicrm_contribution_soft'] = 1; + } + } + }