* [refac] Refactor: improve parameter passing in search module methods.
- Add module parameter to setDefaultParams and getParamValues methods - Remove dependency on $_SESSION global variable in getParamValues - Improve method encapsulation by explicit parameter passing
This commit is contained in:
@@ -45,15 +45,15 @@ class search extends control
|
||||
$this->lang->search->common = $this->lang->search->common . $space . $this->session->objectName;
|
||||
}
|
||||
|
||||
$this->view->module = $module;
|
||||
$this->view->fields = $fields;
|
||||
$this->view->fieldParams = $this->search->setDefaultParams($fields, $params);
|
||||
$this->view->queries = $this->search->getQueryList($module);
|
||||
$this->view->actionURL = $this->session->$searchParams['actionURL'];
|
||||
$this->view->queryID = $this->session->$searchParams['queryID'] ?? 0;
|
||||
$this->view->style = $this->session->$searchParams['style'] ?? 'full';
|
||||
$this->view->onMenuBar = $this->session->$searchParams['onMenuBar'] ?? 'no';
|
||||
$this->view->formSession = $this->session->$searchForm;
|
||||
$this->view->module = $module;
|
||||
$this->view->fields = $fields;
|
||||
$this->view->fieldParams = $this->search->setDefaultParams($module, $fields, $params);
|
||||
$this->view->queries = $this->search->getQueryList($module);
|
||||
$this->view->actionURL = $this->session->$searchParams['actionURL'];
|
||||
$this->view->queryID = $this->session->$searchParams['queryID'] ?? 0;
|
||||
$this->view->style = $this->session->$searchParams['style'] ?? 'full';
|
||||
$this->view->onMenuBar = $this->session->$searchParams['onMenuBar'] ?? 'no';
|
||||
$this->view->formSession = $this->session->$searchForm;
|
||||
|
||||
if($module == 'program') $this->view->options = $this->searchZen->setOptions($fields, $this->view->fieldParams, $this->view->queries);
|
||||
|
||||
|
||||
@@ -67,16 +67,17 @@ class searchModel extends model
|
||||
* 设置默认的搜索参数。
|
||||
* Set default params for selection.
|
||||
*
|
||||
* @param string $module
|
||||
* @param array $fields
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultParams(array $fields, array $params): array
|
||||
public function setDefaultParams(string $module, array $fields, array $params): array
|
||||
{
|
||||
$fields = array_keys($fields);
|
||||
|
||||
list($users, $products, $executions) = $this->getParamValues($fields, $params);
|
||||
list($users, $products, $executions) = $this->getParamValues($module, $fields, $params);
|
||||
|
||||
foreach($fields as $fieldName)
|
||||
{
|
||||
|
||||
@@ -336,11 +336,13 @@ class searchTao extends searchModel
|
||||
* 如果搜索框的选项是users,products, executions, 获取相对应的列表。
|
||||
* Get user, product and execution value of the param.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param string $module
|
||||
* @param array $fields
|
||||
* @param array $params
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function getParamValues(array $fields, array $params): array
|
||||
protected function getParamValues(string $module, array $fields, array $params): array
|
||||
{
|
||||
$hasProduct = false;
|
||||
$hasExecution = false;
|
||||
@@ -355,7 +357,6 @@ class searchTao extends searchModel
|
||||
|
||||
/* 将用户的值追加到获取到的用户列表。*/
|
||||
$appendUsers = array();
|
||||
$module = $_SESSION['searchParams']['module'];
|
||||
$formSessionName = $module . 'Form';
|
||||
if(isset($_SESSION[$formSessionName]))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user