From: eileen Date: Sun, 2 Dec 2018 21:28:57 +0000 (+1300) Subject: [REF] refactor shared search functions in pre-Process X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=09e47399a1bcd6a101efd81ec400071f884e724d;p=civicrm-core.git [REF] refactor shared search functions in pre-Process This simply reduces some duplicate code in the search forms --- diff --git a/CRM/Activity/Form/Search.php b/CRM/Activity/Form/Search.php index 7e682b50fe..1433318102 100644 --- a/CRM/Activity/Form/Search.php +++ b/CRM/Activity/Form/Search.php @@ -82,14 +82,7 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search { $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 70fd4e6e2e..4aa68e1272 100644 --- a/CRM/Campaign/Form/Search.php +++ b/CRM/Campaign/Form/Search.php @@ -77,12 +77,7 @@ class CRM_Campaign_Form_Search extends CRM_Core_Form_Search { $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 86e3d4031d..810ea11f76 100644 --- a/CRM/Case/Form/Search.php +++ b/CRM/Case/Form/Search.php @@ -89,32 +89,8 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { $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 d8c2640b54..07c9521bdd 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -83,17 +83,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { // @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 9c1e316acb..7fbf516ac2 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -237,4 +237,37 @@ class CRM_Core_Form_Search extends CRM_Core_Form { } + /** + * 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 c5b73d8140..04291cf146 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -90,31 +90,8 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { $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 12e6ea09a1..4d833d9708 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 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { $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 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { /** * 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 8d26304f3b..764c19de1b 100644 --- a/CRM/Member/Form/Search.php +++ b/CRM/Member/Form/Search.php @@ -84,17 +84,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search { $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 50558aca71..81b536fc35 100644 --- a/CRM/Pledge/Form/Search.php +++ b/CRM/Pledge/Form/Search.php @@ -73,15 +73,7 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search { $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