From 09e47399a1bcd6a101efd81ec400071f884e724d Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 3 Dec 2018 10:28:57 +1300 Subject: [PATCH] [REF] refactor shared search functions in pre-Process This simply reduces some duplicate code in the search forms --- CRM/Activity/Form/Search.php | 9 +------ CRM/Campaign/Form/Search.php | 7 +----- CRM/Case/Form/Search.php | 28 ++------------------- CRM/Contribute/Form/Search.php | 12 +-------- CRM/Core/Form/Search.php | 33 +++++++++++++++++++++++++ CRM/Event/Form/Search.php | 27 ++------------------ CRM/Grant/Form/Search.php | 45 ++++++---------------------------- CRM/Member/Form/Search.php | 12 +-------- CRM/Pledge/Form/Search.php | 10 +------- 9 files changed, 49 insertions(+), 134 deletions(-) diff --git a/CRM/Activity/Form/Search.php b/CRM/Activity/Form/Search.php index 7e682b50fe0c..1433318102fa 100644 --- a/CRM/Activity/Form/Search.php +++ b/CRM/Activity/Form/Search.php @@ -82,14 +82,7 @@ public function preProcess() { $this->_done = FALSE; $this->defaults = array(); - // we allow the controller to set force/reset externally, useful when we are being - // driven by the wizard framework - $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean'); - $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); - $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); - $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search'); - - $this->assign("context", $this->_context); + $this->getUrlVariables(); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this diff --git a/CRM/Campaign/Form/Search.php b/CRM/Campaign/Form/Search.php index 70fd4e6e2e91..4aa68e127210 100644 --- a/CRM/Campaign/Form/Search.php +++ b/CRM/Campaign/Form/Search.php @@ -77,12 +77,7 @@ public function preProcess() { $this->_printButtonName = $this->getButtonName('next', 'print'); $this->_actionButtonName = $this->getButtonName('next', 'action'); - //we allow the controller to set force/reset externally, - //useful when we are being driven by the wizard framework - $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); - $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); - $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search'); - $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean'); + $this->getUrlVariables(); //operation for state machine. $this->_operation = CRM_Utils_Request::retrieve('op', 'String', $this, FALSE, 'reserve'); diff --git a/CRM/Case/Form/Search.php b/CRM/Case/Form/Search.php index 86e3d4031d3e..810ea11f763d 100644 --- a/CRM/Case/Form/Search.php +++ b/CRM/Case/Form/Search.php @@ -89,32 +89,8 @@ public function preProcess() { $this->_done = FALSE; $this->defaults = array(); - /* - * we allow the controller to set force/reset externally, useful when we are being - * driven by the wizard framework - */ - - $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean'); - $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); - $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); - $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search'); - - $this->assign('context', $this->_context); - - // get user submitted values - // get it from controller only if form has been submitted, else preProcess has set this - if (!empty($_POST) && !$this->controller->isModal()) { - $this->_formValues = $this->controller->exportValues($this->_name); - } - else { - $this->_formValues = $this->get('formValues'); - } - - if (empty($this->_formValues)) { - if (isset($this->_ssID)) { - $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); - } - } + $this->getUrlVariables(); + $this->getFormValues(); if ($this->_force) { $this->postProcess(); diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index d8c2640b5410..07c9521bdd18 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -83,17 +83,7 @@ public function preProcess() { // @todo - is this an error - $this->_defaults is used. $this->defaults = array(); - /* - * we allow the controller to set force/reset externally, useful when we are being - * driven by the wizard framework - */ - - $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean'); - $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); - $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); - $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search'); - - $this->assign("context", $this->_context); + $this->getUrlVariables(); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 9c1e316acb6c..7fbf516ac2e5 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -237,4 +237,37 @@ protected function addContactSearchFields() { } + /** + * we allow the controller to set force/reset externally, useful when we are being + * driven by the wizard framework + */ + protected function getUrlVariables() { + $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean'); + $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); + $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); + $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search'); + $this->_ssID = CRM_Utils_Request::retrieve('ssID', 'Positive', $this); + $this->assign("context", $this->_context); + } + + /** + * Get user submitted values. + * + * Get it from controller only if form has been submitted, else preProcess has set this + */ + protected function getFormVariables() { + if (!empty($_POST) && !$this->controller->isModal()) { + $this->_formValues = $this->controller->exportValues($this->_name); + } + else { + $this->_formValues = $this->get('formValues'); + } + + if (empty($this->_formValues)) { + if (isset($this->_ssID)) { + $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); + } + } + } + } diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index c5b73d81403b..04291cf1467a 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -90,31 +90,8 @@ public function preProcess() { $this->_done = FALSE; $this->defaults = array(); - /* - * we allow the controller to set force/reset externally, useful when we are being - * driven by the wizard framework - */ - $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean'); - $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); - $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); - $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search'); - $this->_ssID = CRM_Utils_Request::retrieve('ssID', 'Positive', $this); - $this->assign("context", $this->_context); - - // get user submitted values - // get it from controller only if form has been submitted, else preProcess has set this - if (!empty($_POST) && !$this->controller->isModal()) { - $this->_formValues = $this->controller->exportValues($this->_name); - } - else { - $this->_formValues = $this->get('formValues'); - } - - if (empty($this->_formValues)) { - if (isset($this->_ssID)) { - $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); - } - } + $this->getUrlVariables(); + $this->getFormValues(); if ($this->_force) { $this->postProcess(); diff --git a/CRM/Grant/Form/Search.php b/CRM/Grant/Form/Search.php index 12e6ea09a1f8..4d833d9708c1 100644 --- a/CRM/Grant/Form/Search.php +++ b/CRM/Grant/Form/Search.php @@ -29,16 +29,10 @@ * * @package CRM * @copyright CiviCRM LLC (c) 2004-2018 - * $Id$ - * */ /** - * Files required - */ - -/** - * This file is for civigrant search + * This file is for CiviGrant search */ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { @@ -57,9 +51,9 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { protected $_single = FALSE; /** - * Are we restricting ourselves to a single contact. + * Return limit. * - * @var boolean + * @var int */ protected $_limit = NULL; @@ -68,6 +62,8 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { */ protected $_prefix = "grant_"; + protected $entity = 'grant'; + /** * Processing needed for buildForm and later. * @@ -83,32 +79,8 @@ public function preProcess() { $this->_done = FALSE; $this->defaults = array(); - /* - * we allow the controller to set force/reset externally, useful when we are being - * driven by the wizard framework - */ - - $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean'); - $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); - $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); - $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search'); - - $this->assign("context", $this->_context); - - // get user submitted values - // get it from controller only if form has been submitted, else preProcess has set this - if (!empty($_POST)) { - $this->_formValues = $this->controller->exportValues($this->_name); - } - else { - $this->_formValues = $this->get('formValues'); - } - - if (empty($this->_formValues)) { - if (isset($this->_ssID)) { - $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); - } - } + $this->getUrlVariables(); + $this->getFormVariables(); if ($this->_force) { $this->postProcess(); @@ -154,9 +126,6 @@ public function preProcess() { /** * Build the form object. - * - * - * @return void */ public function buildQuickForm() { parent::buildQuickForm(); diff --git a/CRM/Member/Form/Search.php b/CRM/Member/Form/Search.php index 8d26304f3b9e..764c19de1b33 100644 --- a/CRM/Member/Form/Search.php +++ b/CRM/Member/Form/Search.php @@ -84,17 +84,7 @@ public function preProcess() { $this->defaults = array(); - /* - * we allow the controller to set force/reset externally, useful when we are being - * driven by the wizard framework - */ - - $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean'); - $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); - $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); - $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search'); - - $this->assign("context", $this->_context); + $this->getUrlVariables(); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this diff --git a/CRM/Pledge/Form/Search.php b/CRM/Pledge/Form/Search.php index 50558aca71d1..81b536fc35b1 100644 --- a/CRM/Pledge/Form/Search.php +++ b/CRM/Pledge/Form/Search.php @@ -73,15 +73,7 @@ public function preProcess() { $this->_done = FALSE; $this->defaults = array(); - // we allow the controller to set force/reset externally, useful when we are being - // driven by the wizard framework - - $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean'); - $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); - $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); - $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'search'); - - $this->assign("context", $this->_context); + $this->getUrlVariables(); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this