zen.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?php
  2. /**
  3. * The zen file of tree module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author lanzongjun <lanzongjun@easycorp.ltd>
  8. * @link https://www.zentao.net
  9. */
  10. class treeZen extends tree
  11. {
  12. /**
  13. * Set root.
  14. *
  15. * @param int $rootID
  16. * @param string $viewType
  17. * @param string $branch
  18. * @static
  19. * @access
  20. * @return object
  21. */
  22. protected function setRoot($rootID, $viewType, $branch)
  23. {
  24. /* 产品线没有root。 Product line has no root. */
  25. if($viewType == 'line') return (object)array('id' => 0, 'name' => $this->lang->tree->mangeLine, 'rootType' => 'line');
  26. if(in_array($viewType, array('host'))) return (object)array('id' => 0, 'name' => $this->lang->host->groupMaintenance, 'rootType' => 'line');
  27. if(in_array($viewType, array('datasource')) || strpos($viewType, '_') !== false) return (object)array('id' => 0, 'name' => $this->lang->tree->manage, 'rootType' => 'line');
  28. /* 用例库的root是caselib,其他都是产品。 The root of caselib is caselib, others are product. */
  29. if(strpos($viewType, 'caselib') !== false)
  30. {
  31. $root = $this->loadModel('caselib')->getById($rootID);
  32. $root->rootType = 'lib';
  33. return $root;
  34. }
  35. $products = $this->loadModel('product')->getPairs('', 0, '', 'all');
  36. $rootID = $this->product->getAccessibleProductID($rootID, $products);
  37. if($this->app->tab == 'product')
  38. {
  39. $this->product->setMenu($rootID, $branch, '', $viewType);
  40. }
  41. elseif($this->app->tab == 'qa')
  42. {
  43. $this->loadModel('qa')->setMenu($rootID, $branch);
  44. }
  45. elseif($this->app->tab == 'feedback')
  46. {
  47. $branch = 'all';
  48. $products = $this->loadModel('feedback')->getGrantProducts();
  49. if(!$rootID) $rootID = key($products);
  50. $this->loadModel('feedback')->setMenu($rootID, $viewType, $viewType);
  51. }
  52. $root = $this->product->getByID($rootID);
  53. if(empty($root))
  54. {
  55. if($this->viewType == 'json' or (defined('RUN_MODE') && RUN_MODE == 'api')) return $this->send(array('result' => 'fail', 'message' => 'No product.'));
  56. $this->locate($this->createLink('product', 'create'));
  57. }
  58. $root->rootType = 'product';
  59. return $root;
  60. }
  61. /**
  62. * 获取产品的分支列表。
  63. * Get branches of product
  64. *
  65. * @param object $product
  66. * @param string $viewType
  67. * @param int $currentModuleID
  68. * @static
  69. * @access protected
  70. * @return array
  71. */
  72. protected function getBranches($product, $viewType, $currentModuleID)
  73. {
  74. if(strpos('story|bug|case', $viewType) !== false)
  75. {
  76. if(!empty($product->type) && $product->type != 'normal')
  77. {
  78. $branches = $this->loadModel('branch')->getPairs($product->id, 'withClosed');
  79. if($currentModuleID)
  80. {
  81. $currentModuleBranch = $this->dao->select('branch')->from(TABLE_MODULE)->where('id')->eq($currentModuleID)->fetch('branch');
  82. $branchName = $branches[$currentModuleBranch];
  83. unset($branches);
  84. $branches[$currentModuleBranch] = $branchName;
  85. }
  86. return $branches;
  87. }
  88. }
  89. return array();
  90. }
  91. /**
  92. * 更新语言项。
  93. * Update lang.
  94. *
  95. * @param string $viewType
  96. * @static
  97. * @access protected
  98. * @return void
  99. */
  100. protected function updateBrowseLang($viewType)
  101. {
  102. switch($viewType)
  103. {
  104. case 'host':
  105. $this->lang->tree->manage = $this->lang->tree->groupMaintenance;
  106. break;
  107. case 'caselib':
  108. $this->app->loadConfig('qa');
  109. foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa';
  110. break;
  111. case 'feedback':
  112. case 'ticket':
  113. $this->app->loadLang('feedback');
  114. $this->lang->tree->menu = $this->lang->feedback->menu;
  115. break;
  116. case 'trainskill':
  117. $this->lang->tree->menu = $this->lang->trainskill->menu;
  118. break;
  119. case 'trainpost':
  120. $postBrowseType = $this->session->postBrowseType ? $this->session->postBrowseType : 'train';
  121. $this->lang->tree->menu = $postBrowseType == 'train' ? $this->lang->train->menu : $this->lang->company->menu;
  122. break;
  123. default:
  124. if(strpos($viewType, '_') !== false) // viewType is workflow building category.
  125. {
  126. $this->updateWorkflowLang($viewType);
  127. }
  128. break;
  129. }
  130. $viewType = ucfirst($viewType);
  131. $this->lang->tree->manage = isset($this->lang->tree->$viewType) ? $this->lang->tree->$viewType : $this->lang->tree->common;
  132. }
  133. /**
  134. * 更新工作流语言项。
  135. * Update workflow lang.
  136. *
  137. * @param string $viewType
  138. * @access protected
  139. * @return void
  140. */
  141. protected function updateWorkflowLang($viewType)
  142. {
  143. $params = explode('_', $viewType);
  144. if(count($params) == 2)
  145. {
  146. $manageChild = 'manage' . ucfirst($viewType) . 'Child';
  147. $this->lang->tree->common = $this->lang->workflowdatasource->category;
  148. $this->lang->tree->name = $this->lang->tree->cate;
  149. $this->lang->tree->$manageChild = $this->lang->tree->common;
  150. if(strpos($viewType, 'datasource') !== false)
  151. {
  152. $datasourceID = $params[1];
  153. $datasource = $this->loadModel('workflowdatasource', 'flow')->getByID($datasourceID);
  154. if($datasource)
  155. {
  156. $this->lang->tree->$manageChild = $datasource->name;
  157. $this->lang->tree->manage = $datasource->name;
  158. $this->lang->tree->common = $this->lang->workflowdatasource->category;
  159. $this->lang->tree->name = $this->lang->tree->cate;
  160. }
  161. }
  162. }
  163. }
  164. /**
  165. * 更新 rawModule。
  166. * Update rawModule.
  167. *
  168. * @param int $rootID
  169. * @param string $viewType
  170. * @access protected
  171. * @return void
  172. */
  173. protected function updateRawModule($rootID, $viewType)
  174. {
  175. $manageLangs = array('');
  176. switch($viewType)
  177. {
  178. case 'bug':
  179. $this->app->loadConfig('qa');
  180. foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa';
  181. $this->app->rawModule = 'bug';
  182. break;
  183. case 'case':
  184. $this->app->loadConfig('qa');
  185. foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa';
  186. $this->app->rawModule = 'testcase';
  187. break;
  188. case 'caselib':
  189. $this->loadModel('caselib');
  190. $this->caselib->setLibMenu($this->caselib->getLibraries(), $rootID);
  191. $this->app->rawModule = 'caselib';
  192. break;
  193. case 'datasource':
  194. $this->app->rawModule = 'workflowdatasource';
  195. break;
  196. default:
  197. /* viewType is workflow building category. */
  198. if(strpos($viewType, '_') !== false)
  199. {
  200. $params = explode('_', $viewType);
  201. if(count($params) == 2) $this->app->rawModule = $params[0] == 'datasource' ? 'workflowdatasource' : $params[0];
  202. }
  203. }
  204. }
  205. /**
  206. * 输出MHTML格式的OptionMenu。
  207. * Print OptionMenu typed of MHTML.
  208. *
  209. * @param array $optionMenu
  210. * @param string $viewType
  211. * @param int $rootID
  212. * @static
  213. * @access protected
  214. * @return void
  215. */
  216. protected function printOptionMenuMHtml($optionMenu, $viewType, $rootID)
  217. {
  218. $changeFunc = '';
  219. if($viewType == 'bug' or $viewType == 'case') $changeFunc = "onchange='loadModuleRelated()'";
  220. if($viewType == 'task') $changeFunc = "onchange='setStories(this.value, $rootID)'";
  221. $field = $fieldID ? "modules[$fieldID]" : 'module';
  222. $output = html::select("$field", $optionMenu, '', "class='input' $changeFunc");
  223. print($output);
  224. }
  225. /**
  226. * 输出Item格式的OptionMenu。
  227. * Print OptionMenu typed of Item.
  228. *
  229. * @param array $optionMenu
  230. * @static
  231. * @access protected
  232. * @return void
  233. */
  234. protected function printOptionMenuArray($optionMenu)
  235. {
  236. $output = array();
  237. foreach($optionMenu as $menuID => $menu) $output[] = array('text' => $menu, 'value' => $menuID, 'keys' => $menu);
  238. print(json_encode($output));
  239. }
  240. /**
  241. * 输出HTML格式的OptionMenu。
  242. * Print OptionMenu typed of HTML.
  243. *
  244. * @param array $optionMenu
  245. * @param string $viewType
  246. * @param int $fieldID
  247. * @param int $currentModuleID
  248. * @static
  249. * @access protected
  250. * @return void
  251. */
  252. protected function printOptionMenuHtml($optionMenu, $viewType, $fieldID, $currentModuleID)
  253. {
  254. if($viewType == 'line')
  255. {
  256. $lineID = $this->dao->select('id')->from(TABLE_MODULE)->where('type')->eq('line')->andWhere('deleted')->eq(0)->orderBy('id_desc')->limit(1)->fetch('id');
  257. $items = array();
  258. foreach($optionMenu as $moduleID => $moduleName) $items[] = array('text' => $moduleName, 'value' => $moduleID);
  259. $output = array('name' => 'line', 'defaultValue' => $lineID, 'items' => $items);
  260. }
  261. else
  262. {
  263. $field = $fieldID !== '' ? "modules[$fieldID]" : 'module';
  264. $currentModule = $this->tree->getById($currentModuleID);
  265. $currentModuleID = (isset($currentModule->branch) and $currentModule->branch == 0) ? $currentModuleID : 0;
  266. $items = array();
  267. foreach($optionMenu as $moduleID => $moduleName) $items[] = array('text' => $moduleName, 'value' => $moduleID);
  268. $output = array('name' => $field, 'defaultValue' => $currentModuleID, 'items' => $items);
  269. }
  270. return print(json_encode($output));
  271. }
  272. }