* Refactor myModel::getRequirement, and modify its unit test.
This commit is contained in:
+7
-42
@@ -835,6 +835,7 @@ class myModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过搜索获取用户需求。
|
||||
* Get requirements by search.
|
||||
*
|
||||
* @param int $queryID
|
||||
@@ -844,7 +845,7 @@ class myModel extends model
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getRequirementsBySearch($queryID, $type, $orderBy, $pager)
|
||||
public function getRequirementsBySearch(int $queryID, string $type, string $orderBy, object $pager = null): array
|
||||
{
|
||||
$queryName = $type == 'contribute' ? 'contributeRequirementQuery' : 'workRequirementQuery';
|
||||
$queryForm = $type == 'contribute' ? 'contributeRequirementForm' : 'workRequirementForm';
|
||||
@@ -863,52 +864,16 @@ class myModel extends model
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->session->$queryName == false) $this->session->set($queryName, ' 1 = 1');
|
||||
if($this->session->{$queryName} == false) $this->session->set($queryName, ' 1 = 1');
|
||||
}
|
||||
|
||||
$myRequirementQuery = $this->session->$queryName;
|
||||
$myRequirementQuery = $this->session->{$queryName};
|
||||
$myRequirementQuery = preg_replace('/`(\w+)`/', 't1.`$1`', $myRequirementQuery);
|
||||
|
||||
$requirementIDList = array();
|
||||
if($type == 'contribute')
|
||||
{
|
||||
$requirementsAssignedByMe = $this->getAssignedByMe($this->app->user->account, null, $orderBy, 'requirement');
|
||||
foreach($requirementsAssignedByMe as $requirementID => $requirement)
|
||||
{
|
||||
$requirementIDList[$requirementID] = $requirementID;
|
||||
}
|
||||
$requirementsAssignedByMe = $type == 'contribute' ? $this->getAssignedByMe($this->app->user->account, null, $orderBy, 'requirement') : array();
|
||||
$requirementIdList = array_keys($requirementsAssignedByMe);
|
||||
|
||||
$requirements = $this->dao->select("distinct t1.*, IF(t1.`pri` = 0, {$this->config->maxPriValue}, t1.`pri`) as priOrder, t2.name as productTitle")->from(TABLE_STORY)->alias('t1')
|
||||
->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id')
|
||||
->leftJoin(TABLE_STORYREVIEW)->alias('t3')->on('t1.id = t3.story')
|
||||
->where($myRequirementQuery)
|
||||
->andWhere('t1.type')->eq('requirement')
|
||||
->andWhere('t1.openedBy',1)->eq($this->app->user->account)
|
||||
->orWhere('t1.closedBy')->eq($this->app->user->account)
|
||||
->orWhere('t3.reviewer')->eq($this->app->user->account)
|
||||
->orWhere('t1.id')->in($requirementIDList)
|
||||
->markRight(1)
|
||||
->andWhere('t1.deleted')->eq(0)
|
||||
->orderBy($orderBy)
|
||||
->page($pager, 't1.id')
|
||||
->fetchAll('id');
|
||||
}
|
||||
else
|
||||
{
|
||||
$requirements = $this->dao->select("distinct t1.*, IF(t1.`pri` = 0, {$this->config->maxPriValue}, t1.`pri`) as priOrder, t2.name as productTitle")->from(TABLE_STORY)->alias('t1')
|
||||
->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id')
|
||||
->leftJoin(TABLE_STORYREVIEW)->alias('t3')->on('t1.id = t3.story')
|
||||
->where($myRequirementQuery)
|
||||
->andWhere('t1.type')->eq('requirement')
|
||||
->andWhere('t1.assignedTo',1)->eq($this->app->user->account)
|
||||
->orWhere('t3.reviewer')->eq($this->app->user->account)
|
||||
->markRight(1)
|
||||
->andWhere('t1.deleted')->eq(0)
|
||||
->orderBy($orderBy)
|
||||
->page($pager, 't1.id')
|
||||
->fetchAll('id');
|
||||
}
|
||||
return $requirements;
|
||||
return $this->myTao->fetchRequirementsBySearch($myRequirementQuery, $type, $orderBy, $pager, $requirementIdList, 'requirement');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+49
-1
@@ -166,5 +166,53 @@ class myTao extends myModel
|
||||
}
|
||||
return $stories;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过搜索查找用户需求。
|
||||
* Fetch requirements by search.
|
||||
*
|
||||
* @param string $myRequirementQuery
|
||||
* @param string $type
|
||||
* @param string $orderBy
|
||||
* @param object $pager
|
||||
* @param array $requirementIDList
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function fetchRequirementsBySearch(string $myRequirementQuery, string $type, string $orderBy, object $pager = null, array $requirementIDList = array()): array
|
||||
{
|
||||
if($type == 'contribute')
|
||||
{
|
||||
$requirements = $this->dao->select("distinct t1.*, IF(t1.`pri` = 0, {$this->config->maxPriValue}, t1.`pri`) as priOrder, t2.name as productTitle")->from(TABLE_STORY)->alias('t1')
|
||||
->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id')
|
||||
->leftJoin(TABLE_STORYREVIEW)->alias('t3')->on('t1.id = t3.story')
|
||||
->where($myRequirementQuery)
|
||||
->andWhere('t1.type')->eq('requirement')
|
||||
->andWhere('t1.openedBy',1)->eq($this->app->user->account)
|
||||
->orWhere('t1.closedBy')->eq($this->app->user->account)
|
||||
->orWhere('t3.reviewer')->eq($this->app->user->account)
|
||||
->orWhere('t1.id')->in($requirementIDList)
|
||||
->markRight(1)
|
||||
->andWhere('t1.deleted')->eq(0)
|
||||
->orderBy($orderBy)
|
||||
->page($pager, 't1.id')
|
||||
->fetchAll('id');
|
||||
}
|
||||
else
|
||||
{
|
||||
$requirements = $this->dao->select("distinct t1.*, IF(t1.`pri` = 0, {$this->config->maxPriValue}, t1.`pri`) as priOrder, t2.name as productTitle")->from(TABLE_STORY)->alias('t1')
|
||||
->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id')
|
||||
->leftJoin(TABLE_STORYREVIEW)->alias('t3')->on('t1.id = t3.story')
|
||||
->where($myRequirementQuery)
|
||||
->andWhere('t1.type')->eq('requirement')
|
||||
->andWhere('t1.assignedTo',1)->eq($this->app->user->account)
|
||||
->orWhere('t3.reviewer')->eq($this->app->user->account)
|
||||
->markRight(1)
|
||||
->andWhere('t1.deleted')->eq(0)
|
||||
->orderBy($orderBy)
|
||||
->page($pager, 't1.id')
|
||||
->fetchAll('id');
|
||||
}
|
||||
return $requirements;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/my.class.php';
|
||||
|
||||
zdTable('story')->config('story')->gen('20');
|
||||
zdTable('product')->gen('10');
|
||||
zdTable('productplan')->gen('15');
|
||||
zdTable('planstory')->gen('20');
|
||||
zdTable('userquery')->config('userquery')->gen('2');
|
||||
zdTable('user')->gen('1');
|
||||
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
@@ -10,16 +18,17 @@ title=测试 myModel->getRequirementsBySearch();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
获取requirement状态的项目 >> 用户需求397,draft
|
||||
获取requirement状态的项目 >> 用户需求1,active
|
||||
|
||||
*/
|
||||
|
||||
$my = new myTest();
|
||||
$queryID = array(0, 2);
|
||||
$typeList = array('contribute', 'other');
|
||||
$orderBy = array('id_desc', 'id_asc');
|
||||
|
||||
$requirement1 = $my->getRequirementsBySearchTest(0, $typeList[0], $orderBy[0]);
|
||||
$requirement2 = $my->getRequirementsBySearchTest(0, $typeList[1], $orderBy[1]);
|
||||
r($requirement1) && p('397:title,status') && e('用户需求397,draft');//获取requirement状态的项目
|
||||
r($requirement2) && p('1:title,status') && e('用户需求1,active'); //获取requirement状态的项目
|
||||
r($my->getRequirementsBySearchTest($queryID[0], $typeList[0], $orderBy[0])) && p() && e('9,5'); // 测试获取 queryID 0 类型 contribute 排序 id_desc 的需求。
|
||||
r($my->getRequirementsBySearchTest($queryID[0], $typeList[0], $orderBy[1])) && p() && e('5,9'); // 测试获取 queryID 0 类型 contribute 排序 id_asc 的需求。
|
||||
r($my->getRequirementsBySearchTest($queryID[0], $typeList[1], $orderBy[0])) && p() && e('19,10,4'); // 测试获取 queryID 0 类型 other 排序 id_desc 的需求。
|
||||
r($my->getRequirementsBySearchTest($queryID[0], $typeList[1], $orderBy[1])) && p() && e('4,10,19'); // 测试获取 queryID 0 类型 other 排序 id_asc 的需求。
|
||||
r($my->getRequirementsBySearchTest($queryID[1], $typeList[0], $orderBy[0])) && p() && e('0'); // 测试获取 queryID 1 类型 contribute 排序 id_desc 的需求。
|
||||
r($my->getRequirementsBySearchTest($queryID[1], $typeList[0], $orderBy[1])) && p() && e('0'); // 测试获取 queryID 1 类型 contribute 排序 id_asc 的需求。
|
||||
r($my->getRequirementsBySearchTest($queryID[1], $typeList[1], $orderBy[0])) && p() && e('19,10'); // 测试获取 queryID 1 类型 other 排序 id_desc 的需求。
|
||||
r($my->getRequirementsBySearchTest($queryID[1], $typeList[1], $orderBy[1])) && p() && e('10,19'); // 测试获取 queryID 1 类型 other 排序 id_asc 的需求。
|
||||
|
||||
@@ -165,28 +165,22 @@ class myTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Get requirements by search.
|
||||
* 测试通过搜索获取用户需求。
|
||||
* Test get requirements by search.
|
||||
*
|
||||
* @param int $queryID
|
||||
* @param string $type
|
||||
* @param string $orderBy
|
||||
* @param int $queryID
|
||||
* @param string $type
|
||||
* @param string $orderBy
|
||||
* @access public
|
||||
* @return array
|
||||
* @return string|array
|
||||
*/
|
||||
public function getRequirementsBySearchTest($queryID, $type, $orderBy)
|
||||
public function getRequirementsBySearchTest(int $queryID, string $type, string $orderBy): string|array
|
||||
{
|
||||
global $tester;
|
||||
$recTotal = 0;
|
||||
$recPerPage = 1;
|
||||
$pageID = 0;
|
||||
$tester->app->loadClass('pager', $static = true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
$objects = $this->objectModel->getRequirementsBySearch($queryID, $type, $orderBy, $pager);
|
||||
$objects = $this->objectModel->getRequirementsBySearch($queryID, $type, $orderBy);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
return implode(',', array_keys($objects));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,9 +24,6 @@ fields:
|
||||
postfix: ""
|
||||
loop: 0
|
||||
format: ""
|
||||
- field: project
|
||||
note: "所属项目"
|
||||
range: 0
|
||||
- field: module
|
||||
note: "所属模块"
|
||||
range: 1821-10000
|
||||
|
||||
Reference in New Issue
Block a user