From 96c2c8a7f6148c3d3471a238897b74bdf2b47629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E9=87=91=E5=8B=87?= Date: Sat, 23 Dec 2023 15:40:13 +0800 Subject: [PATCH] * Refactor tree model. --- module/testcase/control.php | 2 +- module/tree/control.php | 465 ++++++----------------------------- module/tree/js/edit.ui.js | 2 +- module/tree/lang/de.php | 2 +- module/tree/lang/en.php | 2 +- module/tree/lang/fr.php | 2 +- module/tree/lang/vi.php | 2 +- module/tree/lang/zh-cn.php | 2 +- module/tree/lang/zh-tw.php | 2 +- module/tree/model.php | 115 ++++----- module/tree/ui/edit.html.php | 1 - module/tree/zen.php | 300 ++++++++++++++++++++++ 12 files changed, 443 insertions(+), 454 deletions(-) create mode 100644 module/tree/zen.php diff --git a/module/testcase/control.php b/module/testcase/control.php index 6a5fb529a8..98017f9ce7 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1396,7 +1396,7 @@ class testcase extends control * @access public * @return void */ - public function ajaxGetOptionMenu(int $rootID, int|string $branch = 0, int $rootModuleID = 0, string $returnType = 'html', string $fieldID = ''): bool + public function ajaxGetOptionMenu(int $rootID, int|string $branch = 0, int $rootModuleID = 0, string $returnType = 'html', string $fieldID = '') { $optionMenu = $this->loadModel('tree')->getOptionMenu($rootID, 'case', $rootModuleID, $branch); diff --git a/module/tree/control.php b/module/tree/control.php index da6357f862..7660e82370 100644 --- a/module/tree/control.php +++ b/module/tree/control.php @@ -1,5 +1,5 @@ loadModel('product'); - $placeholder = $this->lang->tree->name; + $this->updateBrowseLang($viewType); + $this->updateRawModule($viewType); - if($this->app->tab == 'product' and strpos($viewType, 'doc') === false) - { - $this->product->setMenu($rootID, $branch, 0, '', $viewType); - } - elseif($this->app->tab == 'qa' and $viewType != 'caselib') - { - $this->loadModel('qa')->setMenu($rootID, $branch); - } - elseif($this->app->tab == 'project' and strpos($viewType, 'doc') === false) - { - $this->loadModel('project')->setMenu($this->session->project); - - $products = $this->product->getProducts($this->session->project, 'all', '', false); - if($viewType == 'case') $this->lang->modulePageNav = $this->product->select($products, $rootID, 'tree', 'browse', 'case', $branch); - } - elseif($this->app->tab == 'feedback') - { - $branch = 'all'; - $products = $this->loadModel('feedback')->getGrantProducts(); - if(!$rootID) $rootID = key($products); - $this->loadModel('feedback')->setMenu($rootID, $viewType, $viewType); - } + /* 可以维护模块的类型:story, bug, case, feedback, caselib, ticket, line, 另外 doc, api在列表页面维护。*/ + $root = $this->setRoot($rootID, $viewType, $branch); /* According to the type, set the module root and modules. */ - if(strpos('story|bug|case', $viewType) !== false) - { - $product = $this->loadModel('product')->getById($rootID); - if(empty($product)) - { - if($this->viewType == 'json' or (defined('RUN_MODE') && RUN_MODE == 'api')) return $this->send(array('result' => 'fail', 'message' => 'No product.')); - $this->locate($this->createLink('product', 'create')); - } - - if(!empty($product->type) && $product->type != 'normal') - { - $branches = $this->loadModel('branch')->getPairs($product->id, 'withClosed'); - if($currentModuleID) - { - $currentModuleBranch = $this->dao->select('branch')->from(TABLE_MODULE)->where('id')->eq($currentModuleID)->fetch('branch'); - $branchName = $branches[$currentModuleBranch]; - unset($branches); - $branches[$currentModuleBranch] = $branchName; - } - $this->view->branches = $branches; - } - $this->view->root = $product; - - /* Determines whether an object is editable. */ - $canBeChanged = common::canModify('product', $product); - } - elseif(strpos($viewType, 'doc') !== false) - { - /* The viewType is doc. */ - $this->loadModel('doc'); - $viewType = 'doc'; - $lib = $this->doc->getLibById($rootID); - $this->view->root = $lib; - } - elseif(strpos($viewType, 'api') !== false) - { - /* The viewType is doc. */ - $this->loadModel('doc'); - $viewType = 'api'; - $lib = $this->doc->getLibById($rootID); - $title = $this->lang->tree->manageCustomDoc; - $position[] = html::a($this->createLink('api', 'index', "libID=$rootID"), $lib->name); - $position[] = $this->lang->tree->manageCustomDoc; - $this->view->root = $lib; - } - elseif(strpos($viewType, 'caselib') !== false) - { - $this->loadModel('caselib'); - $lib = $this->caselib->getById($rootID); - $this->view->root = $lib; - $this->view->libID = $rootID; - } + $branches = $this->getBranches($root, $viewType, $currentModuleID); if($viewType == 'story') { - /* Set menu.*/ - $products = $this->product->getPairs($mode = '', $programID = 0, $append = '', 'all'); - if($this->app->tab == 'project') $this->view->projectID = $this->session->project; - - $rootID = $this->product->getAccessibleProductID($rootID, $products); + $products = $this->loadModel('product')->getPairs($mode = '', $programID = 0, $append = '', 'all'); $this->session->set('product', $rootID, $this->app->tab); + $this->lang->modulePageNav = ''; + unset($products[$rootID]); $currentProduct = (int)key($products); - $this->lang->modulePageNav = ''; $this->view->allProduct = $products; $this->view->currentProduct = $currentProduct; $this->view->productModules = $this->tree->getOptionMenu($currentProduct, 'story'); - $this->view->productID = $rootID; - - $title = $this->lang->tree->manageProduct; - $position[] = html::a($this->createLink('product', 'browse', "product=$rootID"), $product->name); - $position[] = $this->lang->tree->manageProduct; } - elseif($viewType == 'bug') - { - $this->app->loadConfig('qa'); - foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa'; - $this->app->rawModule = 'bug'; - $title = $this->lang->tree->manageBug; - $position[] = html::a($this->createLink('bug', 'browse', "product=$rootID"), $product->name); - $position[] = $this->lang->tree->manageBug; - - $this->view->productID = $rootID; - } - elseif($viewType == 'feedback' or $viewType == 'ticket') + if($viewType == 'feedback' or $viewType == 'ticket') { - $this->app->loadLang('feedback'); - $this->lang->tree->menu = $this->lang->feedback->menu; - $productItem = $this->product->getById($rootID); - $root = new stdclass(); - $root->name = !empty($rootID) ? $productItem->name : $this->lang->feedback->common; - $this->view->root = $root; $syncConfig = json_decode($this->config->global->syncProduct, true); $this->view->syncConfig = isset($syncConfig[$viewType]) ? $syncConfig[$viewType] : array(); - $title = $this->lang->tree->{$viewType == 'feedback' ? 'manageFeedback' : 'manageTicket'}; - $position[] = html::a($this->createLink('feedback', 'admin'), $this->lang->tree->manageFeedback); - } - elseif($viewType == 'case') - { - $this->app->loadConfig('qa'); - foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa'; - $this->app->rawModule = 'testcase'; - - $title = $this->lang->tree->manageCase; - $position[] = html::a($this->createLink('testcase', 'browse', "product=$rootID"), $product->name); - $position[] = $this->lang->tree->manageCase; - - $this->view->productID = $rootID; - } - elseif($viewType == 'caselib') - { - $this->app->loadConfig('qa'); - foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa'; - - $this->caselib->setLibMenu($this->caselib->getLibraries(), $rootID); - $this->app->rawModule = 'caselib'; - - $title = $this->lang->tree->manageCaseLib; - $position[] = html::a($this->createLink('caselib', 'browse', "libID=$rootID"), $lib->name); - $position[] = $this->lang->tree->manageCaseLib; - } - elseif(strpos($viewType, 'doc') !== false) - { - $this->lang->navGroup->tree = 'doc'; - - if($from == 'product') - { - $productID = $lib->product; - unset($this->lang->product->menu->set['subModule']); - - $products = $this->product->getPairs(); - $productID = $this->product->getAccessibleProductID($productID, $products); - $this->session->set('product', $productID, $this->app->tab); - } - elseif($from == 'project') - { - $this->lang->navGroup->tree = 'project'; - - /* The project parameter needs to be present when the tree module belongs to the project grouping. */ - if($this->session->docList && $this->session->project && strpos($this->session->docList, 'project') === false) $this->session->set('docList', $this->session->docList . '?project=' . $this->session->project, 'project'); - } - - if($from == 'doc') $this->lang->navGroup->doc = 'doc'; - $type = $lib->product ? 'product' : ($lib->project ? 'project' : ($lib->execution ? 'execution' : 'custom')); - $this->lang->tree->menu = $this->lang->doc->menu; - $this->lang->tree->menuOrder = $this->lang->doc->menuOrder; - - $title = $this->lang->tree->manageCustomDoc; - $position[] = html::a($this->createLink('doc', 'browse', "libID=$rootID"), $lib->name); - $position[] = $this->lang->tree->manageCustomDoc; - } - elseif($viewType == 'line') - { - $products = $this->product->getPairs('', $this->session->project); - - $this->product->setMenu($products, $rootID, $branch, 'line', '', 'line'); - $this->lang->tree->menu = $this->lang->product->menu; - $this->lang->tree->menuOrder = $this->lang->product->menuOrder; - - unset($products[$rootID]); - $currentProduct = key($products); - - $this->view->allProduct = $products; - $this->view->currentProduct = $currentProduct; - $this->view->productModules = $this->tree->getOptionMenu($currentProduct, 'line'); - - $title = $this->lang->tree->manageLine; - $position[] = $this->lang->tree->manageLine; - } - elseif($viewType == 'dashboard') - { - $root = new stdclass(); - $root->name = $this->lang->dashboard->common; - - $this->view->root = $root; - $this->lang->tree->menu = $this->lang->report->menu; - - $title = $this->lang->tree->manageDashboard; - $position[] = $this->lang->tree->manageDashboard; - } - elseif($viewType == 'trainskill') - { - $this->lang->tree->menu = $this->lang->trainskill->menu; - - $title = $this->lang->tree->manageTrainskill; - $position[] = $this->lang->tree->manageTrainskill; - } - elseif($viewType == 'trainpost') - { - $postBrowseType = $this->session->postBrowseType ? $this->session->postBrowseType : 'train'; - if($postBrowseType == 'train') - { - $this->lang->tree->menu = $this->lang->train->menu; - } - else - { - $this->lang->tree->menu = $this->lang->company->menu; - } - - $title = $this->lang->tree->manageTrainpost; - $position[] = $this->lang->tree->manageTrainpost; - } - elseif($viewType == 'report') - { - $title = $this->lang->tree->manageReport; - $position[] = $this->lang->tree->manageReport; - - $root = new stdclass(); - $root->name = $this->lang->tree->report; - $this->view->root = $root; - } - elseif(strpos($viewType, 'datasource') !== false) - { - $params = explode('_', $viewType); - if(count($params) == 2) - { - $datasourceID = $params[1]; - $manageChild = 'manage' . ucfirst($viewType) . 'Child'; - $datasource = $this->loadModel('workflowdatasource', 'flow')->getByID($datasourceID); - if($datasource) - { - $this->app->rawModule = 'workflowdatasource'; - - $title = $datasource->name; - $position[] = $datasource->name; - - $this->lang->tree->$manageChild = $title; - - $root = new stdclass(); - $root->name = $title; - $this->view->root = $root; - } - } - } - /* viewType is workflow building category. */ - elseif(strpos($viewType, '_') !== false) - { - $params = explode('_', $viewType); - if(count($params) == 2) - { - $this->app->rawModule = $params[0]; - - $manageChild = 'manage' . ucfirst($viewType) . 'Child'; - - $title = $this->lang->tree->common; - $position[] = $this->lang->tree->common; - - $this->lang->tree->$manageChild = $title; - - $root = new stdclass(); - $root->name = $title; - $this->view->root = $root; - } - } - elseif(strpos($viewType, 'host') !== false) - { - $position = array(); - $title = $this->lang->tree->groupMaintenance; - $placeholder = $this->lang->tree->groupName; - - $root = new stdclass(); - $root->id = 0; - $root->name = $this->lang->tree->groupMaintenance; - - $this->view->productID = 0; - $this->view->root = $root; } - if($this->app->tab == 'project' and strpos($viewType, 'doc') === false) - { - $project = $this->loadModel('project')->getByID($this->session->project); - if(empty($project->hasProduct)) $this->view->root->name = $project->name; - } - - $this->view->title = $title; - $this->view->position = $position; - $this->view->rootID = $rootID; + $this->view->title = $this->lang->tree->manage; + $this->view->rootID = $root->id; + $this->view->root = $root; + $this->view->productID = $root->rootType == 'product' ? $root->id: 0; + $this->view->libID = $root->rootType == 'caselib' ? $root->id : 0; $this->view->viewType = $viewType; - $this->view->placeholder = $placeholder; + $this->view->placeholder = $viewType == 'host' ? $this->lang->tree->groupName : $this->lang->tree->name; $this->view->sons = $this->tree->getSons($rootID, $currentModuleID, $viewType, $branch); $this->view->currentModuleID = $currentModuleID; $this->view->parentModules = $this->tree->getParents($currentModuleID); $this->view->branch = $branch; $this->view->from = $from; $this->view->tree = $this->tree->getProductStructure($rootID, $viewType, $branch); - $this->view->canBeChanged = isset($canBeChanged) ? $canBeChanged : true; + $this->view->canBeChanged = common::canModify($root->rootType, $root); $this->display(); } /** + * 任务模块维护。 * Browse task module. * * @param int $rootID @@ -356,7 +86,7 @@ class tree extends control * @access public * @return void */ - public function browseTask($rootID, $productID = 0, $currentModuleID = 0) + public function browseTask(int $rootID, int $productID = 0, int $currentModuleID = 0) { $this->lang->navGroup->tree = 'execution'; @@ -382,11 +112,8 @@ class tree extends control $newModule = (version_compare($execution->openedVersion, '4.1', '>') and $products) ? true : false; $title = $execution->multiple ? $this->lang->tree->manageExecution : $this->lang->tree->manageProject; - $position[] = html::a($this->createLink('execution', 'task', "executionID=$rootID"), $execution->name); - $position[] = $this->lang->tree->manageExecution; $this->view->title = $title; - $this->view->position = $position; $this->view->rootID = $rootID; $this->view->productID = $productID; $this->view->execution = $execution; @@ -402,17 +129,19 @@ class tree extends control } /** + * 编辑模块。 * Edit a module. * - * @param int $moduleID + * @param int $moduleID + * @param string $type + * @param string $branch * @access public * @return void */ - public function edit($moduleID, $type, $branch = 0) + public function edit(int $moduleID, string $type, string $branch = '0') { if(!empty($_POST)) { - $this->tree->update($moduleID, $type); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); @@ -430,31 +159,8 @@ class tree extends control $this->view->optionMenu = $this->tree->getOptionMenu($module->root, $module->type, 0, $module->branch, 'noMainBranch|nodeleted'); } - if($type == 'doc') - { - $docLib = $this->loadModel('doc')->getLibById($module->root); - $objectID = isset($docLib->{$docLib->type}) ? $docLib->{$docLib->type} : 0; - $this->view->libs = $this->doc->getLibs($docLib->type, '', '', $objectID, 'book'); - } - - if($type == 'doc' or $type == 'api') - { - $name = $this->lang->tree->dir; - $title = $this->lang->tree->editDir; - } - elseif($type == 'line') - { - $name = $this->lang->tree->line; - $title = $this->lang->tree->manageLine; - } - else - { - $name = $this->lang->tree->name; - $title = $this->lang->tree->edit; - } - - $this->view->name = $name; - $this->view->title = $title; + $this->view->name = $type == 'line' ? $this->lang->tree->line : $this->lang->tree->name; + $this->view->title = $type == 'line' ? $this->lang->tree->manageLine : $this->lang->tree->edit; $this->view->module = $module; $this->view->type = $type; $this->view->branch = $branch; @@ -475,31 +181,26 @@ class tree extends control $childs = $this->tree->getAllChildId($moduleID); foreach($childs as $childModuleID) unset($this->view->optionMenu[$childModuleID]); - $this->view->hiddenProduct = false; - if($this->app->tab == 'project') - { - $project = $this->loadModel('project')->getByID($this->session->project); - $this->view->hiddenProduct = empty($project->hasProduct); - } - $this->display(); } /** + * 修复模块的path和grade字段。 * Fix path, grades. * - * @param string $root + * @param int $rootID * @param string $type * @access public * @return void */ - public function fix($root, $type) + public function fix(int $rootID, string $type) { - $this->tree->fixModulePath($root, $type); + $this->tree->fixModulePath($rootID, $type); echo js::alert($this->lang->tree->successFixed) . js::reload('parent'); } /** + * 更新模块排序。 * Update modules' orders. * * @param int $root @@ -509,7 +210,7 @@ class tree extends control * @access public * @return void */ - public function updateOrder($rootID = 0, $viewType = '', $moduleID = 0) + public function updateOrder(int $rootID = 0, string $viewType = '', int $moduleID = 0) { if(!empty($_POST)) { @@ -520,6 +221,7 @@ class tree extends control } /** + * 管理子模块。 * Manage child modules. * * @param int $rootID @@ -540,6 +242,22 @@ class tree extends control } /** + * 查看模块历史记录。 + * View module histories. + * + * @param int $productID + * @access public + * @return void + */ + public function viewHistory(int $productID) + { + $this->view->actions = $this->loadModel('action')->getList('module', $productID); + $this->view->users = $this->loadModel('user')->getPairs('noletter'); + $this->display(); + } + + /** + * 删除模块。 * Delete a module. * * @param int $moduleID @@ -547,7 +265,7 @@ class tree extends control * @access public * @return void */ - public function delete($moduleID, $confirm = 'no') + public function delete(int $moduleID, string $confirm = 'no') { if($confirm == 'no') { @@ -564,7 +282,7 @@ class tree extends control } else { - $result = $this->tree->delete($moduleID); + $result = $this->tree->remove($moduleID); if(!$result) return; return $this->send(array('result' => 'success', 'load' => true, 'closeModal' => true)); @@ -572,7 +290,8 @@ class tree extends control } /** - * AJAX: Get the option menu of modules. + * Ajax: 获取模块的下拉菜单。 + * Ajax: Get the option menu of modules. * * @param int $rootID * @param string $viewType @@ -580,13 +299,12 @@ class tree extends control * @param int $rootModuleID * @param string $returnType * @param string $fieldID - * @param bool $needManage * @param string $extra * @param int $currentModuleID * @access public * @return string the html select string. */ - public function ajaxGetOptionMenu(int $rootID, string $viewType = 'story', string $branch = '0', int $rootModuleID = 0, string $returnType = 'html', string $fieldID = '', bool $needManage = false, string $extra = 'nodeleted', int $currentModuleID = 0) + public function ajaxGetOptionMenu(int $rootID, string $viewType = 'story', string $branch = '0', int $rootModuleID = 0, string $returnType = 'html', string $fieldID = '', string $extra = 'nodeleted', int $currentModuleID = 0) { if($viewType == 'task') { @@ -616,40 +334,16 @@ class tree extends control if($returnType == 'items') { - $output = array(); - foreach($optionMenu as $menuID => $menu) $output[] = array('text' => $menu, 'value' => $menuID, 'keys' => $menu); - return print(json_encode($output)); + $this->printOptionMenuArray($optionMenu); } - - if($returnType == 'html') + elseif($returnType == 'html') { - //Code for task #5081. - if($viewType == 'line') - { - $lineID = $this->dao->select('id')->from(TABLE_MODULE)->where('type')->eq('line')->andWhere('deleted')->eq(0)->orderBy('id_desc')->limit(1)->fetch('id'); - - $items = array(); - foreach($optionMenu as $moduleID => $moduleName) $items[] = array('text' => $moduleName, 'value' => $moduleID); - - $output = array('name' => 'line', 'defaultValue' => $lineID, 'items' => $items); - } - else - { - $field = $fieldID !== '' ? "modules[$fieldID]" : 'module'; - - $currentModule = $this->tree->getById($currentModuleID); - $currentModuleID = (isset($currentModule->branch) and $currentModule->branch == 0) ? $currentModuleID : 0; - - $items = array(); - foreach($optionMenu as $moduleID => $moduleName) $items[] = array('text' => $moduleName, 'value' => $moduleID); - - $output = array('name' => $field, 'defaultValue' => $currentModuleID, 'items' => $items); - } - - return print(json_encode($output)); + $this->printOptionMenuHtml($optionMenu, $viewType, $fieldID, $currentModuleID); } - if($returnType == 'mhtml') + elseif($returnType == 'mhtml') { + $this->printOptionMenuMHtml($optionMenu, $viewType, $rootID); + $changeFunc = ''; if($viewType == 'bug' or $viewType == 'case') $changeFunc = "onchange='loadModuleRelated()'"; if($viewType == 'task') $changeFunc = "onchange='setStories(this.value, $rootID)'"; @@ -657,11 +351,15 @@ class tree extends control $output = html::select("$field", $optionMenu, '', "class='input' $changeFunc"); return print($output); } - if($returnType == 'json') die(json_encode($optionMenu)); + elseif($returnType == 'json') + { + print(json_encode($optionMenu)); + } } /** - * Ajax get drop menu. + * Ajax: 获取drop菜单。 + * Ajax: get drop menu. * * @param int $rootID * @param string $module @@ -670,7 +368,7 @@ class tree extends control * @access public * @return void */ - public function ajaxGetDropMenu($rootID, $module, $method, $extra = '') + public function ajaxGetDropMenu(int $rootID, string $module, string $method, string $extra = '') { $this->view->productID = $rootID; $this->view->module = $module; @@ -692,7 +390,8 @@ class tree extends control } /** - * AJAX: get modules. + * Ajax: 获取模块列表。 + * Ajax: get modules. * * @param int $productID * @param string $viewType @@ -703,7 +402,7 @@ class tree extends control * @access public * @return string the html select string. */ - public function ajaxGetModules($productID, $viewType = 'story', $branchID = 0, $number = 0, $currentModuleID = 0, $from = '') + public function ajaxGetModules(int $productID, string $viewType = 'story', int $branchID = 0, int $number = 0, int $currentModuleID = 0, string $from = '') { $currentModule = $this->tree->getById($currentModuleID); $currentModuleID = (isset($currentModule->branch) and $currentModule->branch == 0) ? $currentModuleID : 0; @@ -725,7 +424,8 @@ class tree extends control } /** - * AJAX: get a module's son modules. + * Ajax: 获取一个模块的子模块。 + * Ajax: get a module's son modules. * * @param int $moduleID * @param int $rootID @@ -733,7 +433,7 @@ class tree extends control * @access public * @return string json_encoded modules. */ - public function ajaxGetSonModules($moduleID, $rootID = 0, $type = 'story') + public function ajaxGetSonModules(int $moduleID, int $rootID = 0, string $type = 'story') { $modules = $this->dao->select('id,name,short')->from(TABLE_MODULE) ->where('root')->eq($rootID) @@ -745,21 +445,8 @@ class tree extends control } /** - * View module histories. - * - * @param int $productID - * @access public - * @return void - */ - public function viewHistory($productID) - { - $this->view->actions = $this->loadModel('action')->getList('module', $productID); - $this->view->users = $this->loadModel('user')->getPairs('noletter'); - $this->display(); - } - - /** - * Create module by ajax. + * Ajax: 创建模块。 + * Ajax: Create module. * * @access public * @return void diff --git a/module/tree/js/edit.ui.js b/module/tree/js/edit.ui.js index e8c8e27c87..329d7995ee 100644 --- a/module/tree/js/edit.ui.js +++ b/module/tree/js/edit.ui.js @@ -77,7 +77,7 @@ function ajaxLoadModules(productID, branchID, viewType = '', currentModuleID = 0 { if(!viewType) viewType = type; - var link = $.createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=' + viewType + '&branch=' + branchID + '&rootModuleID=0&returnType=html&fieldID=&needManage=false&extra=excludeModuleID=' + currentModuleID + ',noMainBranch,nodeleted,excludeRelated'); + var link = $.createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=' + viewType + '&branch=' + branchID + '&rootModuleID=0&returnType=html&fieldID=&extra=excludeModuleID=' + currentModuleID + ',noMainBranch,nodeleted,excludeRelated'); $.getJSON(link, function(data) { $('[name=parent]').zui('picker').render({items: data.items}); diff --git a/module/tree/lang/de.php b/module/tree/lang/de.php index 0a57de6f87..cf89b22ccc 100755 --- a/module/tree/lang/de.php +++ b/module/tree/lang/de.php @@ -23,7 +23,7 @@ $lang->tree->manageExecution = "Verwalte {$lang->execution->common}"; $lang->tree->manageLine = "Manage Product Line"; $lang->tree->manageBug = 'Verwalte Bugs'; $lang->tree->manageCase = 'Verwalte Fälle'; -$lang->tree->manageCaseLib = 'Verwalte Bibliothek'; +$lang->tree->manageCaselib = 'Verwalte Bibliothek'; $lang->tree->manageCustomDoc = 'Verwalte Dokumente'; $lang->tree->manageApiChild = 'Manage API Directory'; $lang->tree->updateOrder = 'Sortierung'; diff --git a/module/tree/lang/en.php b/module/tree/lang/en.php index 616ffc4f81..1e42ba9e26 100755 --- a/module/tree/lang/en.php +++ b/module/tree/lang/en.php @@ -23,7 +23,7 @@ $lang->tree->manageExecution = "Manage {$lang->execution->common} Modules"; $lang->tree->manageLine = "Manage Product Line"; $lang->tree->manageBug = 'Manage Bug'; $lang->tree->manageCase = 'Manage Case'; -$lang->tree->manageCaseLib = 'Manage Library'; +$lang->tree->manageCaselib = 'Manage Library'; $lang->tree->manageCustomDoc = 'Manage Document Library'; $lang->tree->manageApiChild = 'Manage API Directory'; $lang->tree->updateOrder = 'Rank Module'; diff --git a/module/tree/lang/fr.php b/module/tree/lang/fr.php index 17b872907c..35f4b3b20d 100755 --- a/module/tree/lang/fr.php +++ b/module/tree/lang/fr.php @@ -23,7 +23,7 @@ $lang->tree->manageExecution = "Gérer les Modules {$lang->execution->commo $lang->tree->manageLine = 'Gérer Ligne Produit'; $lang->tree->manageBug = 'Gérer Bugs'; $lang->tree->manageCase = 'Gérer CasTests'; -$lang->tree->manageCaseLib = 'Gérer Librairie de recette'; +$lang->tree->manageCaselib = 'Gérer Librairie de recette'; $lang->tree->manageCustomDoc = 'Gérer la librairie de Doc'; $lang->tree->manageApiChild = 'Manage API Directory'; $lang->tree->updateOrder = 'Rang Module'; diff --git a/module/tree/lang/vi.php b/module/tree/lang/vi.php index 774003414a..0884cf7cca 100755 --- a/module/tree/lang/vi.php +++ b/module/tree/lang/vi.php @@ -22,7 +22,7 @@ $lang->tree->manageExecution = "Quản lý module {$lang->executionCommon}" $lang->tree->manageLine = "Quản lý dòng {$lang->productCommon}"; $lang->tree->manageBug = 'Quản lý Bug'; $lang->tree->manageCase = 'Quản lý tình huống'; -$lang->tree->manageCaseLib = 'Quản lý thư viện'; +$lang->tree->manageCaselib = 'Quản lý thư viện'; $lang->tree->manageCustomDoc = 'Quản lý thư viện tài liệu'; $lang->tree->updateOrder = 'Đánh giá Module'; $lang->tree->manageChild = 'Quản lý module con'; diff --git a/module/tree/lang/zh-cn.php b/module/tree/lang/zh-cn.php index a272b2cffa..d037a2b9f7 100755 --- a/module/tree/lang/zh-cn.php +++ b/module/tree/lang/zh-cn.php @@ -23,7 +23,7 @@ $lang->tree->manageExecution = "维护{$lang->execution->common}视图模 $lang->tree->manageLine = "维护产品线"; $lang->tree->manageBug = '维护测试视图模块'; $lang->tree->manageCase = '维护用例视图模块'; -$lang->tree->manageCaseLib = '维护用例库模块'; +$lang->tree->manageCaselib = '维护用例库模块'; $lang->tree->manageCustomDoc = '维护文档库分类'; $lang->tree->manageApiChild = '维护接口库目录'; $lang->tree->updateOrder = '更新排序'; diff --git a/module/tree/lang/zh-tw.php b/module/tree/lang/zh-tw.php index b31bbe1582..a51dc853ce 100755 --- a/module/tree/lang/zh-tw.php +++ b/module/tree/lang/zh-tw.php @@ -22,7 +22,7 @@ $lang->tree->manageExecution = "維護{$lang->executionCommon}視圖模組"; $lang->tree->manageLine = "維護{$lang->productCommon}綫"; $lang->tree->manageBug = '維護測試視圖模組'; $lang->tree->manageCase = '維護用例視圖模組'; -$lang->tree->manageCaseLib = '維護用例庫模組'; +$lang->tree->manageCaselib = '維護用例庫模組'; $lang->tree->manageCustomDoc = '維護文檔庫分類'; $lang->tree->manageApiChild = '維護介面庫目錄'; $lang->tree->updateOrder = '更新排序'; diff --git a/module/tree/model.php b/module/tree/model.php index f5f55d0598..d068f6ebea 100644 --- a/module/tree/model.php +++ b/module/tree/model.php @@ -1,4 +1,5 @@ dao->findById((int)$moduleID)->from(TABLE_MODULE)->fetch(); } @@ -29,7 +30,7 @@ class treeModel extends model * @access public * @return object */ - public function getAllModulePairs($type = 'task') + public function getAllModulePairs(string $type = 'task') { $modules = $this->dao->select('*')->from(TABLE_MODULE) ->where('type')->eq('story') @@ -222,7 +223,7 @@ class treeModel extends model * @access public * @return array */ - public function getModulePairs($rootID, $viewType = 'story', $showModule = 'end', $extra = '') + public function getModulePairs(int $rootID, string $viewType = 'story', string $showModule = 'end', string $extra = '') { if($viewType == 'task') { @@ -468,9 +469,9 @@ class treeModel extends model * @param array $userFunc * @param string $extra * @access public - * @return void + * @return array */ - public function getTaskTreeMenu($rootID, $productID = 0, $startModule = 0, $userFunc = '', $extra = '') + public function getTaskTreeMenu(int $rootID, int $productID = 0, int $startModule = 0, array $userFunc = array(), string $extra = ''): array { $extra = array('tip' => true, 'extra' => $extra, 'executionID' => $rootID, 'productID' => $productID); @@ -559,7 +560,7 @@ class treeModel extends model * @access public * @return array */ - public function getTaskStructure($rootID, $productID = 0) + public function getTaskStructure(int $rootID, int $productID = 0): array { $extra = array('executionID' => $rootID, 'productID' => $productID, 'tip' => true); @@ -615,6 +616,7 @@ class treeModel extends model $stmt = $this->app->dbQuery($query); $taskTrees = $this->getDataStructure($stmt, 'task', $rootID, $executionModules); foreach($taskTrees as $taskModule) $fullTrees[] = $taskModule; + return $fullTrees; } @@ -626,7 +628,7 @@ class treeModel extends model * @access public * @return array */ - public function getTreeStructure($rootID, $type) + public function getTreeStructure(int $rootID, string $type): array { $stmt = $this->app->dbQuery($this->buildMenuQuery($rootID, $type, $startModule = 0)); return $this->getDataStructure($stmt, $type, $rootID); @@ -1202,11 +1204,13 @@ class treeModel extends model /** * Create the manage link of a module. * - * @param object $module + * @param string $module + * @param object $module + * @param array $extra * @access public * @return string */ - public function createManageLink($type, $module, $extra) + public function createManageLink(string $type, object $module, array $extra): string { $branchID = $extra['branchID']; $tip = strpos('bug,case', $type) === false ? '' : ' [' . strtoupper(substr($type, 0, 1)) . ']'; @@ -1238,9 +1242,9 @@ class treeModel extends model * @param int $parent * @param array $extra * @access public - * @return void + * @return object */ - public function createTaskManageLink(string $type, object $module, int $parent, array $extra) + public function createTaskManageLink(string $type, object $module, int $parent, array $extra): object { $executionID = $extra['executionID']; $productID = $extra['productID']; @@ -1267,7 +1271,7 @@ class treeModel extends model * @access public * @return object */ - public function createBugLink(string $type, object $module, string $parent, array $extra = array()) + public function createBugLink(string $type, object $module, string $parent, array $extra = array()): object { $moduleName = strpos(',project,execution,', ",{$this->app->tab},") !== false ? $this->app->tab : 'bug'; $methodName = strpos(',project,execution,', ",{$this->app->tab},") !== false ? 'bug' : 'browse'; @@ -1366,11 +1370,13 @@ class treeModel extends model * @access public * @return string */ - public function createBranchLink($type, $rootID, $branchID, $branch) + public function createBranchLink($type, $rootID, $branchID, $branch): string { if($type == 'story') return html::a(helper::createLink('product', 'browse', "productID={$rootID}&branch=$branchID"), $branch, '_self', "id='branch{$branchID}'"); if($type == 'bug') return html::a(helper::createLink('bug', 'browse', "productID={$rootID}&branch=$branchID"), $branch, '_self', "id='branch{$branchID}'"); if($type == 'case') return html::a(helper::createLink('testcase', 'browse', "productID={$rootID}&branch=$branchID"), $branch, '_self', "id='branch{$branchID}'"); + + return ''; } /** @@ -1381,7 +1387,7 @@ class treeModel extends model * @access public * @return string */ - public function createFeedbackLink($type, $module) + public function createFeedbackLink(string $type, object $module): string { return html::a(helper::createLink('feedback', $this->app->methodName, "type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}' title='{$module->name}'"); } @@ -1394,7 +1400,7 @@ class treeModel extends model * @access public * @return string */ - public function createTicketLink($type, $module) + public function createTicketLink(string $type, object $module): string { return html::a(helper::createLink('ticket', $this->app->methodName, "type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}' title='{$module->name}'"); } @@ -1408,7 +1414,7 @@ class treeModel extends model * @access public * @return string */ - public function createTrainSkillLink($type, $module, $extra = '') + public function createTrainSkillLink(string $type, object $module, string $extra = ''): string { return html::a(helper::createLink('trainskill', 'browse', "type=byModule¶m={$module->id}"), $module->name, '', "id='module{$module->id}' title='{$module->name}'"); } @@ -1422,7 +1428,7 @@ class treeModel extends model * @access public * @return string */ - public function createTrainCourseLink($type, $module, $extra = '') + public function createTrainCourseLink(string $type, object $module, string $extra = ''): string { return html::a(helper::createLink('traincourse', 'browse', "type=byModule¶m={$module->id}"), $module->name, '', "id='module{$module->id}' title='{$module->name}'"); } @@ -1436,7 +1442,7 @@ class treeModel extends model * @access public * @return string */ - public function createTrainPostLink($type, $module, $extra = '') + public function createTrainPostLink(string $type, object $module, string $extra = ''): string { return html::a(helper::createLink('trainpost', 'browse', "type=byModule¶m={$module->id}"), $module->name, '', "id='module{$module->id}' title='{$module->name}'"); } @@ -1450,7 +1456,7 @@ class treeModel extends model * @access public * @return string */ - public function createDashboardLink($type, $module, $extra = '') + public function createDashboardLink(string $type, object $module, string $extra = ''): string { return html::a(helper::createLink('dashboard', 'browse', "type=bymodule¶m={$module->id}"), $module->name, '', "id='module{$module->id}' title='{$module->name}'"); } @@ -1464,7 +1470,7 @@ class treeModel extends model * @access public * @return string */ - public function createReportLink($type, $module, $extra) + public function createReportLink(string $type, object $module, string $extra): string { $dimension = zget($extra, 'dimension', 0); return html::a(helper::createLink('report', 'browsereport', "dimension={$dimension}&module={$module->id}"), $module->name, '', "id='module{$module->id}' title='{$module->name}'"); @@ -1498,11 +1504,11 @@ class treeModel extends model * @param int $rootID * @param int $moduleID * @param string $type - * @param int $branch + * @param string $branch * @access public * @return array */ - public function getSons($rootID, $moduleID, $type = 'root', $branch = 0) + public function getSons(int $rootID, int $moduleID, string $type = 'root', string $branch = '0'): array { $syncConfig = $this->getSyncConfig($type); @@ -1551,9 +1557,9 @@ class treeModel extends model * @param int $productID * @param int $moduleID * @access public - * @return void + * @return array */ - public function getTaskSons($rootID, $productID, $moduleID) + public function getTaskSons(int $rootID, int $productID, int $moduleID): array { if($moduleID) { @@ -1584,7 +1590,7 @@ class treeModel extends model * @access public * @return array */ - public function getAllChildId($moduleID) + public function getAllChildId(int $moduleID): array { if($moduleID == 0) return array(); @@ -1600,9 +1606,9 @@ class treeModel extends model * @param int $projectID * @param int $productID * @access public - * @return void + * @return array */ - public function getProjectModule($projectID, $productID = 0) + public function getProjectModule(int $projectID, int $productID = 0): array { $modules = array(); $rootModules = $this->dao->select('path')->from(TABLE_MODULE) @@ -1628,7 +1634,7 @@ class treeModel extends model * @access public * @return array */ - public function getParents($moduleID) + public function getParents(int $moduleID): array { if($moduleID == 0) return array(); $path = $this->dao->select('path')->from(TABLE_MODULE)->where('id')->eq((int)$moduleID)->fetch('path'); @@ -1662,9 +1668,9 @@ class treeModel extends model * * @param int $moduleID * @access public - * @return void + * @return int */ - public function getStoryModule($moduleID) + public function getStoryModule(int $moduleID): int { $module = $this->dao->select('id,type,parent')->from(TABLE_MODULE)->where('id')->eq((int)$moduleID)->fetch(); if(empty($module)) return 0; @@ -1729,7 +1735,7 @@ class treeModel extends model * @access public * @return void */ - public function updateOrder($orders) + public function updateOrder(array $orders): void { asort($orders); $orderInfo = $this->dao->select('*')->from(TABLE_MODULE)->where('id')->in(array_keys($orders))->andWhere('deleted')->eq(0)->fetchAll('id'); @@ -1762,7 +1768,7 @@ class treeModel extends model * @access public * @return array */ - public function manageChild($rootID, $type) + public function manageChild(int $rootID, string $type): array { if($type == 'line') $rootID = 0; @@ -1896,9 +1902,9 @@ class treeModel extends model * @param int $moduleID * @param string $type * @access public - * @return void + * @return bool */ - public function update($moduleID, $type = '') + public function update(int $moduleID, string $type = ''): bool { $module = fixer::input('post')->get(); $self = $this->getById($moduleID); @@ -2003,7 +2009,7 @@ class treeModel extends model * @access public * @return void */ - public function changeRoot($moduleID, $oldRoot, $newRoot, $type) + public function changeRoot(int $moduleID, int $oldRoot, int $newRoot, string $type): void { /* Get all children id list. */ $childIdList = $this->dao->select('id')->from(TABLE_MODULE)->where('path')->like("%,$moduleID,%")->andWhere('deleted')->eq(0)->fetchPairs('id', 'id'); @@ -2055,11 +2061,10 @@ class treeModel extends model * Delete a module. * * @param int $moduleID - * @param null $null compatible with that of model::delete() * @access public - * @return void + * @return bool */ - public function delete($moduleID, $null = null) + public function remove(int $moduleID): bool { $module = $this->getById($moduleID); if(empty($module)) return false; @@ -2133,16 +2138,16 @@ class treeModel extends model /** * Fix the path, grade fields according to the id and parent fields. * - * @param string $root - * @param string $type + * @param int $rootID + * @param string $type * @access public * @return void */ - public function fixModulePath($root, $type) + public function fixModulePath(int $rootID, string $type): void { /* Get all modules grouped by parent. */ if($type == 'bug' or $type == 'case') $type = 'story,' . $type; - $groupModules = $this->dao->select('id, parent, branch')->from(TABLE_MODULE)->where('root')->eq($root)->andWhere('type')->in($type)->andWhere('deleted')->eq(0)->fetchGroup('parent', 'id'); + $groupModules = $this->dao->select('id, parent, branch')->from(TABLE_MODULE)->where('root')->eq($rootID)->andWhere('type')->in($type)->andWhere('deleted')->eq(0)->fetchGroup('parent', 'id'); $modules = array(); /* Cycle the groupModules until it has no item any more. */ @@ -2184,15 +2189,13 @@ class treeModel extends model /** * Check unique module name. * - * @param int $rootID - * @param string $viewType - * @param int $parentModuleID + * @param object $module * @param array $modules * @param array $branches * @access public * @return bool */ - public function checkUnique($module, $modules = array(), $branches = array()) + public function checkUnique(object $module, $modules = array(), $branches = array()): bool { if(empty($branches)) $branches = $this->post->branch; if(empty($branches) and isset($module->branch)) $branches = array($module->branch); @@ -2245,7 +2248,7 @@ class treeModel extends model * @access public * @return bool */ - public function isMergeModule($rootID, $viewType) + public function isMergeModule(int $rootID, string $viewType): bool { if($viewType == 'bug' or $viewType == 'case' or $viewType == 'task') { @@ -2272,7 +2275,7 @@ class treeModel extends model * @access public * @return array */ - public function getProductStructure($rootID, $viewType, $branchID = 'all', $currentModuleID = 0) + public function getProductStructure(int $rootID, string $viewType, string $branchID = 'all', int $currentModuleID = 0): array { if($viewType == 'line') $rootID = 0; $stmt = $this->app->dbQuery($this->buildMenuQuery($rootID, $viewType, $currentModuleID, $branchID)); @@ -2287,11 +2290,11 @@ class treeModel extends model * @param string $viewType * @param int $rootID * @param array $keepModules - * @param string $branchID + * @param string $branch * @access public * @return array */ - public function getDataStructure($stmt, $viewType, $rootID, $keepModules = array(), $branchID = 'all') + public function getDataStructure(object $stmt, string $viewType, int $rootID, array $keepModules = array(), string $branch = 'all'): array { $parent = array(); @@ -2323,7 +2326,7 @@ class treeModel extends model } else { - $module->url = helper::createLink('tree', 'browse', "rootID=$rootID&view=$viewType¤tModuleID=$module->id&branchID=$branchID"); + $module->url = helper::createLink('tree', 'browse', "rootID=$rootID&view=$viewType¤tModuleID=$module->id&branchID=$branch"); } $parent[$module->parent]->children[] = $module; } @@ -2349,7 +2352,7 @@ class treeModel extends model * @access public * @return array */ - public function getDocStructure() + public function getDocStructure(): array { $stmt = $this->app->dbQuery($this->dao->select('*')->from(TABLE_MODULE)->where('type')->eq('doc')->andWhere('deleted')->eq(0)->orderBy('`grade`_desc, `order`')->get()); $parent = array(); @@ -2411,7 +2414,7 @@ class treeModel extends model * @access public * @return void */ - public function setModuleLang() + public function setModuleLang(): void { $this->lang->module = new stdclass(); $this->lang->module->name = $this->lang->tree->wordName; @@ -2422,9 +2425,9 @@ class treeModel extends model * Create module. * * @access public - * @return bool|object + * @return object|false */ - public function createModule() + public function createModule(): object|false { $data = fixer::input('post') ->setDefault('name', '') @@ -2512,7 +2515,7 @@ class treeModel extends model * @access public * @return array */ - public function getGroupPairs($dimensionID = 0, $parentGroup = 0, $grade = 2, $type = 'chart') + public function getGroupPairs(int $dimensionID = 0, int $parentGroup = 0, int $grade = 2, string $type = 'chart'): array { $groups = $this->dao->select('id,name,grade,parent')->from(TABLE_MODULE) ->where('root')->eq($dimensionID) diff --git a/module/tree/ui/edit.html.php b/module/tree/ui/edit.html.php index 525072a09d..1dfc4825d6 100644 --- a/module/tree/ui/edit.html.php +++ b/module/tree/ui/edit.html.php @@ -31,7 +31,6 @@ formPanel set::submitBtnText($lang->save), $showProduct ? formRow ( - set::className($hiddenProduct ? 'hidden' : ''), formGroup ( set::label($lang->tree->product), diff --git a/module/tree/zen.php b/module/tree/zen.php new file mode 100644 index 0000000000..522adf9638 --- /dev/null +++ b/module/tree/zen.php @@ -0,0 +1,300 @@ + + * @link https://www.zentao.net + */ +class treeZen extends tree +{ + /** + * Set root. + * + * @param int $rootID + * @param string $viewType + * @param string $branch + * @static + * @access + * @return object + */ + protected function setRoot(int $rootID, string $viewType, string $branch): object + { + /* 产品线没有root。 Product line has no root. */ + if($viewType == 'line') return (object)array('id' => 0, 'name' => $this->lang->tree->mangeLine, 'rootType' => 'line'); + + if(in_array($viewType, array('host', 'datasource')) || strpos($viewType, '_') !== false) return (object)array('id' => 0, 'name' => $this->lang->tree->manage, 'rootType' => 'line'); + + /* 用例库的root是caselib,其他都是产品。 The root of caselib is caselib, others are product. */ + if(strpos($viewType, 'caselib') !== false) + { + $root = $this->loadModel('caselib')->getById($rootID); + $root->rootType = 'lib'; + + return $root; + } + + $this->loadModel('product'); + + $products = $this->product->getPairs($mode = '', $programID = 0, $append = '', 'all'); + $rootID = $this->product->getAccessibleProductID($rootID, $products); + + if($this->app->tab == 'product') + { + $this->product->setMenu($rootID, $branch, '', $viewType); + } + elseif($this->app->tab == 'qa') + { + $this->loadModel('qa')->setMenu($rootID, $branch); + } + elseif($this->app->tab == 'feedback') + { + $branch = 'all'; + $products = $this->loadModel('feedback')->getGrantProducts(); + if(!$rootID) $rootID = key($products); + $this->loadModel('feedback')->setMenu($rootID, $viewType, $viewType); + } + + $root = $this->product->getByID($rootID); + + if(empty($root)) + { + if($this->viewType == 'json' or (defined('RUN_MODE') && RUN_MODE == 'api')) return $this->send(array('result' => 'fail', 'message' => 'No product.')); + $this->locate($this->createLink('product', 'create')); + } + + $root->rootType = 'product'; + + return $root; + } + + /** + * 获取产品的分支列表。 + * Get branches of product + * + * @param object $product + * @param string $viewType + * @param int $currentModuleID + * @static + * @access protected + * @return array + */ + protected function getBranches(object $product, string $viewType, int $currentModuleID): array + { + if(strpos('story|bug|case', $viewType) !== false) + { + if(!empty($product->type) && $product->type != 'normal') + { + $branches = $this->loadModel('branch')->getPairs($product->id, 'withClosed'); + if($currentModuleID) + { + $currentModuleBranch = $this->dao->select('branch')->from(TABLE_MODULE)->where('id')->eq($currentModuleID)->fetch('branch'); + $branchName = $branches[$currentModuleBranch]; + unset($branches); + $branches[$currentModuleBranch] = $branchName; + } + return $branches; + } + } + + return array(); + } + + /** + * 更新语言项。 + * Update lang. + * + * @param string $viewType + * @static + * @access protected + * @return void + */ + protected function updateBrowseLang(string $viewType) + { + switch($viewType) + { + case 'host': + $this->lang->tree->manage = $this->lang->tree->groupMaintenance; + break; + case 'caselib': + $this->app->loadConfig('qa'); + foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa'; + break; + case 'feedback': + case 'ticket': + $this->app->loadLang('feedback'); + $this->lang->tree->menu = $this->lang->feedback->menu; + case 'dashboard': + $this->lang->tree->menu = $this->lang->report->menu; + break; + case 'trainskill': + $this->lang->tree->menu = $this->lang->trainskill->menu; + break; + case 'trainpost': + $postBrowseType = $this->session->postBrowseType ? $this->session->postBrowseType : 'train'; + $this->lang->tree->menu = $postBrowseType == 'train' ? $this->lang->train->menu : $this->lang->company->menu; + break; + default: + if(strpos($viewType, '_') !== false) // viewType is workflow building category. + { + $this->updateWorkflowLang(); + } + break; + } + + $viewType = ucfirst($viewType); + $this->lang->tree->manage = isset($this->lang->tree->$viewType) ? $this->lang->tree->$viewType : $this->lang->tree->common; + } + + /** + * 更新工作流语言项。 + * Update workflow lang. + * + * @param string $viewType + * @static + * @access protected + * @return void + */ + protected function updateWorkflowLang($viewType) + { + $params = explode('_', $viewType); + if(count($params) == 2) + { + $manageChild = 'manage' . ucfirst($viewType) . 'Child'; + if($viewType == 'datasource') + { + $datasourceID = $params[1]; + $datasource = $this->loadModel('workflowdatasource', 'flow')->getByID($datasourceID); + if($datasource) + { + $this->lang->tree->$manageChild = $datasource->name; + $this->lang->tree->manage = $datasource->name; + } + } + else + { + $this->lang->tree->$manageChild = $this->lang->tree->common; + } + } + } + + /** + * 更新 rawModule。 + * Update rawModule. + * + * @param string $viewType + * @static + * @access protected + * @return void + */ + protected function updateRawModule(string $viewType) + { + $manageLangs = array(''); + switch($viewType) + { + case 'bug': + $this->app->loadConfig('qa'); + foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa'; + $this->app->rawModule = 'bug'; + break; + case 'case': + $this->app->loadConfig('qa'); + foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa'; + $this->app->rawModule = 'testcase'; + break; + case 'caselib': + $this->loadModel('caselib'); + $this->caselib->setLibMenu($this->caselib->getLibraries(), $rootID); + $this->app->rawModule = 'caselib'; + break; + case 'datasource': + $this->app->rawModule = 'workflowdatasource'; + break; + default: + /* viewType is workflow building category. */ + if(strpos($viewType, '_') !== false) + { + $params = explode('_', $viewType); + if(count($params) == 2) $this->app->rawModule = $params[0]; + } + } + } + + /** + * 输出MHTML格式的OptionMenu。 + * Print OptionMenu typed of MHTML. + * + * @param array $optionMenu + * @param string $viewType + * @param int $rootID + * @static + * @access protected + * @return void + */ + protected function printOptionMenuMHtml($optionMenu, $viewType, $rootID) + { + $changeFunc = ''; + if($viewType == 'bug' or $viewType == 'case') $changeFunc = "onchange='loadModuleRelated()'"; + if($viewType == 'task') $changeFunc = "onchange='setStories(this.value, $rootID)'"; + $field = $fieldID ? "modules[$fieldID]" : 'module'; + $output = html::select("$field", $optionMenu, '', "class='input' $changeFunc"); + print($output); + } + + /** + * 输出Item格式的OptionMenu。 + * Print OptionMenu typed of Item. + * + * @param array $optionMenu + * @static + * @access protected + * @return void + */ + protected function printOptionMenuArray($optionMenu) + { + $output = array(); + foreach($optionMenu as $menuID => $menu) $output[] = array('text' => $menu, 'value' => $menuID, 'keys' => $menu); + print(json_encode($output)); + } + + /** + * 输出HTML格式的OptionMenu。 + * Print OptionMenu typed of HTML. + * + * @param array $optionMenu + * @param string $viewType + * @param int $fieldID + * @param int $currentModuleID + * @static + * @access protected + * @return void + */ + protected function printOptionMenuHtml($optionMenu, $viewType, $fieldID, $currentModuleID) + { + if($viewType == 'line') + { + $lineID = $this->dao->select('id')->from(TABLE_MODULE)->where('type')->eq('line')->andWhere('deleted')->eq(0)->orderBy('id_desc')->limit(1)->fetch('id'); + + $items = array(); + foreach($optionMenu as $moduleID => $moduleName) $items[] = array('text' => $moduleName, 'value' => $moduleID); + + $output = array('name' => 'line', 'defaultValue' => $lineID, 'items' => $items); + } + else + { + $field = $fieldID !== '' ? "modules[$fieldID]" : 'module'; + + $currentModule = $this->tree->getById($currentModuleID); + $currentModuleID = (isset($currentModule->branch) and $currentModule->branch == 0) ? $currentModuleID : 0; + + $items = array(); + foreach($optionMenu as $moduleID => $moduleName) $items[] = array('text' => $moduleName, 'value' => $moduleID); + + $output = array('name' => $field, 'defaultValue' => $currentModuleID, 'items' => $items); + } + + return print(json_encode($output)); + } +}