Merge branch feature/search of zentao/zentaopms (#10994)

This commit is contained in:
刘刚
2025-08-18 16:44:57 +08:00
committed by Gitfox
14 changed files with 505 additions and 129 deletions
+36
View File
@@ -282,6 +282,42 @@ class model extends baseModel
return $menu;
}
/**
* 缓存用于构造搜索参数的方法和参数。
* Cache the method and arguments used to build search parameters.
*
* @param string $module
* @param string $classMethod 构造搜索参数的类名和方法名,以::分隔。The class name and method name which builds the search params, separated by ::.
* @param array $methodArgs 调用构造搜索参数的方法时传入的参数列表(实参)。 The arguments passed to the method which builds the search params (actual parameters).
* @access public
* @return void
*/
public function cacheSearchFunc(string $module, string $classMethod, array $methodArgs)
{
list($className, $methodName) = explode('::', $classMethod);
$funcModel = str_replace(['ext', 'Model'], '', $className);
$key = 0;
$funcArgs = [];
$method = new ReflectionMethod($className, $methodName);
$params = $method->getParameters(); // 构造搜索参数的方法的参数列表(形参)。The parameters of the method which builds the search params (formal parameters).
foreach($params as $param)
{
if(isset($methodArgs[$key]))
{
$funcArgs[$param->getName()] = $methodArgs[$key];
}
elseif($param->isDefaultValueAvailable())
{
$funcArgs[$param->getName()] = $param->getDefaultValue();
}
$key++;
}
$this->session->set($module . 'SearchFunc', ['funcModel' => $funcModel, 'funcName' => $methodName, 'funcArgs' => $funcArgs]);
}
/**
* Process status of an object according to its subStatus.
*
+1 -3
View File
@@ -197,9 +197,7 @@ class execution extends control
/* Build the search form. */
$modules = $this->loadModel('tree')->getTaskOptionMenu($executionID, 0, $showModule);
$actionURL = $this->createLink('execution', 'task', "executionID=$executionID&status=bySearch&param=myQueryID&orderBy=$orderBy&recTotal=0&recPerPage=100&pageID=1&from=$from&blockID=$blockID");
$this->config->execution->search['onMenuBar'] = 'yes';
if(!$execution->multiple) unset($this->config->execution->search['fields']['execution']);
$this->execution->buildTaskSearchForm($executionID, $this->executions, $queryID, $actionURL);
$this->execution->buildTaskSearchForm($executionID, $productID, $this->executions, $queryID, $actionURL);
$this->view->title = $execution->name . $this->lang->hyphen . $this->lang->execution->task;
$this->view->tasks = $tasks;
+48 -13
View File
@@ -4169,15 +4169,28 @@ class executionModel extends model
* Build task search form.
*
* @param int $executionID
* @param int $productID
* @param array $executions
* @param int $queryID
* @param string $actionURL
* @param bool $cacheSearchFunc 是否缓存构造搜索参数的方法。默认缓存可以提高性能,构造搜索表单时再加载真实值。
* @access public
* @return void
*/
public function buildTaskSearchForm(int $executionID, array $executions, int $queryID, string $actionURL)
public function buildTaskSearchForm(int $executionID, int $productID, array $executions, int $queryID, string $actionURL, string $module = 'task', bool $cacheSearchFunc = true)
{
$showAll = empty($executionID) && empty($executions) ? true : false;
$searchConfig = $this->config->execution->search;
if($cacheSearchFunc)
{
$this->cacheSearchFunc($module, __METHOD__, func_get_args());
return $searchConfig;
}
$searchConfig['module'] = $module;
$searchConfig['actionURL'] = $actionURL;
$searchConfig['queryID'] = $queryID;
$showAll = empty($executionID) && empty($executions);
if($showAll)
{
$executions = $this->getPairs(0, 'all', "nocode,noprefix,multiple");
@@ -4185,27 +4198,49 @@ class executionModel extends model
}
$execution = $this->getByID($executionID);
$this->config->execution->search['actionURL'] = $actionURL;
$this->config->execution->search['queryID'] = $queryID;
$this->config->execution->search['params']['story']['values'] = $this->loadModel('story')->getExecutionStoryPairs($executionID, 0, 'all', '', 'full', 'unclosed', 'story', false);
$searchConfig['params']['story']['values'] = $this->loadModel('story')->getExecutionStoryPairs($executionID, 0, 'all', '', 'full', 'unclosed', 'story', false);
if($module == 'task')
{
$searchConfig['onMenuBar'] = 'yes';
if(!$execution->multiple) unset($searchConfig['fields']['execution']);
}
elseif($module == 'programplanTask')
{
unset($searchConfig['fields']['project']);
$executions = $this->loadModel('programplan')->getPairs($executionID, $productID, 'all');
}
elseif($module == 'projectTask')
{
unset($searchConfig['fields']['project']);
unset($searchConfig['fields']['module']);
}
if(isset($execution->type) && $execution->type == 'project')
{
unset($this->config->execution->search['fields']['project']);
$this->config->execution->search['params']['execution']['values'] = array('' => '') + $executions;
unset($searchConfig['fields']['project']);
if(isset($searchConfig['fields']['execution'])) $searchConfig['params']['execution']['values'] = array('' => '') + $executions;
}
else
{
$this->config->execution->search['params']['execution']['values'] = $showAll ? $executions : array(''=>'', $executionID => zget($executions, $executionID, ''), 'all' => $this->lang->execution->allExecutions);
if(isset($searchConfig['fields']['execution'])) $searchConfig['params']['execution']['values'] = $showAll ? $executions : array(''=>'', $executionID => zget($executions, $executionID, ''), 'all' => $this->lang->execution->allExecutions);
}
$projects = $this->loadModel('project')->getPairsByProgram();
$this->config->execution->search['params']['project']['values'] = $projects + array('all' => $this->lang->project->allProjects);
if(isset($searchConfig['fields']['project']))
{
$projects = $this->loadModel('project')->getPairsByProgram();
$searchConfig['params']['project']['values'] = $projects + array('all' => $this->lang->project->allProjects);
}
$showAllModule = isset($this->config->execution->task->allModule) ? $this->config->execution->task->allModule : '';
$this->config->execution->search['params']['module']['values'] = $this->loadModel('tree')->getTaskOptionMenu($executionID, 0, $showAllModule ? 'allModule' : '');
if(isset($searchConfig['fields']['module']))
{
$showAllModule = $this->config->execution->task->allModule ?? '';
$searchConfig['params']['module']['values'] = $this->loadModel('tree')->getTaskOptionMenu($executionID, 0, $showAllModule ? 'allModule' : '');
}
$this->loadModel('search')->setSearchParams($this->config->execution->search);
$this->loadModel('search')->setSearchParams($searchConfig);
return $searchConfig;
}
/**
@@ -2481,15 +2481,18 @@ class executionTest
* Test build task search form.
*
* @param int $executionID
* @param int $productID
* @param array $executions
* @param int $queryID
* @param string $actionURL
* @param string $module
* @param bool $cacheSearchFunc
* @access public
* @return int
* @return array
*/
public function buildTaskSearchFormTest($executionID, $queryID)
public function buildTaskSearchFormTest($executionID, $productID, $executions, $queryID, $actionURL, $module, $cacheSearchFunc): array
{
$this->executionModel->buildTaskSearchForm($executionID, array($executionID => 'yes'), $queryID, 'searchTask');
return $_SESSION['tasksearchParams']['queryID'];
return $this->executionModel->buildTaskSearchForm($executionID, $productID, $executions, $queryID, $actionURL, $module, $cacheSearchFunc);
}
/**
@@ -4,17 +4,18 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/execution.unittest.class.php';
$execution = zenData('project');
$execution->id->range('1-5');
$execution->name->range('项目1,项目2,迭代1,迭代2,迭代3');
$execution->type->range('project{2},sprint,stage,kanban');
$execution->id->range('1-8');
$execution->name->range('项目1,项目2,迭代1,迭代2,迭代3,阶段1,阶段2,阶段3');
$execution->type->range('project{2},sprint,stage,kanban,stage{3}');
$execution->model->range('scrum,waterfall,``{6}');
$execution->status->range('doing');
$execution->parent->range('0,0,1,1,2');
$execution->project->range('0,0,1,1,2');
$execution->grade->range('2{2},1{3}');
$execution->path->range('1,2,`1,3`,`1,4`,`2,5`')->prefix(',')->postfix(',');
$execution->parent->range('0,0,1{3},2{3}');
$execution->project->range('0,0,1{3},2{3}');
$execution->grade->range('2{2},1{6}');
$execution->path->range('1,2,`1,3`,`1,4`,`1,5`,`2,6`,`2,7`,`2,8`')->prefix(',')->postfix(',');
$execution->begin->range('20230102 000000:0')->type('timestamp')->format('YY/MM/DD');
$execution->end->range('20230212 000000:0')->type('timestamp')->format('YY/MM/DD');
$execution->gen(5);
$execution->gen(8);
$task = zenData('task');
$task->id->range('1-10');
@@ -36,6 +37,10 @@ $query->form->range('`a:59:{s:9:"fieldname";s:0:"";s:11:"fieldstatus";s:0:"";s:9
$query->sql->range("`(( 1 AND `name` LIKE '%任务%' ) AND ( 1 )) AND deleted = '0'`");
$query->gen(1);
$module = zenData('module');
$module->name->range('1,2,3,4,5')->prefix('模块');
$module->gen(5);
su('admin');
/**
@@ -44,20 +49,144 @@ title=测试executionModel->buildTaskSearchForm();
timeout=0
cid=1
- 正确的执行,正确的queryID @1
- 错误的执行,正确的queryID @1
- 正确的执行,错误的queryID @0
- 错误的执行,错误的queryID @0
- 正确的执行,正确的queryID @2
- module 为 projectTask,缓存查询参数,查询参数中 queryID 为空。 @0
- module 为 projectTask,缓存查询参数,查询参数中 actionURL 为空。 @0
- module 为 projectTask,缓存查询参数,查询参数中有 project 字段。 @1
- module 为 projectTask,缓存查询参数,查询参数中有 module 字段。 @1
- module 为 projectTask,缓存查询参数,打印 module 的值。属性module @task
- module 为 projectTask,缓存查询参数,打印所属执行列表。
- 属性3 @0
- 属性4 @0
- 属性5 @0
- module 为 projectTask,不缓存查询参数,查询参数中 queryID 有值。 @1
- module 为 projectTask,不缓存查询参数,查询参数中 actionURL 有值。 @1
- module 为 projectTask,不缓存查询参数,查询参数中没有 project 字段。 @0
- module 为 projectTask,不缓存查询参数,查询参数中没有 module 字段。 @0
- module 为 projectTask,不缓存查询参数,打印 module 的值。属性module @projectTask
- module 为 projectTask,不缓存查询参数,打印 queryID 的值。属性queryID @1
- module 为 projectTask,不缓存查询参数,打印 actionURL 的值。属性actionURL @/project-execution-bySearch-1-order_desc-0-0-100-1-myQueryID.html
- module 为 projectTask,不缓存查询参数,打印所属执行列表。
- 属性3 @迭代1
- 属性4 @迭代2
- 属性5 @迭代3
- module 为 programplanTask,缓存查询参数,查询参数中 queryID 为空。 @0
- module 为 programplanTask,缓存查询参数,查询参数中 actionURL 为空。 @0
- module 为 programplanTask,缓存查询参数,查询参数中有 project 字段。 @1
- module 为 programplanTask,缓存查询参数,打印 module 的值。属性module @task
- module 为 programplanTask,缓存查询参数,打印所属执行列表。
- 属性6 @0
- 属性7 @0
- 属性8 @0
- module 为 programplanTask,不缓存查询参数,查询参数中 queryID 有值。 @1
- module 为 programplanTask,不缓存查询参数,查询参数中 actionURL 有值。 @1
- module 为 programplanTask,不缓存查询参数,查询参数中没有 project 字段。 @0
- module 为 programplanTask,不缓存查询参数,打印 module 的值。属性module @programplanTask
- module 为 programplanTask,不缓存查询参数,打印 queryID 的值。属性queryID @1
- module 为 programplanTask,不缓存查询参数,打印 actionURL 的值。属性actionURL @/programplan-browse-2-0-gantt-id_asc-0-bysearch-myQueryID.html
- module 为 programplanTask,不缓存查询参数,打印所属执行列表。
- 属性6 @/阶段1
- 属性7 @/阶段2
- 属性8 @/阶段3
- module 为 task,缓存查询参数,查询参数中 queryID 为空。 @0
- module 为 task,缓存查询参数,查询参数中 actionURL 为空。 @0
- module 为 task,缓存查询参数,查询参数中 onMenuBar 为空。 @0
- module 为 task,缓存查询参数,打印所属项目列表。
- 属性1 @0
- 属性2 @0
- 属性all @0
- module 为 task,缓存查询参数,打印所属执行列表。
- @0
- 属性3 @0
- 属性all @0
- module 为 task,不缓存查询参数,查询参数中 queryID 有值。 @1
- module 为 task,不缓存查询参数,查询参数中 actionURL 有值。 @1
- module 为 task,不缓存查询参数,查询参数中 onMenuBar 有值。 @1
- module 为 task,不缓存查询参数,打印 module 的值。属性module @task
- module 为 task,不缓存查询参数,打印 queryID 的值。属性queryID @1
- module 为 task,不缓存查询参数,打印 actionURL 的值。属性actionURL @/execution-task-3-bySearch-myQueryID.html
- module 为 task,不缓存查询参数,打印所属项目列表。
- 属性1 @项目1
- 属性2 @项目2
- 属性all @所有项目
- module 为 task,不缓存查询参数,打印所属执行列表。
- @~~
- 属性3 @迭代1
- 属性all @所有执行
*/
$executionIDList = array('3', '0');
$queryIDList = array('0', '1', '2');
$execution = new executionTest();
r($execution->buildTaskSearchFormTest($executionIDList[0], $queryIDList[1])) && p() && e('1'); // 正确的执行,正确的queryID
r($execution->buildTaskSearchFormTest($executionIDList[1], $queryIDList[1])) && p() && e('1'); // 错误的执行,正确的queryID
r($execution->buildTaskSearchFormTest($executionIDList[0], $queryIDList[0])) && p() && e('0'); // 正确的执行,错误的queryID
r($execution->buildTaskSearchFormTest($executionIDList[1], $queryIDList[0])) && p() && e('0'); // 错误的执行,错误的queryID
r($execution->buildTaskSearchFormTest($executionIDList[1], $queryIDList[2])) && p() && e('2'); // 正确的执行,正确的queryID
$productID = 0;
$queryID = 1;
/**
* 测试为项目迭代列表页面构造搜索参数功能。
*/
$executionID = 1;
$executions = [3 => '迭代1', 4 => '迭代2', 5 => '迭代3'];
$actionURL = '/project-execution-bySearch-1-order_desc-0-0-100-1-myQueryID.html';
$module = 'projectTask';
$searchConfig = $execution->buildTaskSearchFormTest($executionID, $productID, $executions, $queryID, $actionURL, $module, true);
r(isset($searchConfig['queryID'])) && p() && e(0); // module 为 projectTask,缓存查询参数,查询参数中 queryID 为空。
r(isset($searchConfig['actionURL'])) && p() && e(0); // module 为 projectTask,缓存查询参数,查询参数中 actionURL 为空。
r(isset($searchConfig['fields']['project'])) && p() && e(1); // module 为 projectTask,缓存查询参数,查询参数中有 project 字段。
r(isset($searchConfig['fields']['module'])) && p() && e(1); // module 为 projectTask,缓存查询参数,查询参数中有 module 字段。
r($searchConfig) && p('module') && e('task'); // module 为 projectTask,缓存查询参数,打印 module 的值。
r($searchConfig['params']['execution']['values']) && p('3,4,5') && e('0,0,0'); // module 为 projectTask,缓存查询参数,打印所属执行列表。
$searchConfig = $execution->buildTaskSearchFormTest($executionID, $productID, $executions, $queryID, $actionURL, $module, false);
r(isset($searchConfig['queryID'])) && p() && e(1); // module 为 projectTask,不缓存查询参数,查询参数中 queryID 有值。
r(isset($searchConfig['actionURL'])) && p() && e(1); // module 为 projectTask,不缓存查询参数,查询参数中 actionURL 有值。
r(isset($searchConfig['fields']['project'])) && p() && e(0); // module 为 projectTask,不缓存查询参数,查询参数中没有 project 字段。
r(isset($searchConfig['fields']['module'])) && p() && e(0); // module 为 projectTask,不缓存查询参数,查询参数中没有 module 字段。
r($searchConfig) && p('module') && e('projectTask'); // module 为 projectTask,不缓存查询参数,打印 module 的值。
r($searchConfig) && p('queryID') && e('1'); // module 为 projectTask,不缓存查询参数,打印 queryID 的值。
r($searchConfig) && p('actionURL') && e('/project-execution-bySearch-1-order_desc-0-0-100-1-myQueryID.html'); // module 为 projectTask,不缓存查询参数,打印 actionURL 的值。
r($searchConfig['params']['execution']['values']) && p('3,4,5') && e('迭代1,迭代2,迭代3'); // module 为 projectTask,不缓存查询参数,打印所属执行列表。
/**
* 测试为瀑布项目阶段甘特图页面构造搜索参数功能。
*/
$executionID = 2;
$executions = [3 => '迭代1', 4 => '迭代2', 5 => '迭代3'];
$actionURL = '/programplan-browse-2-0-gantt-id_asc-0-bysearch-myQueryID.html';
$module = 'programplanTask';
$searchConfig = $execution->buildTaskSearchFormTest($executionID, $productID, $executions, $queryID, $actionURL, $module, true);
r(isset($searchConfig['queryID'])) && p() && e(0); // module 为 programplanTask,缓存查询参数,查询参数中 queryID 为空。
r(isset($searchConfig['actionURL'])) && p() && e(0); // module 为 programplanTask,缓存查询参数,查询参数中 actionURL 为空。
r(isset($searchConfig['fields']['project'])) && p() && e(1); // module 为 programplanTask,缓存查询参数,查询参数中有 project 字段。
r($searchConfig) && p('module') && e('task'); // module 为 programplanTask,缓存查询参数,打印 module 的值。
r($searchConfig['params']['execution']['values']) && p('6,7,8') && e('0,0,0'); // module 为 programplanTask,缓存查询参数,打印所属执行列表。
$searchConfig = $execution->buildTaskSearchFormTest($executionID, $productID, $executions, $queryID, $actionURL, $module, false);
r(isset($searchConfig['queryID'])) && p() && e(1); // module 为 programplanTask,不缓存查询参数,查询参数中 queryID 有值。
r(isset($searchConfig['actionURL'])) && p() && e(1); // module 为 programplanTask,不缓存查询参数,查询参数中 actionURL 有值。
r(isset($searchConfig['fields']['project'])) && p() && e(0); // module 为 programplanTask,不缓存查询参数,查询参数中没有 project 字段。
r($searchConfig) && p('module') && e('programplanTask'); // module 为 programplanTask,不缓存查询参数,打印 module 的值。
r($searchConfig) && p('queryID') && e('1'); // module 为 programplanTask,不缓存查询参数,打印 queryID 的值。
r($searchConfig) && p('actionURL') && e('/programplan-browse-2-0-gantt-id_asc-0-bysearch-myQueryID.html'); // module 为 programplanTask,不缓存查询参数,打印 actionURL 的值。
r($searchConfig['params']['execution']['values']) && p('6,7,8') && e('/阶段1,/阶段2,/阶段3'); // module 为 programplanTask,不缓存查询参数,打印所属执行列表。
/**
* 测试为执行任务列表页面构造搜索参数功能。
*/
$executionID = 3;
$executions = [3 => '迭代1', 4 => '迭代2', 5 => '迭代3'];
$actionURL = '/execution-task-3-bySearch-myQueryID.html';
$module = 'task';
$searchConfig = $execution->buildTaskSearchFormTest($executionID, $productID, $executions, $queryID, $actionURL, $module, true);
r(isset($searchConfig['queryID'])) && p() && e(0); // module 为 task,缓存查询参数,查询参数中 queryID 为空。
r(isset($searchConfig['actionURL'])) && p() && e(0); // module 为 task,缓存查询参数,查询参数中 actionURL 为空。
r(isset($searchConfig['onMenuBar'])) && p() && e(0); // module 为 task,缓存查询参数,查询参数中 onMenuBar 为空。
r($searchConfig['params']['project']['values']) && p('1,2,all') && e('0,0,0'); // module 为 task,缓存查询参数,打印所属项目列表。
r($searchConfig['params']['execution']['values']) && p(',3,all') && e('0,0,0'); // module 为 task,缓存查询参数,打印所属执行列表。
$searchConfig = $execution->buildTaskSearchFormTest($executionID, $productID, $executions, $queryID, $actionURL, $module, false);
r(isset($searchConfig['queryID'])) && p() && e(1); // module 为 task,不缓存查询参数,查询参数中 queryID 有值。
r(isset($searchConfig['actionURL'])) && p() && e(1); // module 为 task,不缓存查询参数,查询参数中 actionURL 有值。
r(isset($searchConfig['onMenuBar'])) && p() && e(1); // module 为 task,不缓存查询参数,查询参数中 onMenuBar 有值。
r($searchConfig) && p('module') && e('task'); // module 为 task,不缓存查询参数,打印 module 的值。
r($searchConfig) && p('queryID') && e('1'); // module 为 task,不缓存查询参数,打印 queryID 的值。
r($searchConfig) && p('actionURL') && e('/execution-task-3-bySearch-myQueryID.html'); // module 为 task,不缓存查询参数,打印 actionURL 的值。
r($searchConfig['params']['project']['values']) && p('1,2,all') && e('项目1,项目2,所有项目'); // module 为 task,不缓存查询参数,打印所属项目列表。
r($searchConfig['params']['execution']['values']) && p(',3,all') && e('~~,迭代1,所有执行'); // module 为 task,不缓存查询参数,打印所属执行列表。
+1 -1
View File
@@ -434,7 +434,7 @@ class my extends control
$tasks = $this->myZen->buildTaskData($tasks);
$actionURL = $this->createLink('my', $this->app->rawMethod, "mode=task&browseType=bySearch&queryID=myQueryID");
$this->my->buildTaskSearchForm($queryID, $actionURL);
$this->my->buildTaskSearchForm($queryID, $actionURL, $this->app->rawMethod . 'Task');
$this->myZen->showWorkCount($recTotal, $recPerPage, $pageID);
+28 -19
View File
@@ -448,38 +448,47 @@ class myModel extends model
*
* @param int $queryID
* @param string $actionURL
* @param string $module
* @param bool $cacheSearchFunc 是否缓存构造搜索参数的方法。默认缓存可以提高性能,构造搜索表单时再加载真实值。
* @access public
* @return void
*/
public function buildTaskSearchForm(int $queryID, string $actionURL): void
public function buildTaskSearchForm(int $queryID, string $actionURL, string $module, bool $cacheSearchFunc = true)
{
$rawMethod = $this->app->rawMethod;
$this->loadModel('execution');
$this->config->execution->search['module'] = $rawMethod . 'Task';
$this->config->execution->search['actionURL'] = $actionURL;
$this->config->execution->search['queryID'] = $queryID;
if($rawMethod == 'work')
$searchConfig = $this->config->execution->search;
if($cacheSearchFunc)
{
unset($this->config->execution->search['fields']['closedReason']);
unset($this->config->execution->search['fields']['closedBy']);
unset($this->config->execution->search['fields']['canceledBy']);
unset($this->config->execution->search['fields']['closedDate']);
unset($this->config->execution->search['fields']['canceledDate']);
unset($this->config->execution->search['params']['status']['values']['cancel']);
unset($this->config->execution->search['params']['status']['values']['closed']);
$this->cacheSearchFunc($module, __METHOD__, func_get_args());
return $searchConfig;
}
$searchConfig['module'] = $module;
$searchConfig['actionURL'] = $actionURL;
$searchConfig['queryID'] = $queryID;
if($module == 'workTask')
{
unset($searchConfig['fields']['closedReason']);
unset($searchConfig['fields']['closedBy']);
unset($searchConfig['fields']['canceledBy']);
unset($searchConfig['fields']['closedDate']);
unset($searchConfig['fields']['canceledDate']);
unset($searchConfig['params']['status']['values']['cancel']);
unset($searchConfig['params']['status']['values']['closed']);
}
$projects = $this->loadModel('project')->getPairsByProgram();
$this->config->execution->search['params']['project']['values'] = $projects + array('all' => $this->lang->project->allProjects);
$searchConfig['params']['project']['values'] = $projects + array('all' => $this->lang->project->allProjects);
$executions = $this->execution->getPairs(0, 'all', 'multiple');
$this->config->execution->search['params']['execution']['values'] = $executions + array('all' => $this->lang->execution->allExecutions);
$searchConfig['params']['execution']['values'] = $executions + array('all' => $this->lang->execution->allExecutions);
$this->config->execution->search['params']['module']['values'] = $this->loadModel('tree')->getAllModulePairs();
$searchConfig['params']['module']['values'] = $this->loadModel('tree')->getAllModulePairs();
$this->loadModel('search')->setSearchParams($this->config->execution->search);
$this->loadModel('search')->setSearchParams($searchConfig);
return $searchConfig;
}
/**
+4 -6
View File
@@ -269,16 +269,14 @@ class myTest
*
* @param int $queryID
* @param string $actionURL
* @param string $module
* @param bool $cacheSearchFunc
* @access public
* @return array
*/
public function buildTaskSearchFormTest(int $queryID, string $actionURL): array
public function buildTaskSearchFormTest(int $queryID, string $actionURL, string $module, bool $cacheSearchFunc): array
{
$this->objectModel->buildTaskSearchForm($queryID, $actionURL);
if(dao::isError()) return dao::getError();
global $tester;
return $tester->config->execution->search;
return $this->objectModel->buildTaskSearchForm($queryID, $actionURL, $module, $cacheSearchFunc);
}
/**
+167 -15
View File
@@ -4,7 +4,18 @@ declare(strict_types=1);
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/my.unittest.class.php';
zenData('user')->gen('1');
zenData('user')->gen(1);
$execution = zenData('project');
$execution->id->range('1-5');
$execution->name->range('项目1,项目2,迭代1,迭代2,迭代3');
$execution->type->range('project{2},sprint,stage,kanban');
$execution->path->range('1,2,`1,3`,`1,4`,`2,5`')->prefix(',')->postfix(',');
$execution->gen(5);
$module = zenData('module');
$module->name->range('1,2,3,4,5')->prefix('模块');
$module->gen(5);
su('admin');
@@ -14,22 +25,163 @@ title=测试 myModel->buildTaskSearchForm();
timeout=0
cid=1
- 测试获取queryID 1 actionURL actionURL1 的搜索表单
- 属性module @Task
- 属性queryID @0
- 属性actionURL @actionURL1
- 测试获取queryID 0 actionURL actionURL2 的搜索表单
- 属性module @Task
- 属性queryID @1
- 属性actionURL @actionURL2
- module 为 workTask,缓存查询参数,查询参数中 queryID 为空。 @0
- module 为 workTask,缓存查询参数,查询参数中 actionURL 为空。 @0
- module 为 workTask,缓存查询参数,查询字段中 closedReason 不为空。 @1
- module 为 workTask,缓存查询参数,查询字段中 closedBy 不为空。 @1
- module 为 workTask,缓存查询参数,查询字段中 closedDate 不为空。 @1
- module 为 workTask,缓存查询参数,查询字段中 canceledBy 不为空。 @1
- module 为 workTask,缓存查询参数,查询字段中 canceledDate 不为空。 @1
- module 为 workTask,缓存查询参数,打印 module 的值。属性module @task
- module 为 workTask,缓存查询参数,打印所属项目列表。
- 属性1 @0
- 属性2 @0
- 属性all @0
- module 为 workTask,缓存查询参数,打印所属执行列表。
- 属性3 @0
- 属性4 @0
- 属性5 @0
- 属性all @0
- module 为 workTask,缓存查询参数,打印所属模块列表。
- @0
- 属性2 @0
- 属性5 @0
- module 为 workTask,不缓存查询参数,查询参数中 queryID 不为空。 @1
- module 为 workTask,不缓存查询参数,查询参数中 actionURL 不为空。 @1
- module 为 workTask,不缓存查询参数,查询字段中 closedReason 为空。 @0
- module 为 workTask,不缓存查询参数,查询字段中 closedBy 为空。 @0
- module 为 workTask,不缓存查询参数,查询字段中 closedDate 为空。 @0
- module 为 workTask,不缓存查询参数,查询字段中 canceledBy 为空。 @0
- module 为 workTask,不缓存查询参数,查询字段中 canceledDate 为空。 @0
- module 为 workTask,不缓存查询参数,打印 module 的值。属性module @workTask
- module 为 workTask,不缓存查询参数,打印 queryID 的值。属性queryID @1
- module 为 workTask,不缓存查询参数,打印 actionURL 的值。属性actionURL @/my-work-task.html
- module 为 workTask,不缓存查询参数,打印所属项目列表。
- 属性1 @项目1
- 属性2 @项目2
- 属性all @所有项目
- module 为 workTask,不缓存查询参数,打印所属执行列表。
- 属性3 @/迭代1
- 属性4 @/迭代2
- 属性5 @/迭代3
- 属性all @所有执行
- module 为 workTask,不缓存查询参数,打印所属模块列表。
- @/
- 属性2 @/模块2
- 属性5 @/模块5
- module 为 contributeTask,缓存查询参数,查询参数中 queryID 为空。 @0
- module 为 contributeTask,缓存查询参数,查询参数中 actionURL 为空。 @0
- module 为 contributeTask,缓存查询参数,查询字段中 closedReason 不为空。 @1
- module 为 contributeTask,缓存查询参数,查询字段中 closedBy 不为空。 @1
- module 为 contributeTask,缓存查询参数,查询字段中 closedDate 不为空。 @1
- module 为 contributeTask,缓存查询参数,查询字段中 canceledBy 不为空。 @1
- module 为 contributeTask,缓存查询参数,查询字段中 canceledDate 不为空。 @1
- module 为 contributeTask,缓存查询参数,打印 module 的值。属性module @task
- module 为 contributeTask,缓存查询参数,打印所属项目列表。
- 属性1 @0
- 属性2 @0
- 属性all @0
- module 为 contributeTask,缓存查询参数,打印所属执行列表。
- 属性3 @0
- 属性4 @0
- 属性5 @0
- 属性all @0
- module 为 contributeTask,缓存查询参数,打印所属模块列表。
- @0
- 属性2 @0
- 属性5 @0
- 不缓存查询参数,module 为 contributeTask,查询参数中 module 不为空。 @1
- 不缓存查询参数,module 为 contributeTask,查询参数中 queryID 不为空。 @1
- 不缓存查询参数,module 为 contributeTask,查询参数中 actionURL 不为空。 @1
- 不缓存查询参数,module 为 contributeTask,查询字段中 closedReason 不为空。 @1
- 不缓存查询参数,module 为 contributeTask,查询字段中 closedBy 不为空。 @1
- 不缓存查询参数,module 为 contributeTask,查询字段中 closedDate 不为空。 @1
- 不缓存查询参数,module 为 contributeTask,查询字段中 canceledBy 不为空。 @1
- 不缓存查询参数,module 为 contributeTask,查询字段中 canceledDate 不为空。 @1
- 不缓存查询参数,module 为 contributeTask,打印 module 的值。属性module @contributeTask
- 不缓存查询参数,module 为 contributeTask,打印 queryID 的值。属性queryID @1
- 不缓存查询参数,module 为 contributeTask,打印 actionURL 的值。属性actionURL @/my-contribute-task.html
- 不缓存查询参数,module 为 contributeTask,打印所属项目列表。
- 属性1 @项目1
- 属性2 @项目2
- 属性all @所有项目
- 不缓存查询参数,module 为 contributeTask,打印所属执行列表。
- 属性3 @/迭代1
- 属性4 @/迭代2
- 属性5 @/迭代3
- 属性all @所有执行
- 不缓存查询参数,module 为 contributeTask,打印所属模块列表。
- @/
- 属性2 @/模块2
- 属性5 @/模块5
*/
$my = new myTest();
$queryID = array(0, 1);
$actionURL = array('actionURL1', 'actionURL2');
$config1 = $my->buildTaskSearchFormTest($queryID[0], $actionURL[0]);
$config2 = $my->buildTaskSearchFormTest($queryID[1], $actionURL[1]);
r($config1) && p('module,queryID,actionURL') && e('Task,0,actionURL1'); // 测试获取queryID 1 actionURL actionURL1 的搜索表单
r($config2) && p('module,queryID,actionURL') && e('Task,1,actionURL2'); // 测试获取queryID 0 actionURL actionURL2 的搜索表单
$queryID = 1;
$module = 'workTask';
$actionURL = "/my-work-task.html";
$searchConfig = $my->buildTaskSearchFormTest($queryID, $actionURL, $module, true);
r(isset($searchConfig['queryID'])) && p() && e(0); // module 为 workTask,缓存查询参数,查询参数中 queryID 为空。
r(isset($searchConfig['actionURL'])) && p() && e(0); // module 为 workTask,缓存查询参数,查询参数中 actionURL 为空。
r(isset($searchConfig['fields']['closedReason'])) && p() && e(1); // module 为 workTask,缓存查询参数,查询字段中 closedReason 不为空。
r(isset($searchConfig['fields']['closedBy'])) && p() && e(1); // module 为 workTask,缓存查询参数,查询字段中 closedBy 不为空。
r(isset($searchConfig['fields']['closedDate'])) && p() && e(1); // module 为 workTask,缓存查询参数,查询字段中 closedDate 不为空。
r(isset($searchConfig['fields']['canceledBy'])) && p() && e(1); // module 为 workTask,缓存查询参数,查询字段中 canceledBy 不为空。
r(isset($searchConfig['fields']['canceledDate'])) && p() && e(1); // module 为 workTask,缓存查询参数,查询字段中 canceledDate 不为空。
r($searchConfig) && p('module') && e('task'); // module 为 workTask,缓存查询参数,打印 module 的值。
r($searchConfig['params']['project']['values']) && p('1,2,all') && e('0,0,0'); // module 为 workTask,缓存查询参数,打印所属项目列表。
r($searchConfig['params']['execution']['values']) && p('3,4,5,all') && e('0,0,0,0'); // module 为 workTask,缓存查询参数,打印所属执行列表。
r($searchConfig['params']['module']['values']) && p('0,2,5') && e('0,0,0'); // module 为 workTask,缓存查询参数,打印所属模块列表。
$searchConfig = $my->buildTaskSearchFormTest($queryID, $actionURL, $module, false);
r(isset($searchConfig['queryID'])) && p() && e(1); // module 为 workTask,不缓存查询参数,查询参数中 queryID 不为空。
r(isset($searchConfig['actionURL'])) && p() && e(1); // module 为 workTask,不缓存查询参数,查询参数中 actionURL 不为空。
r(isset($searchConfig['fields']['closedReason'])) && p() && e(0); // module 为 workTask,不缓存查询参数,查询字段中 closedReason 为空。
r(isset($searchConfig['fields']['closedBy'])) && p() && e(0); // module 为 workTask,不缓存查询参数,查询字段中 closedBy 为空。
r(isset($searchConfig['fields']['closedDate'])) && p() && e(0); // module 为 workTask,不缓存查询参数,查询字段中 closedDate 为空。
r(isset($searchConfig['fields']['canceledBy'])) && p() && e(0); // module 为 workTask,不缓存查询参数,查询字段中 canceledBy 为空。
r(isset($searchConfig['fields']['canceledDate'])) && p() && e(0); // module 为 workTask,不缓存查询参数,查询字段中 canceledDate 为空。
r($searchConfig) && p('module') && e('workTask'); // module 为 workTask,不缓存查询参数,打印 module 的值。
r($searchConfig) && p('queryID') && e('1'); // module 为 workTask,不缓存查询参数,打印 queryID 的值。
r($searchConfig) && p('actionURL') && e('/my-work-task.html'); // module 为 workTask,不缓存查询参数,打印 actionURL 的值。
r($searchConfig['params']['project']['values']) && p('1,2,all') && e('项目1,项目2,所有项目'); // module 为 workTask,不缓存查询参数,打印所属项目列表。
r($searchConfig['params']['execution']['values']) && p('3,4,5,all') && e('/迭代1,/迭代2,/迭代3,所有执行'); // module 为 workTask,不缓存查询参数,打印所属执行列表。
r($searchConfig['params']['module']['values']) && p('0,2,5') && e('/,/模块2,/模块5'); // module 为 workTask,不缓存查询参数,打印所属模块列表。
$queryID = 1;
$module = 'contributeTask';
$actionURL = "/my-contribute-task.html";
$searchConfig = $my->buildTaskSearchFormTest($queryID, $actionURL, $module, true);
r(isset($searchConfig['queryID'])) && p() && e(0); // module 为 contributeTask,缓存查询参数,查询参数中 queryID 为空。
r(isset($searchConfig['actionURL'])) && p() && e(0); // module 为 contributeTask,缓存查询参数,查询参数中 actionURL 为空。
r(isset($searchConfig['fields']['closedReason'])) && p() && e(1); // module 为 contributeTask,缓存查询参数,查询字段中 closedReason 不为空。
r(isset($searchConfig['fields']['closedBy'])) && p() && e(1); // module 为 contributeTask,缓存查询参数,查询字段中 closedBy 不为空。
r(isset($searchConfig['fields']['closedDate'])) && p() && e(1); // module 为 contributeTask,缓存查询参数,查询字段中 closedDate 不为空。
r(isset($searchConfig['fields']['canceledBy'])) && p() && e(1); // module 为 contributeTask,缓存查询参数,查询字段中 canceledBy 不为空。
r(isset($searchConfig['fields']['canceledDate'])) && p() && e(1); // module 为 contributeTask,缓存查询参数,查询字段中 canceledDate 不为空。
r($searchConfig) && p('module') && e('task'); // module 为 contributeTask,缓存查询参数,打印 module 的值。
r($searchConfig['params']['project']['values']) && p('1,2,all') && e('0,0,0'); // module 为 contributeTask,缓存查询参数,打印所属项目列表。
r($searchConfig['params']['execution']['values']) && p('3,4,5,all') && e('0,0,0,0'); // module 为 contributeTask,缓存查询参数,打印所属执行列表。
r($searchConfig['params']['module']['values']) && p('0,2,5') && e('0,0,0'); // module 为 contributeTask,缓存查询参数,打印所属模块列表。
$searchConfig = $my->buildTaskSearchFormTest($queryID, $actionURL, $module, false);
r(isset($searchConfig['module'])) && p() && e(1); // 不缓存查询参数,module 为 contributeTask,查询参数中 module 不为空。
r(isset($searchConfig['queryID'])) && p() && e(1); // 不缓存查询参数,module 为 contributeTask,查询参数中 queryID 不为空。
r(isset($searchConfig['actionURL'])) && p() && e(1); // 不缓存查询参数,module 为 contributeTask,查询参数中 actionURL 不为空。
r(isset($searchConfig['fields']['closedReason'])) && p() && e(1); // 不缓存查询参数,module 为 contributeTask,查询字段中 closedReason 不为空。
r(isset($searchConfig['fields']['closedBy'])) && p() && e(1); // 不缓存查询参数,module 为 contributeTask,查询字段中 closedBy 不为空。
r(isset($searchConfig['fields']['closedDate'])) && p() && e(1); // 不缓存查询参数,module 为 contributeTask,查询字段中 closedDate 不为空。
r(isset($searchConfig['fields']['canceledBy'])) && p() && e(1); // 不缓存查询参数,module 为 contributeTask,查询字段中 canceledBy 不为空。
r(isset($searchConfig['fields']['canceledDate'])) && p() && e(1); // 不缓存查询参数,module 为 contributeTask,查询字段中 canceledDate 不为空。
r($searchConfig) && p('module') && e('contributeTask'); // 不缓存查询参数,module 为 contributeTask,打印 module 的值。
r($searchConfig) && p('queryID') && e('1'); // 不缓存查询参数,module 为 contributeTask,打印 queryID 的值。
r($searchConfig) && p('actionURL') && e('/my-contribute-task.html'); // 不缓存查询参数,module 为 contributeTask,打印 actionURL 的值。
r($searchConfig['params']['project']['values']) && p('1,2,all') && e('项目1,项目2,所有项目'); // 不缓存查询参数,module 为 contributeTask,打印所属项目列表。
r($searchConfig['params']['execution']['values']) && p('3,4,5,all') && e('/迭代1,/迭代2,/迭代3,所有执行'); // 不缓存查询参数,module 为 contributeTask,打印所属执行列表。
r($searchConfig['params']['module']['values']) && p('0,2,5') && e('/,/模块2,/模块5'); // 不缓存查询参数,module 为 contributeTask,打印所属模块列表。
+1 -5
View File
@@ -442,12 +442,8 @@ class programplanZen extends programplan
if($hasSearch)
{
/* Build the search form. */
$this->config->execution->search['module'] = 'projectTask';
$actionURL = $this->createLink('programplan', 'browse', "projectID=$projectID&productID=$productID&type=$type&orderBy=$orderBy&baselineID=$baselineID&browseType=bysearch&queryID=myQueryID");
unset($this->config->execution->search['fields']['project']);
$executions = $this->programplan->getPairs($projectID, $productID, 'all');
$this->loadModel('execution')->buildTaskSearchForm($projectID, $executions, $queryID, $actionURL);
$this->loadModel('execution')->buildTaskSearchForm($projectID, $productID, $executions, $queryID, $actionURL, 'programplanTask');
}
$this->view->title = $this->lang->programplan->browse;
+2 -7
View File
@@ -870,15 +870,10 @@ class project extends control
if($this->cookie->showTask)
{
/* Build the search form. */
$this->config->execution->search['module'] = 'projectTask';
$actionURL = $this->createLink('project', 'execution', "status=bysearch&projectID=$projectID&orderBy=$orderBy&productID=$productID&recTotal=$recTotal&recPerPage=$recPerPage&pageID=$pageID&queryID=myQueryID");
unset($this->config->execution->search['fields']['project']);
unset($this->config->execution->search['fields']['module']);
$actionURL = $this->createLink('project', 'execution', "status=bysearch&projectID=$projectID&orderBy=$orderBy&productID=$productID&recTotal=$recTotal&recPerPage=$recPerPage&pageID=$pageID&queryID=myQueryID");
$executions = $this->execution->fetchExecutionList($projectID, 'all', $productID);
$executions = $this->execution->getPairsByList(array_keys($executions));
$this->execution->buildTaskSearchForm($projectID, $executions, $queryID, $actionURL);
$this->execution->buildTaskSearchForm($projectID, $productID, $executions, $queryID, $actionURL, 'projectTask');
}
$this->view->title = $this->lang->execution->allExecutions;
+7 -7
View File
@@ -34,9 +34,9 @@ class search extends control
$module = empty($module) ? $this->session->searchParams['module'] : $module;
$searchParams = $module . 'searchParams';
$searchForm = $module . 'Form';
$fields = empty($fields) ? json_decode($_SESSION[$searchParams]['searchFields'], true) : $fields;
$params = empty($params) ? json_decode($_SESSION[$searchParams]['fieldParams'], true) : $params;
$searchConfig = $this->search->processSearchParams($module);
$fields = $searchConfig['fields'] ?? $fields;
$params = $searchConfig['params'] ?? $params;
$_SESSION['searchParams']['module'] = $module;
if(empty($_SESSION[$searchForm])) $this->search->initSession($module, $fields, $params);
@@ -55,7 +55,7 @@ class search extends control
$this->view->queryID = (empty($module) && empty($queryID)) ? $_SESSION[$searchParams]['queryID'] : $queryID;
$this->view->style = !empty($_SESSION[$searchParams]['style']) ? $_SESSION[$searchParams]['style'] : 'full';
$this->view->onMenuBar = !empty($_SESSION[$searchParams]['onMenuBar']) ? $_SESSION[$searchParams]['onMenuBar'] : 'no';
$this->view->formSession = $_SESSION[$module . 'Form'];
$this->view->formSession = $_SESSION[$searchForm];
$this->view->formName = $formName;
if($module == 'program') $this->view->options = $this->searchZen->setOptions($fields, $this->view->fieldParams, $this->view->queries);
@@ -82,9 +82,9 @@ class search extends control
$module = empty($module) ? $this->session->searchParams['module'] : $module;
$searchParams = $module . 'searchParams';
$searchForm = $module . 'Form';
$fields = empty($fields) ? json_decode($_SESSION[$searchParams]['searchFields'], true) : $fields;
$params = empty($params) ? json_decode($_SESSION[$searchParams]['fieldParams'], true) : $params;
$searchConfig = $this->search->processSearchParams($module);
$fields = $searchConfig['fields'] ?? $fields;
$params = $searchConfig['fields'] ?? $params;
$_SESSION['searchParams']['module'] = $module;
if(empty($_SESSION[$searchForm])) $this->search->initOldSession($module, $fields, $params);
+45 -19
View File
@@ -13,6 +13,26 @@
<?php
class searchModel extends model
{
/**
* 构造搜索表单时调用被搜索模块的方法处理搜索参数。
* Call the method of the searched module to process search parameters when constructing the search form.
*
* @param string $module
* @param bool $cacheSearchFunc // 是否缓存构造搜索参数的方法。默认不缓存以加载真实值。Wheater to cache the method of constructing search parameters. Default is not to cache to load real values.
* @access public
* @return array
*/
public function processSearchParams(string $module, bool $cacheSearchFunc = false): array
{
$cacheKey = $module . 'SearchFunc';
$funcModel = $this->session->$cacheKey['funcModel'] ?? '';
$funcName = $this->session->$cacheKey['funcName'] ?? '';
$funcArgs = $this->session->$cacheKey['funcArgs'] ?? [];
if(!$funcModel || !$funcName || !$funcArgs) return $this->session->{$module . 'searchParams'} ?? [];
$funcArgs['cacheSearchFunc'] = $cacheSearchFunc;
return $this->loadModel($funcModel)->$funcName(...$funcArgs);
}
/**
* 设置搜索参数的session。
@@ -22,19 +42,23 @@ class searchModel extends model
* @access public
* @return void
*/
public function setSearchParams(array $searchConfig): void
public function setSearchParams(array $searchConfig)
{
$module = $searchConfig['module'];
if($this->config->edition != 'open') $searchConfig = $this->searchTao->processBuildinFields($module, $searchConfig);
$searchParams['module'] = $searchConfig['module'];
$searchParams['searchFields'] = json_encode($searchConfig['fields']);
$searchParams['fieldParams'] = json_encode($searchConfig['params']);
$searchParams['actionURL'] = $searchConfig['actionURL'];
$searchParams['style'] = zget($searchConfig, 'style', 'full');
$searchParams['onMenuBar'] = zget($searchConfig, 'onMenuBar', 'no');
$searchParams['queryID'] = isset($searchConfig['queryID']) ? $searchConfig['queryID'] : 0;
$searchParams['module'] = $module;
$searchParams['actionURL'] = $searchConfig['actionURL'];
$searchParams['style'] = zget($searchConfig, 'style', 'full');
$searchParams['onMenuBar'] = zget($searchConfig, 'onMenuBar', 'no');
$searchParams['queryID'] = isset($searchConfig['queryID']) ? $searchConfig['queryID'] : 0;
if(empty($_SESSION[$module . 'SearchFunc']))
{
$searchParams['searchFields'] = $searchConfig['fields'];
$searchParams['fieldParams'] = $searchConfig['params'];
}
$this->session->set($module . 'searchParams', $searchParams);
}
@@ -96,9 +120,9 @@ class searchModel extends model
{
/* Init vars. */
$module = $this->post->module;
$searchParams = $module . 'searchParams';
$searchFields = json_decode($_SESSION[$searchParams]['searchFields']);
$fieldParams = json_decode($_SESSION[$searchParams]['fieldParams']);
$searchConfig = $this->processSearchParams($module, true);
$searchFields = $searchConfig['fields'];
$fieldParams = $searchConfig['params'];
$groupItems = $this->config->search->groupItems;
$groupAndOr = strtoupper($this->post->groupAndOr);
if($groupAndOr != 'AND' && $groupAndOr != 'OR') $groupAndOr = 'AND';
@@ -122,12 +146,12 @@ class searchModel extends model
$field = $this->post->$fieldName;
$value = $this->post->$valueName;
$fieldControl = isset($fieldParams->$field) && isset($fieldParams->{$field}->control) ? $fieldParams->{$field}->control : '';
$fieldControl = $fieldParams[$field]['control'] ?? '';
if(empty($field) || $value === '' || $value === false) continue; // false means no exist this post item. '' means no search data. ignore it.
if(!preg_match('/^[a-zA-Z0-9]+$/', $field)) continue; // Fix sql injection.
/* 如果是输入框,并且输入框的值为'0',或者 id 的值为'0',将值设置为zero。*/
if(isset($fieldParams->$field) && $fieldControl == 'input' && $value === '0') $this->post->set($valueName, 'ZERO');
if($fieldControl == 'input' && $value === '0') $this->post->set($valueName, 'ZERO');
if($field == 'id' && $value === '0') $this->post->set($valueName, 'ZERO');
/* set queryForm. */
@@ -169,8 +193,8 @@ class searchModel extends model
$groupItems = $this->config->search->groupItems;
$groupAndOr = strtoupper($this->post->groupAndOr);
$module = $this->post->module;
$searchParams = $module . 'searchParams';
$fieldParams = json_decode($_SESSION[$searchParams]['fieldParams']);
$searchConfig = $this->processSearchParams($module, true);
$fieldParams = $searchConfig['params'];
$scoreNum = 0;
if($groupAndOr != 'AND' and $groupAndOr != 'OR') $groupAndOr = 'AND';
@@ -190,13 +214,15 @@ class searchModel extends model
/* Fix bug #2704. */
$field = $this->post->$fieldName;
if(!preg_match('/^[a-zA-Z0-9]+$/', $field)) continue; // Fix sql injection.
if(isset($fieldParams->$field) and $fieldParams->$field->control == 'input' and $this->post->$valueName === '0') $this->post->set($valueName, 'ZERO');
$fieldControl = $fieldParams[$field]['control'] ?? '';
if($fieldControl == 'input' and $this->post->$valueName === '0') $this->post->set($valueName, 'ZERO');
if($field == 'id' and $this->post->$valueName === '0') $this->post->set($valueName, 'ZERO');
/* Skip empty values. */
if($this->post->$valueName == false) continue;
if($this->post->$valueName == 'ZERO') $this->post->$valueName = 0; // ZERO is special, stands to 0.
if(isset($fieldParams->$field) and $fieldParams->$field->control == 'select' and $this->post->$valueName === 'null') $this->post->set($valueName, ''); // Null is special, stands to empty if control is select. Fix bug #3279.
if($fieldControl == 'select' and $this->post->$valueName === 'null') $this->post->set($valueName, ''); // Null is special, stands to empty if control is select. Fix bug #3279.
$scoreNum += 1;
@@ -220,7 +246,7 @@ class searchModel extends model
}
else
{
$condition = $fieldParams->$field->control == 'select' ? " LIKE CONCAT('%,', '{$value}', ',%')" : ' LIKE ' . $this->dbh->quote("%$value%");
$condition = $fieldControl == 'select' ? " LIKE CONCAT('%,', '{$value}', ',%')" : ' LIKE ' . $this->dbh->quote("%$value%");
}
}
elseif($operator == "notinclude")
@@ -232,7 +258,7 @@ class searchModel extends model
}
else
{
$condition = $fieldParams->$field->control == 'select' ? " NOT LIKE CONCAT('%,', '{$value}', ',%')" : ' NOT LIKE ' . $this->dbh->quote("%$value%");
$condition = $fieldControl == 'select' ? " NOT LIKE CONCAT('%,', '{$value}', ',%')" : ' NOT LIKE ' . $this->dbh->quote("%$value%");
}
}
elseif($operator == 'belong')
+7 -8
View File
@@ -76,15 +76,14 @@ class searchTao extends searchModel
* 初始化搜索表单,并且保存到 session。
* Init the search session for the first time search.
*
* @param string $module
* @param object|array $fields
* @param object|array $fieldParams
* @param string $module
* @param array $fields
* @param array $fieldParams
* @access public
* @return array
*/
public function initSession(string $module, object|array $fields, object|array $fieldParams): array
public function initSession(string $module, array $fields, array $fieldParams): array
{
if(is_object($fields)) $fields = get_object_vars($fields);
$formSessionName = $module . 'Form';
$queryForm = array();
@@ -143,7 +142,7 @@ class searchTao extends searchModel
* 处理查询表单的相关数据。
* Process query form datas.
*
* @param object $fieldParams
* @param array $fieldParams
* @param string $field
* @param string $andOrName
* @param string $operatorName
@@ -151,7 +150,7 @@ class searchTao extends searchModel
* @access public
* @return array
*/
public function processQueryFormDatas(object $fieldParams, string $field, string $andOrName, string $operatorName, string $valueName): array
public function processQueryFormDatas(array $fieldParams, string $field, string $andOrName, string $operatorName, string $valueName): array
{
/* 设置分组之间的逻辑关系。*/
/* Set and or. */
@@ -167,7 +166,7 @@ class searchTao extends searchModel
/* Skip empty values. */
$value = $this->post->$valueName;
if($value == 'ZERO') $this->post->set($valueName, 0); // ZERO is special, stands to 0.
if(isset($fieldParams->$field) && $fieldParams->$field->control == 'select' && $value === 'null') $this->post->set($valueName, ''); // Null is special, stands to empty if control is select.
if(isset($fieldParams[$field]) && $fieldParams[$field]['control'] == 'select' && $value === 'null') $this->post->set($valueName, ''); // Null is special, stands to empty if control is select.
$value = addcslashes(trim((string)$this->post->{$valueName}), '%');
return array($andOr, $operator, $value);