diff --git a/module/testcase/model.php b/module/testcase/model.php index 6c60512585..29fa2e4b55 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -2378,203 +2378,6 @@ class testcaseModel extends model ->fetchPairs(); } - /** - * Search cases has scene. - * - * @param int $productID - * @param int $queryID - * @param string $orderBy - * @param object $pager - * @param int $branch - * @param string $auto - * @access public - * @return object - */ - public function getBySearchHasScene($productID, $queryID, $orderBy, $pager = null, $branch = 0, $auto = 'no') - { - if($queryID) - { - $query = $this->loadModel('search')->getQuery($queryID); - if($query) - { - $this->session->set('testcaseQuery', $query->sql); - $this->session->set('testcaseForm', $query->form); - } - else - { - $this->session->set('testcaseQuery', ' 1 = 1'); - } - } - else - { - if($this->session->testcaseQuery == false) $this->session->set('testcaseQuery', ' 1 = 1'); - } - - $queryProductID = $productID; - $allProduct = "`product` = 'all'"; - $caseQuery = '(' . $this->session->testcaseQuery; - if(strpos($this->session->testcaseQuery, $allProduct) !== false) - { - $products = $this->app->user->view->products; - $caseQuery = str_replace($allProduct, '1', $caseQuery); - $caseQuery = $caseQuery . ' AND `product` ' . helper::dbIN($products); - $queryProductID = 'all'; - } - - $allBranch = "`branch` = 'all'"; - if($branch !== 'all' and strpos($caseQuery, '`branch` =') === false) $caseQuery .= " AND `branch` in('$branch')"; - if(strpos($caseQuery, $allBranch) !== false) $caseQuery = str_replace($allBranch, '1', $caseQuery); - $caseQuery .= ')'; - $caseQuery = str_replace('`version`', 't1.`version`', $caseQuery); - - if($this->app->tab == 'project') $caseQuery = str_replace('`product`', 't2.`product`', $caseQuery); - - /* Search criteria under compatible project. */ - $sql = $this->dao->select('*')->from(VIEW_SCENECASE)->alias('t1'); - if($this->app->tab == 'project') $sql->leftJoin(TABLE_PROJECTCASE)->alias('t2')->on('t1.id=t2.case'); - $cases = $sql - ->where($caseQuery) - ->andWhere('isCase')->eq(1) - ->beginIF($this->app->tab == 'project')->andWhere('t2.project')->eq($this->session->project)->fi() - ->beginIF($this->app->tab == 'project' and !empty($productID) and $queryProductID != 'all')->andWhere('t2.product')->eq($productID)->fi() - ->beginIF($this->app->tab != 'project' and !empty($productID) and $queryProductID != 'all')->andWhere('t1.product')->eq($productID)->fi() - ->beginIF($auto == 'unit')->andWhere('t1.auto')->eq('unit')->fi() - ->beginIF($auto == 'auto')->andWhere('t1.auto')->eq('auto')->fi() - ->beginIF($auto != 'unit' && $auto != 'auto')->andWhere('t1.auto')->ne('unit')->fi() - ->andWhere('t1.deleted')->eq(0) - ->orderBy($orderBy)->page($pager)->fetchAll('id'); - - return $cases; - } - - /** - * Get scenes and cases list. - * - * @param mixed $productID int|array - * @param string $branch number|all - * @param int $moduleID - * @param array $caseIdList - * @param object $pager object|NULL - * @param string $type - * @param array $topIdList - * @param string $browseType - * @access public - * @return array - */ - public function getList($productID,$branch, $moduleID, $caseIdList, $pager = NULL, $type = '', $topIdList = array(), $browseType = '', &$executionSql = NULL) - { - if(!$caseIdList && $browseType != 'onlyscene') return array(); - - /* Get list of module and its children module. */ - $modules = $moduleID ? $this->loadModel('tree')->getAllChildId($moduleID) : '0'; - - /* Get scenes and all cases in $caseIdList. */ - $cases = $this->dao->select('id,path')->from(VIEW_SCENECASE) - ->where('id')->in($caseIdList) - ->beginIF(is_array($productID))->andWhere('product')->in($productID)->fi() - ->beginIF(!is_array($productID) and intval($productID) > 0)->andWhere('product')->eq($productID)->fi() - ->beginIF($branch != 'all')->andWhere('branch')->eq($branch)->fi() - ->beginIF(intval($moduleID) > 0)->andWhere('module')->in($modules)->fi() - ->beginIF($browseType != 'all')->andWhere('isCase')->eq(1)->fi() - ->beginIF($browseType == 'all')->orWhere('isCase')->eq(2)->fi() - ->fetchPairs('id','path'); - - $sceneIdArr = array(); - foreach ($cases as $path) { - $tmpArr = explode(',', trim($path, ',')); - $sceneIdArr = array_merge($sceneIdArr,$tmpArr); - } - $sceneIdArr = array_unique($sceneIdArr); - - /* Get path list. */ - $pathList = $this->dao->select('id,path')->from(VIEW_SCENECASE) - ->where('deleted')->eq(0) - ->beginIF(is_array($productID))->andWhere('product')->in($productID)->fi() - ->beginIF(!is_array($productID) and intval($productID) > 0)->andWhere('product')->eq($productID)->fi() - ->andWhere('id')->in($sceneIdArr) - ->beginIF($modules)->andWhere('module')->in($modules)->fi() - ->beginIF($browseType == 'onlyscene')->andWhere('isCase')->eq(2)->fi() - ->orderBy('id_asc') - ->fetchPairs('id'); - - /* Get all IDs list. */ - $objectIdList = array(); - foreach($pathList as $path) - { - if($type == 'child' and !empty($topIdList)) - { - $paths = explode(',', trim($path, ',')); - $topID = $paths[0]; - - if(!in_array($topID, $topIdList)) continue; - } - - foreach(explode(',', trim($path, ',')) as $pathID) $objectIdList[$pathID] = $pathID; - } - - /* Sort by product ID for project list. */ - $orderBy = 'product_desc,sort_asc'; - - /* Get sql for batch execution. */ - if($executionSql !== null) $executionSql = $this->buildQuery($modules, $type, $objectIdList, $branch, $browseType)->andWhere('isCase')->eq(1)->orderBy($orderBy)->get(); - - return $this->buildQuery($modules, $type, $objectIdList, $branch, $browseType)->orderBy($orderBy)->page($pager)->fetchAll('id'); - } - - /** - * Get paginated data with all IDs list. - * - * @param string $modules - * @param string $type - * @param string $objectIdList - * @param string $branch - * @param string $browseType - * @access public - * @return object - */ - private function buildQuery($modules, $type, $objectIdList, $branch, $browseType) - { - $this->dao->reset(); - $rawMethod = $this->app->rawMethod; - $rawModule = $this->app->rawModule; - return $this->dao->select('*')->from(VIEW_SCENECASE) - ->where('deleted')->eq(0) - ->beginIF($this->cookie->onlyAutoCase)->andWhere('isCase')->eq(1)->fi() - ->beginIF($browseType == 'onlyscene')->andWhere('isCase')->eq(2)->fi() - ->beginIF($modules)->andWhere('module')->in($modules)->fi() - ->beginIF($rawMethod == 'browse' and $type === 'top')->andWhere('parent')->eq(0)->andWhere('id')->in($objectIdList)->fi() - ->beginIF($rawMethod == 'browse' and $type === 'child')->andWhere('id')->in($objectIdList)->fi() - ->beginIF($rawModule == 'project' and $rawMethod == 'testcase' and intval($branch) > 0)->andWhere('branch')->eq($branch)->fi() - ->beginIF($rawModule == 'project' and $rawMethod == 'testcase' and $type === 'top')->andWhere('parent')->eq(0)->andWhere('id')->in($objectIdList)->fi() - ->beginIF($rawModule == 'project' and $rawMethod == 'testcase' and $type === 'child')->andWhere('id')->in($objectIdList)->fi(); - } - - /** - * Search cases has scene. - * - * @param int $viewID - * @access public - * @return string - */ - public function getParents($viewID) - { - if($viewID == 0) return '/'; - - $path = $this->dao->select('path')->from(VIEW_SCENECASE)->where('id')->eq((int)$viewID)->fetch('path'); - $path = trim($path, ','); - if(!$path) return '/'; - - $pathArr = explode(',', $path); - $scenePath = ""; - foreach ($pathArr as $vid) - { - $title = $this->dao->select('title')->from(VIEW_SCENECASE)->where('id')->eq((int)$vid)->fetch('title'); - $scenePath .= '  '.$title; - } - - return substr($scenePath,34); - } - /** * Get scenes by id list and query string. * @@ -2715,72 +2518,6 @@ class testcaseModel extends model return $modulePairs; } - /** - * Get cases which has scene. - * - * @param int $productID - * @param int $branch - * @param string $browseType - * @param int $queryID - * @param int $moduleID - * @param string $sort - * @param object $pager - * @param string $auto - * @access public - * @return array - */ - public function getTestCaseHasScene($productID, $branch, $browseType, $queryID, $moduleID, $sort, $pager, $auto = 'no') - { - /* Set modules and browse type. */ - $modules = $moduleID ? $this->loadModel('tree')->getAllChildId($moduleID) : '0'; - $browseType = ($browseType == 'bymodule' and $this->session->caseBrowseType and $this->session->caseBrowseType != 'bysearch') ? $this->session->caseBrowseType : $browseType; - $group = $this->lang->navGroup->testcase; - - /* By module or all cases. */ - $cases = array(); - if($browseType == 'bymodule' or $browseType == 'all' or $browseType == 'wait') - { - if($this->app->tab == 'project') - { - $cases = $this->getModuleProjectCases($productID, $branch, $modules, $sort, $pager, $browseType, $auto); - } - else - { - $cases = $this->getModuleCases($productID, $branch, $modules, $sort, $pager, $browseType, $auto); - } - } - /* Cases need confirmed. */ - elseif($browseType == 'needconfirm') - { - $cases = $this->dao->select('distinct t1.*, t2.title AS storyTitle')->from(TABLE_CASE)->alias('t1') - ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') - ->leftJoin(TABLE_PROJECTCASE)->alias('t3')->on('t1.id = t3.case') - ->where("t2.status = 'active'") - ->andWhere('t1.deleted')->eq(0) - ->andWhere('t2.version > t1.storyVersion') - ->beginIF(!empty($productID))->andWhere('t1.product')->eq($productID)->fi() - ->beginIF($this->app->tab == 'project')->andWhere('t3.project')->eq($this->session->project)->fi() - ->beginIF($branch !== 'all')->andWhere('t1.branch')->eq($branch)->fi() - ->beginIF($modules)->andWhere('t1.module')->in($modules)->fi() - ->beginIF($auto != 'unit')->andWhere('t1.auto')->ne('unit')->fi() - ->beginIF($auto == 'unit')->andWhere('t1.auto')->eq('unit')->fi() - ->orderBy($sort) - ->page($pager, 't1.id') - ->fetchAll(); - } - elseif($browseType == 'bysuite') - { - $cases = $this->getBySuite($productID, $branch, $queryID, $modules, $sort, $pager, $auto); - } - /* By search. */ - elseif($browseType == 'bysearch') - { - $cases = $this->getBySearchHasScene($productID, $queryID, $sort, $pager, $branch, $auto); - } - - return $cases; - } - /** * Substr string. *