From c7940124e4599b93915192005b450c4ccc9b7c53 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 10 Dec 2015 16:28:18 +1300 Subject: [PATCH] CRM-17691 do not use default return properties from search screen Change-Id: Ic6b3d7a2ac2b0ca691ed9fdb84a1ff86f6c73e52 Change-Id: Ib275a710fceceba2e10d0293dc3366c1f37d3397 --- CRM/Contribute/BAO/Contribution.php | 2 +- CRM/Contribute/BAO/Query.php | 40 ++++++++++++++++++++++++++++- CRM/Contribute/Selector/Search.php | 5 +--- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 79bebb63b6..fb59766956 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1354,7 +1354,7 @@ LEFT JOIN civicrm_option_value contribution_status ON (civicrm_contribution.cont {$additionalClause} "; - $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); + $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $paymentDetails[$dao->id] = array( diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index c9597e8fca..60547162ee 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -851,7 +851,45 @@ class CRM_Contribute_BAO_Query { } /** - * @param $mode + * Get the list of fields required to populate the selector. + * + * The default return properties array returns far too many fields for 'everyday use. Every field you add to this array + * kills a small kitten so add carefully. + */ + public static function selectorReturnProperties() { + return array( + 'contact_type' => 1, + 'contact_sub_type' => 1, + 'sort_name' => 1, + 'financial_type' => 1, + 'contribution_source' => 1, + 'is_test' => 1, + 'receive_date' => 1, + 'is_pay_later' => 1, + 'thankyou_date' => 1, + 'total_amount' => 1, + 'contribution_status_id' => 1, + // @todo return this & fix query to do pseudoconstant thing. + 'contribution_status' => 1, + // @todo the product field got added because it suited someone's use case. + // ideally we would have some configurability here because I think 90% of sites would + // disagree this is the right field to show - but they wouldn't agree with each other + // on what field to show instead. + 'contribution_product_id' => 1, + 'product_name' => 1, + ); + } + + /** + * Function you should avoid. + * + * This function returns default properties for contribution queries. However, they are + * far more than are required in 'most' cases and you should always try to return the return properties + * you actually require. + * + * It would be nice to throw an e-notice when this is called but it would trash the tests :-(. + * + * @param int $mode * @param bool $includeCustomFields * * @return array|NULL diff --git a/CRM/Contribute/Selector/Search.php b/CRM/Contribute/Selector/Search.php index bf931d8f42..1560690147 100644 --- a/CRM/Contribute/Selector/Search.php +++ b/CRM/Contribute/Selector/Search.php @@ -187,10 +187,7 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C $this->_includeSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($this->_queryParams); $this->_query = new CRM_Contact_BAO_Query( $this->_queryParams, - CRM_Contribute_BAO_Query::defaultReturnProperties( - CRM_Contact_BAO_Query::MODE_CONTRIBUTE, - FALSE - ), + CRM_Contribute_BAO_Query::selectorReturnProperties(), NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE ); -- 2.25.1