diff --git a/module/common/control.php b/module/common/control.php index 43a485199d..95545adc30 100644 --- a/module/common/control.php +++ b/module/common/control.php @@ -328,7 +328,7 @@ class common extends control * @access public * @return void */ - static public function printRPN($backLink, $preAndNext = '') + static public function printRPN($backLink, $preAndNext = '', $linkTemplate = '') { global $lang, $app; if(isonlybody()) return false; @@ -340,14 +340,16 @@ class common extends control $id = (isset($_SESSION['testcaseOnlyCondition']) and !$_SESSION['testcaseOnlyCondition'] and $app->getModuleName() == 'testcase' and isset($preAndNext->pre->case)) ? 'case' : 'id'; $title = isset($preAndNext->pre->title) ? $preAndNext->pre->title : $preAndNext->pre->name; $title = '#' . $preAndNext->pre->$id . ' ' . $title; - echo html::a(inLink('view', "ID={$preAndNext->pre->$id}"), '', '', "id='pre' class='btn' title='{$title}'"); + $link = $linkTemplate ? sprintf($linkTemplate, $preAndNext->pre->$id) : inLink('view', "ID={$preAndNext->pre->$id}"); + echo html::a($link, '', '', "id='pre' class='btn' title='{$title}'"); } if(isset($preAndNext->next) and $preAndNext->next) { $id = (isset($_SESSION['testcaseOnlyCondition']) and !$_SESSION['testcaseOnlyCondition'] and $app->getModuleName() == 'testcase' and isset($preAndNext->next->case)) ? 'case' : 'id'; $title = isset($preAndNext->next->title) ? $preAndNext->next->title : $preAndNext->next->name; $title = '#' . $preAndNext->next->$id . ' ' . $title; - echo html::a(inLink('view', "ID={$preAndNext->next->$id}"), '', '', "id='next' class='btn' title='$title'"); + $link = $linkTemplate ? sprintf($linkTemplate, $preAndNext->next->$id) : inLink('view', "ID={$preAndNext->next->$id}"); + echo html::a($link, '', '', "id='next' class='btn' title='$title'"); } } diff --git a/module/common/model.php b/module/common/model.php index c356de2a3e..c89c3d71f6 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -658,40 +658,39 @@ class commonModel extends model if(empty($queryCondition) or $this->session->$typeOnlyCondition) { - $objects = $this->dao->select('*')->from($table) - ->where('id')->eq($objectID) + $queryObjects = $this->dao->select('*')->from($table)->where('id')->eq($objectID) ->beginIF($queryCondition != false)->orWhere($queryCondition)->fi() ->beginIF($orderBy != false)->orderBy($orderBy)->fi() - ->fetchPairs('id', 'id'); - $tmpIDs = ',' . join(',', $objects) . ','; + ->query(); } else { - $queryObjects = $this->dao->query($queryCondition . " ORDER BY $orderBy")->fetchAll(); - $objects = array(); - $tmpIDs = ','; - foreach($queryObjects as $key => $object) - { - $id = ($type == 'testcase' and isset($object->case)) ? $object->case : $object->id; - $objects[$id] = $object; - $tmpIDs .= $id . ','; - } + $queryObjects = $this->dao->query($queryCondition . " ORDER BY $orderBy"); } - /* Get pre and next ID. */ - $currentStart = strpos($tmpIDs, ',' . $objectID . ','); - $currentEnd = $currentStart + strlen($objectID) + 1; - $preTag = strrpos(substr($tmpIDs, 0, $currentStart), ','); - $nextTag = strpos($tmpIDs, ',', $currentEnd + 1); - $pre = $preTag === false ? '' : substr($tmpIDs, $preTag + 1, $currentStart - $preTag - 1); - $next = $nextTag === false ? '' : substr($tmpIDs, $currentEnd + 1, $nextTag - $currentEnd - 1); - - /* Set pre and next object. */ + $preObj = false; $preAndNextObject->pre = ''; $preAndNextObject->next = ''; - if(empty($queryCondition) or $this->session->$typeOnlyCondition) $objects = $this->dao->select('*')->from($table)->where('id')->in("$pre,$next")->fetchAll('id'); - if(isset($objects[$pre])) $preAndNextObject->pre = $objects[$pre]; - if(isset($objects[$next])) $preAndNextObject->next = $objects[$next]; + while($object = $queryObjects->fetch()) + { + $key = (!$this->session->$typeOnlyCondition and $type == 'testcase' and isset($object->case)) ? 'case' : 'id'; + $id = $object->$key; + + /* Get next object. */ + if($preObj === true) + { + $preAndNextObject->next = $object; + break; + } + + /* Get pre object. */ + if($id == $objectID) + { + if($preObj) $preAndNextObject->pre = $preObj; + $preObj = true; + } + if($preObj !== true) $preObj = $object; + } return $preAndNextObject; } diff --git a/module/testcase/control.php b/module/testcase/control.php index da7a2aae99..c43fbd33d0 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -433,14 +433,16 @@ class testcase extends control * @access public * @return void */ - public function view($caseID, $version = 0, $from = 'testcase') + public function view($caseID, $version = 0, $from = 'testcase', $taskID = 0) { $case = $this->testcase->getById($caseID, $version); if(!$case) die(js::error($this->lang->notFound) . js::locate('back')); + if($from == 'testtask') $run = $this->loadModel('testtask')->getRunByCase($taskID, $caseID); $productID = $case->product; $this->testcase->setMenu($this->products, $productID); + $this->view->title = "CASE #$case->id $case->title - " . $this->products[$productID]; $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $this->view->position[] = $this->lang->testcase->common; @@ -448,12 +450,14 @@ class testcase extends control $this->view->case = $case; $this->view->from = $from; + $this->view->taskID = $taskID; $this->view->version = $version ? $version : $case->version; $this->view->productName = $this->products[$productID]; $this->view->modulePath = $this->tree->getParents($case->module); $this->view->users = $this->user->getPairs('noletter'); $this->view->actions = $this->loadModel('action')->getList('case', $caseID); $this->view->preAndNext = $this->loadModel('common')->getPreAndNextObject('testcase', $caseID); + $this->view->runID = $from == 'testcase' ? 0 : $run->id; $this->display(); } diff --git a/module/testcase/view/view.html.php b/module/testcase/view/view.html.php index b5e6614653..6c255ce2d3 100644 --- a/module/testcase/view/view.html.php +++ b/module/testcase/view/view.html.php @@ -43,10 +43,10 @@ ob_start(); echo "
"; - common::printIcon('testtask', 'runCase', "runID=0&caseID=$case->id&version=$case->currentVersion", '', 'button', '', '', 'runCase'); - common::printIcon('testtask', 'results', "runID=0&caseID=$case->id&version=$case->version", '', 'button', '', '', 'results'); + common::printIcon('testtask', 'runCase', "runID=$runID&caseID=$case->id&version=$case->currentVersion", '', 'button', '', '', 'runCase'); + common::printIcon('testtask', 'results', "runID=$runID&caseID=$case->id&version=$case->version", '', 'button', '', '', 'results'); - if($case->lastRunResult == 'fail') common::printIcon('testcase', 'createBug', "product=$case->product&extra=caseID=$case->id,version=$case->version,runID=", '', 'button', 'bug', '', 'iframe'); + if($case->lastRunResult == 'fail') common::printIcon('testcase', 'createBug', "product=$case->product&extra=caseID=$case->id,version=$case->version,runID=$runID", '', 'button', 'bug', '', 'iframe'); echo '
'; echo "
"; @@ -57,7 +57,7 @@ echo '
'; echo "
"; - common::printRPN($browseLink, $preAndNext); + common::printRPN($browseLink, $preAndNext, inlink('view', "caseID=%s&version=0&testtask=$from&taskID=$taskID")); echo '
'; $actionLinks = ob_get_contents(); diff --git a/module/testtask/model.php b/module/testtask/model.php index d84e8ece54..7d3b8a1a3d 100644 --- a/module/testtask/model.php +++ b/module/testtask/model.php @@ -118,6 +118,19 @@ class testtaskModel extends model return $task; } + /** + * Get taskrun by case id. + * + * @param int $taskID + * @param int $caseID + * @access public + * @return void + */ + public function getRunByCase($taskID, $caseID) + { + return $this->dao->select('*')->from(TABLE_TESTRUN)->where('task')->eq($taskID)->andWhere('`case`')->eq($caseID)->fetch(); + } + /** * Get test tasks by user. * diff --git a/module/testtask/view/cases.html.php b/module/testtask/view/cases.html.php index 973a3e4f63..3d5b7ab35b 100644 --- a/module/testtask/view/cases.html.php +++ b/module/testtask/view/cases.html.php @@ -62,7 +62,7 @@ var moduleID = ''; case);?> testcase->priList, $run->pri, $run->pri)?>'>testcase->priList, $run->pri, $run->pri)?> - createLink('testcase', 'view', "caseID=$run->case&version=$run->version&from=testtask"), $run->title, '_blank');?> + createLink('testcase', 'view', "caseID=$run->case&version=$run->version&from=testtask&taskID=$run->task"), $run->title, '_blank');?> testcase->typeList[$run->type];?> assignedTo]; echo substr($assignedTo, strpos($assignedTo, ':') + 1);?>