From b5c6312508ade70619e43af2fa3b198d0d194bbc Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 9 Nov 2019 11:59:41 +1300 Subject: [PATCH] [REF] replace copy & paste with shared getSortID function. I've replaced this repetitive code chunk across the forms that inherit from CRM_Core_Form_Search --- CRM/Case/Form/Search.php | 18 ++---------------- CRM/Contribute/Form/Search.php | 19 ++----------------- CRM/Core/Form/Search.php | 16 ++++++++++++++++ CRM/Event/Form/Search.php | 18 ++---------------- CRM/Grant/Form/Search.php | 18 ++---------------- CRM/Member/Form/Search.php | 18 ++---------------- CRM/Pledge/Form/Search.php | 18 ++---------------- 7 files changed, 28 insertions(+), 97 deletions(-) diff --git a/CRM/Case/Form/Search.php b/CRM/Case/Form/Search.php index 25c61387e7..1d430b3050 100644 --- a/CRM/Case/Form/Search.php +++ b/CRM/Case/Form/Search.php @@ -103,13 +103,6 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { $this->handleForcedSearch(); } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Case_Selector_Search($this->_queryParams, $this->_action, @@ -129,7 +122,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER, @@ -245,13 +238,6 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { return; } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Case_Selector_Search($this->_queryParams, @@ -273,7 +259,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 5b60e7f898..fac69bfab0 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -96,13 +96,6 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { $this->_formValues['contribution_participant_id'] = $participantId; } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Contribute_Selector_Search($this->_queryParams, $this->_action, @@ -121,7 +114,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER, @@ -356,14 +349,6 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { return; } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - - // @todo - stop changing formValues - respect submitted form values, change a working array. $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Contribute_Selector_Search($this->_queryParams, $this->_action, @@ -381,7 +366,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 4e19ee206d..c4ea8a2599 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -519,6 +519,22 @@ class CRM_Core_Form_Search extends CRM_Core_Form { return (array) $this->get('formValues'); } + /** + * Get the string processed to determine sort order. + * + * This looks like 'sort_name_u' for Sort name ascending. + * + * @return string|null + */ + protected function getSortID() { + if ($this->get(CRM_Utils_Sort::SORT_ID)) { + return CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), + $this->get(CRM_Utils_Sort::SORT_DIRECTION) + ); + } + return NULL; + } + /** * Set the metadata for the form. * diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 88c49fdf4a..feb9f1db72 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -110,13 +110,6 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { $this->set('force', 0); } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, ['event_id']); $selector = new CRM_Event_Selector_Search($this->_queryParams, $this->_action, @@ -135,7 +128,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER, @@ -329,13 +322,6 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { return; } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, ['event_id']); $selector = new CRM_Event_Selector_Search($this->_queryParams, @@ -358,7 +344,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, diff --git a/CRM/Grant/Form/Search.php b/CRM/Grant/Form/Search.php index d1c2a54b9f..17e35f59b3 100644 --- a/CRM/Grant/Form/Search.php +++ b/CRM/Grant/Form/Search.php @@ -99,13 +99,6 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { $this->set('force', 0); } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Grant_Selector_Search($this->_queryParams, $this->_action, @@ -124,7 +117,7 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER, @@ -205,13 +198,6 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { return; } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $selector = new CRM_Grant_Selector_Search($this->_queryParams, $this->_action, NULL, @@ -228,7 +214,7 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, diff --git a/CRM/Member/Form/Search.php b/CRM/Member/Form/Search.php index 2ac9612aaa..0c9c2b20e7 100644 --- a/CRM/Member/Form/Search.php +++ b/CRM/Member/Form/Search.php @@ -101,13 +101,6 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search { $this->set('force', 0); } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields); $selector = new CRM_Member_Selector_Search($this->_queryParams, $this->_action, @@ -126,7 +119,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER, @@ -256,13 +249,6 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search { return; } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields); $selector = new CRM_Member_Selector_Search($this->_queryParams, @@ -281,7 +267,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, diff --git a/CRM/Pledge/Form/Search.php b/CRM/Pledge/Form/Search.php index 96c028901e..e78c21f409 100644 --- a/CRM/Pledge/Form/Search.php +++ b/CRM/Pledge/Form/Search.php @@ -106,13 +106,6 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search { $this->set('force', 0); } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Pledge_Selector_Search($this->_queryParams, $this->_action, @@ -131,7 +124,7 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER, @@ -272,13 +265,6 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search { return; } - $sortID = NULL; - if ($this->get(CRM_Utils_Sort::SORT_ID)) { - $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), - $this->get(CRM_Utils_Sort::SORT_DIRECTION) - ); - } - $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Pledge_Selector_Search($this->_queryParams, @@ -300,7 +286,7 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search { $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), - $sortID, + $this->getSortID(), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, -- 2.25.1