diff --git a/module/common/model.php b/module/common/model.php index a20090c471..2b02ef51ae 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -509,69 +509,48 @@ class commonModel extends model if(strpos('story, task, bug, testcase, doc', $type) === false) return $preAndNextObject; $table = $this->config->objectTables[$type]; - $typeIDs = $type . 'IDs'; - if($this->session->$typeIDs and strpos($this->session->$typeIDs, ',' . $objectID . ',') !== false) + /* Get objectIDs. */ + $queryCondition = $type . 'QueryCondition'; + $typeOnlyCondition = $type . 'OnlyCondition'; + $queryCondition = $this->session->$queryCondition; + $orderBy = $type . 'OrderBy'; + $orderBy = $this->session->$orderBy; + $orderBy = str_replace('`left`', 'left', $orderBy); // process the `left` to left. + + if(empty($queryCondition) or $this->session->$typeOnlyCondition) { - $objectIDs = $this->session->$typeIDs; - $this->session->set($typeIDs, ''); + $objects = $this->dao->select('*')->from($table) + ->beginIF($queryCondition != false)->where($queryCondition)->fi() + ->beginIF($orderBy != false)->orderBy($orderBy)->fi() + ->fetchAll(); } else { - /* Get objectIDs. */ - $queryCondition = $type . 'QueryCondition'; - $typeOnlyCondition = $type . 'OnlyCondition'; - $queryCondition = $this->session->$queryCondition; - $orderBy = $type . 'OrderBy'; - $orderBy = $this->session->$orderBy; - $orderBy = str_replace('`left`', 'left', $orderBy); // process the `left` to left. - - if(empty($queryCondition) or $this->session->$typeOnlyCondition) - { - $objects = $this->dao->select('*')->from($table) - ->beginIF($queryCondition != false)->where($queryCondition)->fi() - ->beginIF($orderBy != false)->orderBy($orderBy)->fi() - ->fetchAll(); - } - else - { - $objects = $this->dbh->query($queryCondition . " ORDER BY $orderBy")->fetchAll(); - } - - $tmpObjectIDs = array(); - foreach($objects as $object) $tmpObjectIDs[$object->id] = (!$this->session->$typeOnlyCondition and $type == 'testcase' and isset($object->case)) ? $object->case : $object->id; - $objectIDs = ',' . implode(',', $tmpObjectIDs) . ','; - $this->session->set($type . 'IDs', $objectIDs); + $objects = $this->dbh->query($queryCondition . " ORDER BY $orderBy")->fetchAll(); } + $tmpObjectIDs = array(); + foreach($objects as $key => $object) $tmpObjectIDs[$key] = (!$this->session->$typeOnlyCondition and $type == 'testcase' and isset($object->case)) ? $object->case : $object->id; + $objectIDs = array_flip($tmpObjectIDs); + /* Current object. */ - $currentStart = strpos($objectIDs, ',' . $objectID . ',') + 1; - $currentEnd = $currentStart + strlen($objectID) - 1; + $currentKey = array_search($objectID, $tmpObjectIDs); - /* Get the previous object. */ - $tmp = substr($objectIDs, 0, $currentStart - 1); - $preStart = strrpos($tmp, ',', 0) + 1; - $preEnd = $currentStart - 2; - if($preEnd - $preStart < 0) + $preKey = $currentKey - 1; + $preAndNextObject->pre = ''; + if($preKey >= 0) { - $preAndNextObject->pre = ''; - } - else - { - $preID = substr($objectIDs, $preStart, $preEnd - $preStart + 1); - $preAndNextObject->pre = $this->dao->select('*')->from($table)->where('id')->eq($preID)->fetch(); + $preID = $tmpObjectIDs[$preKey]; + $preAndNextObject->pre = $objects[$objectIDs[$preID]]; } /* Get the next object. */ - $nextStart = $currentEnd + 2; - $nextEnd = strlen($objectIDs) > $nextStart ? strpos($objectIDs, ',', $nextStart) - 1 : 0; - if($nextEnd - $nextStart < 0) + $nextKey = $currentKey + 1; + $preAndNextObject->next = ''; + if($nextKey < count($tmpObjectIDs)) { - $preAndNextObject->next = ''; - } - else - { - $nextID = substr($objectIDs, $nextStart, $nextEnd - $nextStart + 1); - $preAndNextObject->next = $this->dao->select('*')->from($table)->where('id')->eq($nextID)->fetch(); + $nextID = $tmpObjectIDs[$nextKey]; + $preAndNextObject->next = $objects[$objectIDs[$nextID]]; } return $preAndNextObject; diff --git a/module/my/control.php b/module/my/control.php index db59f1815f..fcd0ea9685 100644 --- a/module/my/control.php +++ b/module/my/control.php @@ -304,6 +304,7 @@ class my extends control ->andWhere('t1.status')->ne('done') ->andWhere('t3.status')->ne('done') ->orderBy($orderBy)->page($pager)->fetchAll(); + $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', false); } elseif($type == 'donebyme') { @@ -312,14 +313,15 @@ class my extends control ->Where('t1.assignedTo')->eq($this->app->user->account) ->andWhere('t1.status')->eq('done') ->orderBy($orderBy)->page($pager)->fetchAll(); + $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase'); } elseif($type == 'openedbyme') { $cases = $this->dao->findByOpenedBy($this->app->user->account)->from(TABLE_CASE) ->andWhere('deleted')->eq(0) ->orderBy($orderBy)->page($pager)->fetchAll(); + $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase'); } - $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase'); /* Assign. */ $this->view->title = $this->lang->my->common . $this->lang->colon . $this->lang->my->testCase; diff --git a/module/testtask/control.php b/module/testtask/control.php index b82ed32838..0916f50e0c 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -538,7 +538,6 @@ class testtask extends control $preCase = ''; $nextCase = ''; $caseID = $caseID ? $caseID : $run->case->id; - if($runID and $preAndNext->next) $preAndNext->next = $this->dao->select('*')->from(TABLE_TESTRUN)->where('`case`')->eq($preAndNext->next->id)->fetch(); if($preAndNext->pre) { $preCase['runID'] = $runID ? $preAndNext->pre->id : 0; @@ -585,8 +584,8 @@ class testtask extends control else { $this->testtask->batchRun($from); - $method = $from == 'testcase' ? 'browse' : 'cases'; - die(js::locate($this->createLink($from, $method, "productID=$productID"), 'parent')); + $url = $this->session->caseList ? $this->session->caseList : $this->createLink('testcase', 'browse', "productID=$productID"); + die(js::locate($url, 'parent')); } $this->app->loadLang('testcase'); $this->testtask->setMenu($this->products, $productID);