* Refactor getBugs2Link function.
This commit is contained in:
@@ -1039,7 +1039,7 @@ class bug extends control
|
||||
* Link related bugs.
|
||||
*
|
||||
* @param int $bugID
|
||||
* @param string $browseType
|
||||
* @param bool $bySearch
|
||||
* @param string $excludeBugs
|
||||
* @param int $queryID
|
||||
* @param int $recTotal
|
||||
@@ -1048,7 +1048,7 @@ class bug extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function linkBugs(int $bugID, string $browseType = '', string $excludeBugs = '', int $queryID = 0, int $recTotal = 0, int $recPerPage = 20, int $pageID = 1)
|
||||
public function linkBugs(int $bugID, bool $bySearch = false, string $excludeBugs = '', int $queryID = 0, int $recTotal = 0, int $recPerPage = 20, int $pageID = 1)
|
||||
{
|
||||
$bug = $this->bug->getByID($bugID);
|
||||
|
||||
@@ -1065,9 +1065,9 @@ class bug extends control
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
/* Assign. */
|
||||
$this->view->title = $this->lang->bug->linkBugs . "BUG #$bug->id $bug->title $this->lang->dash " . $this->products[$bug->product];
|
||||
$this->view->title = $this->lang->bug->linkBugs . "BUG #$bug->id $bug->title {$this->lang->dash} " . $this->products[$bug->product];
|
||||
$this->view->bug = $bug;
|
||||
$this->view->bugs2Link = $this->bug->getBugs2Link($bugID, $browseType, $queryID, $pager, $excludeBugs);
|
||||
$this->view->bugs2Link = $this->bug->getBugs2Link($bugID, $bySearch, $excludeBugs, $queryID, $pager);
|
||||
$this->view->users = $this->user->getPairs('noletter');
|
||||
$this->view->pager = $pager;
|
||||
$this->display();
|
||||
|
||||
@@ -34,7 +34,7 @@ $(function()
|
||||
bugIdList += $(this).val() + ',';
|
||||
});
|
||||
|
||||
var link = createLink('bug', 'linkBugs', 'bugID=' + bugID + '&browseType=&excludeBugs=' + bugIdList, '', true);
|
||||
var link = createLink('bug', 'linkBugs', 'bugID=' + bugID + '&bySearch=&excludeBugs=' + bugIdList, '', true);
|
||||
|
||||
var modalTrigger = new $.zui.ModalTrigger({type: 'iframe', width: '95%', url: link});
|
||||
modalTrigger.show();
|
||||
|
||||
+18
-21
@@ -1134,37 +1134,34 @@ class bugModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可以关联的 bug 列表。
|
||||
* Get bugs to link.
|
||||
*
|
||||
* @param int $bugID
|
||||
* @param string $browseType
|
||||
* @param bool $bySearch
|
||||
* @param int $queryID
|
||||
* @param object $pager
|
||||
* @param string $excludeBugs
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getBugs2Link($bugID, $browseType = 'bySearch', $queryID = 0, $pager = null, $excludeBugs = '')
|
||||
public function getBugs2Link(int $bugID, bool $bySearch = false, string $excludeBugs = '', int $queryID = 0, object $pager = null): array
|
||||
{
|
||||
$bug = $this->getById($bugID);
|
||||
$bugIDList = $bug->id . ',' . $bug->linkBug . ',' . $excludeBugs;
|
||||
$bug = $this->getByID($bugID);
|
||||
|
||||
if($browseType == 'bySearch')
|
||||
{
|
||||
return $this->bugTao->getBySearch((array)$bug->product, 'all', 0, $queryID, $bugIDList, 'id', $pager);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_BUG)
|
||||
->where('deleted')->eq('0')
|
||||
->andWhere('id')->notin($bugIDList)
|
||||
->andWhere('product')->eq($bug->product)
|
||||
->beginIF($bug->project)->andWhere('project')->eq($bug->project)->fi()
|
||||
->beginIF($bug->execution)->andWhere('execution')->eq($bug->execution)->fi()
|
||||
->orderBy('id desc')
|
||||
->page($pager)
|
||||
->fetchAll();
|
||||
}
|
||||
$excludeBugs .= ",{$bug->id},{$bug->linkBug}";
|
||||
|
||||
if($bySearch) return $this->bugTao->getBySearch((array)$bug->product, $branch = 'all', $projectID = 0, $queryID, $excludeBugs, $orderBy = 'id desc', $pager);
|
||||
|
||||
return $this->dao->select('*')->from(TABLE_BUG)
|
||||
->where('deleted')->eq('0')
|
||||
->andWhere('id')->notin($excludeBugs)
|
||||
->andWhere('product')->eq($bug->product)
|
||||
->beginIF($bug->project)->andWhere('project')->eq($bug->project)->fi()
|
||||
->beginIF($bug->execution)->andWhere('execution')->eq($bug->execution)->fi()
|
||||
->orderBy('id desc')
|
||||
->page($pager)
|
||||
->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=bugModel->getBugs2Link();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 获取和 bug1 相同产品下的 bug 列表,第一个 bug 的标题是 BUG9第0条的title属性 @BUG9
|
||||
|
||||
- 获取和 bug1 相同产品下并且不包含 bug9 的 bug 列表,第一个 bug 的标题是 BUG7第0条的title属性 @BUG7
|
||||
|
||||
- 搜索和 bug2 相同产品下的 bug 列表,第一个 bug 的标题是 BUG10第0条的title属性 @BUG10
|
||||
|
||||
- 搜索和 bug2 相同产品下并且不包含 bug4 的 bug 列表,第一个 bug 的标题是 BUG8第0条的title属性 @BUG8
|
||||
|
||||
*/
|
||||
|
||||
function initData()
|
||||
{
|
||||
$bug = zdTable('bug');
|
||||
$bug->id->range('1-10');
|
||||
$bug->product->range('1,2');
|
||||
$bug->branch->range('0,1');
|
||||
$bug->project->range('0,2');
|
||||
$bug->execution->range('0,3');
|
||||
$bug->module->range('1,0');
|
||||
$bug->title->prefix("BUG")->range('1-10');
|
||||
$bug->status->range("resolved,active,closed");
|
||||
$bug->plan->range('1,0');
|
||||
$bug->assignedTo->range('admin');
|
||||
$bug->openedBy->range('admin');
|
||||
$bug->resolvedBy->range('admin');
|
||||
$bug->confirmed->range('0,1');
|
||||
$bug->resolution->range('postponed,fixed');
|
||||
$bug->openedBuild->range('trunk');
|
||||
$bug->gen(10);
|
||||
}
|
||||
|
||||
initData();
|
||||
|
||||
$bugIdList = array(1,2);
|
||||
$bySearch = array(false, true);
|
||||
$excludeBugs = array('', '9', '10');
|
||||
|
||||
global $tester;
|
||||
$bug = $tester->loadModel('bug');
|
||||
r($bug->getBugs2Link($bugIdList[0], $bySearch[0], $excludeBugs[0])) && p('0:title') && e('BUG9'); //获取和 bug1 相同产品下的 bug 列表,第一个 bug 的标题是 BUG9
|
||||
r($bug->getBugs2Link($bugIdList[0], $bySearch[0], $excludeBugs[1])) && p('0:title') && e('BUG7'); //获取和 bug1 相同产品下并且不包含 bug9 的 bug 列表,第一个 bug 的标题是 BUG7
|
||||
r($bug->getBugs2Link($bugIdList[1], $bySearch[1], $excludeBugs[0])) && p('0:title') && e('BUG10'); //搜索和 bug2 相同产品下的 bug 列表,第一个 bug 的标题是 BUG10
|
||||
r($bug->getBugs2Link($bugIdList[1], $bySearch[1], $excludeBugs[2])) && p('0:title') && e('BUG8'); //搜索和 bug2 相同产品下并且不包含 bug4 的 bug 列表,第一个 bug 的标题是 BUG8
|
||||
+1
-1
@@ -1966,7 +1966,7 @@ class bugZen extends bug
|
||||
}
|
||||
}
|
||||
|
||||
$actionURL = $this->createLink('bug', 'linkBugs', "bugID={$bug->id}&browseType=bySearch&excludeBugs={$excludeBugs}&queryID=myQueryID", '', true);
|
||||
$actionURL = $this->createLink('bug', 'linkBugs', "bugID={$bug->id}&bySearch=true&excludeBugs={$excludeBugs}&queryID=myQueryID", '', true);
|
||||
$this->bug->buildSearchForm($bug->product, $this->products, $queryID, $actionURL);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user