From: eileen Date: Fri, 19 Mar 2021 21:13:56 +0000 (+1300) Subject: Extract getQueryParams X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3ccafc036aa9e9c3937a890085ccad3c4ffc2254;p=civicrm-core.git Extract getQueryParams --- diff --git a/CRM/Contribute/Form/Task/TaskTrait.php b/CRM/Contribute/Form/Task/TaskTrait.php index 552d46d847..85d17ffe2b 100644 --- a/CRM/Contribute/Form/Task/TaskTrait.php +++ b/CRM/Contribute/Form/Task/TaskTrait.php @@ -29,25 +29,7 @@ trait CRM_Contribute_Form_Task_TaskTrait { */ 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, - ]; - } + $queryParams = $this->getQueryParams(); $returnProperties = ['contribution_id' => 1]; $sortOrder = $sortCol = NULL; if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { @@ -74,4 +56,29 @@ trait CRM_Contribute_Form_Task_TaskTrait { return $query->searchQuery(0, 0, $sortOrder); } + /** + * Get the query parameters, adding test = FALSE if needed. + * + * @return array|null + */ + protected function getQueryParams(): ?array { + $queryParams = $this->get('queryParams'); + if (!is_array($queryParams)) { + return NULL; + } + foreach ($queryParams as $fields) { + if ($fields[0] === 'contribution_test') { + return $queryParams; + } + } + $queryParams[] = [ + 'contribution_test', + '=', + 0, + 0, + 0, + ]; + return $queryParams; + } + }