v1.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /**
  3. * The dropmenu widget class file of zin 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 sunhao<sunhao@easycorp.ltd>
  8. * @package zin
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. /**
  13. * 1.5 级导航(dropmenu)部件类。
  14. * The dropmenu widget class.
  15. *
  16. * @author Hao Sun
  17. */
  18. class dropmenu extends wg
  19. {
  20. /**
  21. * Define the properties.
  22. *
  23. * @var array
  24. * @access protected
  25. */
  26. protected static $defineProps = array
  27. (
  28. 'id?: string="dropmenu"', // ID,当页面有多个 dropmenu 时确保有唯一的 ID。
  29. 'tab?: string,', // 应用名。
  30. 'module?: string,', // 模块名。
  31. 'method?: string,', // 方法名。
  32. 'objectID?: string,', // 对象 ID。
  33. 'extra?: string,', // 额外参数。
  34. 'url?: string', // 异步获取下拉菜单选项数据的 URL,如果已经指定 module, method,objectID,extra 等参数则可以忽略。
  35. 'text?: string', // 选择按钮上显示的文本。
  36. 'cache?: bool|int=true', // 是否启用缓存。
  37. 'data?: array', // 手动指定数据。
  38. 'menuID?: string' // 指定下拉菜单的ID。
  39. );
  40. /**
  41. * Load the css file.
  42. *
  43. * @access public
  44. * @return string|false
  45. */
  46. public static function getPageCSS()
  47. {
  48. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  49. }
  50. /**
  51. * @param string|int|null $defaultValue
  52. * @param string $menuID
  53. * @param string $id
  54. * @param string|null $url
  55. * @param string|null $text
  56. * @param mixed[]|null $data
  57. */
  58. protected function buildDropmenu($menuID, $id, $url, $text, $data, $defaultValue)
  59. {
  60. $cache = $this->prop('cache');
  61. return zui::dropmenu
  62. (
  63. setID($menuID),
  64. set('_id', $id),
  65. set('_props', array('data-fetcher' => $url, 'data-text' => $text, 'data-default-value' => $defaultValue, 'data-cache' => $cache)),
  66. set('data', $data),
  67. set(array('fetcher' => $url, 'text' => $text, 'defaultValue' => $defaultValue, 'cache' => $cache)),
  68. set($this->getRestProps())
  69. );
  70. }
  71. /**
  72. * 构建子级下拉菜单。
  73. * Build sub drop menu.
  74. *
  75. * @param string $module
  76. * @param string $method
  77. * @param string $tab
  78. * @param string|int $objectID
  79. * @param string|int $extra
  80. * @access public
  81. * @return array
  82. */
  83. public function buildSubDropMenu($module, $method, $tab, $objectID, $extra)
  84. {
  85. $app = data('app');
  86. $subMenu = array();
  87. if(!in_array($module, $app->config->hasBranchMenuModules) || in_array("{$module}-{$method}", $app->config->excludeBranchMenu)) return $subMenu;
  88. if($tab == 'product' || $tab == 'qa') $subMenu[] = $this->buildBranchDropMenu($module, $method, $tab, $objectID, $extra);
  89. if($tab == 'admin') $subMenu[] = $this->buildFlowGroupMenu($module, $method);
  90. return $subMenu;
  91. }
  92. /**
  93. * 构建分支子级下拉菜单。
  94. * Build branch drop menu.
  95. *
  96. * @param string $module
  97. * @param string $method
  98. * @param string $tab
  99. * @param string|int $objectID
  100. * @param string|int $extra
  101. * @access public
  102. * @return object|null
  103. */
  104. public function buildBranchDropMenu($module, $method, $tab, $objectID, $extra)
  105. {
  106. $data = $this->prop('data');
  107. $app = data('app');
  108. $lang = data('lang');
  109. $branchMenu = null;
  110. if(!$objectID) return $branchMenu;
  111. $product = $app->control->loadModel('product')->getByID((int)$objectID);
  112. if($product->type != 'normal')
  113. {
  114. $branchID = '';
  115. if(!is_null(data('branch'))) $branchID = data('branch');
  116. if(!is_null(data('branchID'))) $branchID = data('branchID');
  117. if(strpos((string)$branchID, ',') !== false)
  118. {
  119. $branches = explode(',', $branchID);
  120. $branchID = (!empty($_SESSION['branch']) || $app->session->branch === '0') && in_array($app->session->branch, $branches) ? $app->session->branch : $branches[0];
  121. }
  122. $app->control->loadModel('branch');
  123. /* Get current branch name. */
  124. $branchName = '';
  125. if($branchID == 'all' || $branchID === '')
  126. {
  127. $branchID = 'all';
  128. $branchName = $lang->branch->all;
  129. }
  130. elseif($branchID == 0)
  131. {
  132. $branchName = $lang->branch->main;
  133. }
  134. elseif($branchID > 0)
  135. {
  136. $branchName = $app->control->branch->getByID((string)$branchID);
  137. }
  138. if($module == 'testtask' && $method == 'browse') $extra = data('type');
  139. if($app->moduleName == 'tree' && $app->methodName == 'browse')
  140. {
  141. $module = 'tree';
  142. $method = 'browse';
  143. $extra = data('viewType');
  144. }
  145. $branchURL = createLink('branch', 'ajaxGetDropMenu', "objectID=$objectID&branch=$branchID&module=$module&method=$method&extra=$extra");
  146. $branchMenu = $this->buildDropmenu('branch-dropmenu', 'branch-dropmenu', $branchURL, $branchName, $data, $branchID);
  147. }
  148. return $branchMenu;
  149. }
  150. /**
  151. * 构造流程子级下拉菜单。
  152. * Build flow group menu.
  153. *
  154. * @param string $module
  155. * @param string $method
  156. * @access public
  157. * @return object|null
  158. */
  159. public function buildFlowGroupMenu($module, $method)
  160. {
  161. $data = $this->prop('data');
  162. $app = data('app');
  163. $objectID = data('groupID');
  164. if(!$objectID) return null;
  165. $flowGroup = $app->control->loadModel('workflowGroup')->fetchByID((int)$objectID);
  166. $flowURL = createLink('workflowGroup', 'ajaxGetDropMenu', "objectID=$objectID&module=$module&method=$method");
  167. return $this->buildDropmenu('flow-dropmenu', 'flow-dropmenu', $flowURL, $flowGroup->name, $data, $objectID);
  168. }
  169. /**
  170. * Override the build method.
  171. *
  172. * @access protected
  173. * @return array
  174. */
  175. protected function build()
  176. {
  177. list($url, $text, $objectID, $cache, $tab, $module, $method, $extra, $id, $data, $menuID) = $this->prop(array('url', 'text', 'objectID', 'cache', 'tab', 'module', 'method', 'extra', 'id', 'data', 'menuID'));
  178. $app = data('app');
  179. $lang = data('lang');
  180. $config = data('config');
  181. if(empty($tab)) $tab = $app->tab;
  182. if(empty($module)) $module = $app->rawModule;
  183. if(empty($method)) $method = $app->rawMethod;
  184. /* 打印工作流1.5级导航. */
  185. if($config->edition != 'open')
  186. {
  187. $flow = $app->control->loadModel('workflow')->getByModule($module);
  188. if($flow && $flow->buildin == '0' && $flow->belong) $tab = $flow->belong;
  189. }
  190. if(empty($menuID)) $menuID = $id . '-menu';
  191. if(empty($extra)) $extra = '';
  192. if(empty($objectID)) $objectID = data($tab . 'ID');
  193. if(empty($objectID))
  194. {
  195. $object = data($tab);
  196. if(isset($object->id)) $objectID = $object->id;
  197. }
  198. /*
  199. * 在lite模式下,执行合并到项目视图。所以获取不到项目的时候,尝试获取执行。
  200. * If the lite mode, the execution is merged into the project view. So try to get the execution when the project is not found.
  201. */
  202. if($tab == 'project' && $config->vision == 'lite' && empty($objectID))
  203. {
  204. $object = data('execution');
  205. $objectID = isset($object->id) ? $object->id : data('executionID');
  206. }
  207. if($method == 'showerrornone' && empty($object) && empty($objectID)) return array();
  208. if($module == 'testcase' && in_array($method, array('view', 'edit')) && data('isLibCase')) $tab = 'caselib';
  209. if($config->vision != 'lite' && strpos(',story-create,story-batchcreate,product-browse,projectstory-story,', ",$module-$method,") !== false) $extra = data('storyType');
  210. if($tab == 'dimension' && $module == 'tree' && $method == 'browsegroup') $extra = data('viewType');
  211. if($module == 'testtask' && in_array($method, array('cases', 'view', 'report', 'groupcase', 'linkcase')) && $app->tab == 'qa')
  212. {
  213. $testtaskUrl = createLink('testtask', 'ajaxGetDropMenu', data('switcherParams'));
  214. $testtaskMenu = $this->buildDropmenu('testtask-dropmenu', 'testtask-dropmenu', $testtaskUrl, data('switcherText'), $data, data('switcherObjectID'));
  215. }
  216. if($tab == 'admin')
  217. {
  218. $currentMenuKey = $app->control->loadModel('admin')->getMenuKey();
  219. $extra = $app->rawParams ? reset($app->rawParams) : '';
  220. $text = isset($lang->admin->menuList->{$currentMenuKey}) ? $lang->admin->menuList->{$currentMenuKey}['name'] : $currentMenuKey;
  221. $url = createLink('admin', 'ajaxGetDropMenu', "currentMenuKey={$currentMenuKey}");
  222. $menuID = 'admin-menu';
  223. $objectID = $currentMenuKey;
  224. }
  225. if($tab == 'caselib') $objectID = data('libID');
  226. if($tab == 'demandpool') $objectID = data('poolID');
  227. if($tab == 'feedback')
  228. {
  229. $objectID = data('productID');
  230. $extra = data('viewType') ? data('viewType') : '';
  231. }
  232. if($tab == 'market')
  233. {
  234. $objectID = data('marketID');
  235. if(empty($objectID)) return array();
  236. }
  237. if(empty($url) && empty($data)) $url = createLink($tab, 'ajaxGetDropMenu', "objectID=$objectID&module=$module&method=$method&extra=$extra");
  238. if(empty($text) && !empty($tab) && !empty($objectID))
  239. {
  240. $loadModel = $tab == 'feedback' ? 'product' : $tab;
  241. $object = $app->control->loadModel($loadModel)->getByID((int)$objectID);
  242. $text = $object ? $object->name : '';
  243. if($tab == 'execution')
  244. {
  245. $project = $app->control->loadModel('project')->getByID((int)$object->project);
  246. $text = $project->name . ' / ' . $text;
  247. }
  248. }
  249. /* 如果是产品的 1.5 级导航,把当前产品的类型存入 session 以供后面使用。*/
  250. /* If the tab is product, save the product type to session. */
  251. if($tab == 'product' && isset($object)) $app->session->set('currentProductType', $object->type);
  252. return array
  253. (
  254. $this->buildDropmenu($menuID, $id, $url, $text, $data, $objectID),
  255. $this->buildSubDropMenu($module, $method, $tab, (int)$objectID, $extra),
  256. isset($testtaskMenu) ? $testtaskMenu : null
  257. );
  258. }
  259. }