From 46c4230dea5ab1a42fff55db7cc439c208eef173 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 19 Mar 2021 14:32:32 +1300 Subject: [PATCH] [REF] Minor function extraction --- CRM/Contribute/Form/Task.php | 104 +++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 46 deletions(-) diff --git a/CRM/Contribute/Form/Task.php b/CRM/Contribute/Form/Task.php index 60cc441184..79fea13c6c 100644 --- a/CRM/Contribute/Form/Task.php +++ b/CRM/Contribute/Form/Task.php @@ -42,6 +42,60 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form_Task { */ public $_includesSoftCredits = FALSE; + /** + * Get the results from the BAO_Query object based search. + * + * @return CRM_Core_DAO + * + * @throws \CRM_Core_Exception + */ + public function getSearchQueryResults(): CRM_Core_DAO { + $form = $this; + $queryParams = $form->get('queryParams'); + $isTest = FALSE; + if (is_array($queryParams)) { + foreach ($queryParams as $fields) { + if ($fields[0] === 'contribution_test') { + $isTest = TRUE; + break; + } + } + } + if (!$isTest) { + $queryParams[] = [ + 'contribution_test', + '=', + 0, + 0, + 0, + ]; + } + $returnProperties = ['contribution_id' => 1]; + $sortOrder = $sortCol = NULL; + if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { + $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); + //Include sort column in select clause. + $sortCol = trim(str_replace(['`', 'asc', 'desc'], '', $sortOrder)); + $returnProperties[$sortCol] = 1; + } + + $form->_includesSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams); + $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE, + CRM_Contact_BAO_Query::MODE_CONTRIBUTE + ); + // @todo the function CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled should handle this + // can we remove? if not why not? + if ($form->_includesSoftCredits) { + $query->_rowCountClause = " count(civicrm_contribution.id)"; + $query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id "; + } + else { + $query->_distinctComponentClause = ' civicrm_contribution.id'; + $query->_groupByComponentClause = ' GROUP BY civicrm_contribution.id '; + } + return $query->searchQuery(0, 0, $sortOrder); + } + /** * Build all the data structures needed to build the form. */ @@ -50,11 +104,11 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form_Task { } /** - * @param \CRM_Core_Form_Task $form + * @param \CRM_Contribute_Form_Task $form * * @throws \CRM_Core_Exception */ - public static function preProcessCommon(&$form) { + public static function preProcessCommon(&$form): void { $form->_contributionIds = []; $values = $form->getSearchFormValues(); @@ -63,50 +117,8 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form_Task { $ids = $form->getSelectedIDs($values); if (!$ids) { - $queryParams = $form->get('queryParams'); - $isTest = FALSE; - if (is_array($queryParams)) { - foreach ($queryParams as $fields) { - if ($fields[0] === 'contribution_test') { - $isTest = TRUE; - break; - } - } - } - if (!$isTest) { - $queryParams[] = [ - 'contribution_test', - '=', - 0, - 0, - 0, - ]; - } - $returnProperties = ['contribution_id' => 1]; - $sortOrder = $sortCol = NULL; - if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { - $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); - //Include sort column in select clause. - $sortCol = trim(str_replace(['`', 'asc', 'desc'], '', $sortOrder)); - $returnProperties[$sortCol] = 1; - } - - $form->_includesSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams); - $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE, - CRM_Contact_BAO_Query::MODE_CONTRIBUTE - ); - // @todo the function CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled should handle this - // can we remove? if not why not? - if ($form->_includesSoftCredits) { - $contactIds = $contributionContactIds = []; - $query->_rowCountClause = " count(civicrm_contribution.id)"; - $query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id "; - } - else { - $query->_distinctComponentClause = ' civicrm_contribution.id'; - $query->_groupByComponentClause = ' GROUP BY civicrm_contribution.id '; - } - $result = $query->searchQuery(0, 0, $sortOrder); + $result = $form->getSearchQueryResults(); + $contributionContactIds = $contactIds = []; while ($result->fetch()) { $ids[] = $result->contribution_id; if ($form->_includesSoftCredits) { -- 2.25.1