zen.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. /**
  3. * The zen file of my 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 Mengyi Liu <liumengyi@easycorp.ltd>
  8. * @package my
  9. * @link https://www.zentao.net
  10. */
  11. class myZen extends my
  12. {
  13. /**
  14. * 构造任务数据。
  15. * Build task data.
  16. *
  17. * @param array $tasks
  18. * @access protected
  19. * @return array
  20. */
  21. protected function buildTaskData($tasks)
  22. {
  23. $parents = array();
  24. foreach($tasks as $task)
  25. {
  26. if(isset($tasks[$task->parent]) || $task->parent <= 0 || isset($parents[$task->parent])) continue;
  27. $parents[$task->parent] = $task->parent;
  28. }
  29. $parentPairs = $this->loadModel('task')->getPairsByIdList($parents);
  30. foreach($tasks as $task)
  31. {
  32. $task->estimateLabel = $task->estimate . $this->lang->execution->workHourUnit;
  33. $task->consumedLabel = $task->consumed . $this->lang->execution->workHourUnit;
  34. $task->leftLabel = $task->left . $this->lang->execution->workHourUnit;
  35. $task->status = !empty($task->storyStatus) && $task->storyStatus == 'active' && $task->latestStoryVersion > $task->storyVersion && !in_array($task->status, array('cancel', 'closed')) ? 'changed' : $task->status;
  36. $task->canBeChanged = common::canBeChanged('task', $task);
  37. $task->isChild = false;
  38. $task->parentName = '';
  39. if($task->status == 'changed') $task->rawStatus = 'changed';
  40. if($task->parent > 0)
  41. {
  42. if(isset($tasks[$task->parent]))
  43. {
  44. $tasks[$task->parent]->hasChild = true;
  45. }
  46. else
  47. {
  48. $task->name = zget($parentPairs, $task->parent, '') . ' / ' . $task->name;
  49. $task->isChild = true;
  50. $task->parent = 0;
  51. }
  52. }
  53. }
  54. return $tasks;
  55. }
  56. /**
  57. * 构造用例数据。
  58. * Build case data.
  59. *
  60. * @param array $cases
  61. * @param string $type assigntome|openedbyme
  62. * @access protected
  63. * @return array
  64. */
  65. protected function buildCaseData($cases, $type)
  66. {
  67. $cases = $this->loadModel('story')->checkNeedConfirm($cases);
  68. $cases = $this->loadModel('testcase')->appendData($cases, $type == 'assigntome' ? 'run' : 'case');
  69. $failCount = 0;
  70. foreach($cases as $case)
  71. {
  72. if($case->lastRunResult && $case->lastRunResult != 'pass') $failCount ++;
  73. if($case->needconfirm)
  74. {
  75. $case->status = $this->lang->story->changed;
  76. }
  77. else if(isset($case->fromCaseVersion) and $case->fromCaseVersion > $case->version and !$case->needconfirm)
  78. {
  79. $case->status = $this->lang->testcase->changed;
  80. }
  81. if(!$case->lastRunResult) $case->lastRunResult = $this->lang->testcase->unexecuted;
  82. }
  83. $this->view->failCount = $failCount;
  84. return $cases;
  85. }
  86. /**
  87. * 构造反馈关联的数据。
  88. * Build related data.
  89. *
  90. * @param array $feedbacks
  91. * @access protected
  92. * @return void
  93. */
  94. protected function assignRelatedData($feedbacks)
  95. {
  96. $storyIdList = $bugIdList = $todoIdList = $taskIdList = $ticketIdList = array();
  97. foreach($feedbacks as $feedback)
  98. {
  99. if($feedback->solution == 'tobug') $bugIdList[] = $feedback->result;
  100. if($feedback->solution == 'tostory') $storyIdList[] = $feedback->result;
  101. if($feedback->solution == 'totodo') $todoIdList[] = $feedback->result;
  102. if($feedback->solution == 'totask') $taskIdList[] = $feedback->result;
  103. if($feedback->solution == 'ticket') $ticketIdList[] = $feedback->result;
  104. }
  105. $bugs = $bugIdList ? $this->loadModel('bug')->getByIdList($bugIdList) : array();
  106. $stories = $storyIdList ? $this->loadModel('story')->getByList($storyIdList) : array();
  107. $todos = $todoIdList ? $this->loadModel('todo')->getByList($todoIdList) : array();
  108. $tasks = $taskIdList ? $this->loadModel('task')->getByIdList($taskIdList) : array();
  109. $tickets = $ticketIdList ? $this->loadModel('ticket')->getByList($ticketIdList) : array();
  110. $this->view->bugs = $bugs;
  111. $this->view->todos = $todos;
  112. $this->view->stories = $stories;
  113. $this->view->tasks = $tasks;
  114. $this->view->tickets = $tickets;
  115. }
  116. /**
  117. * 构造反馈的搜索表单。
  118. * Build search form for feedback.
  119. *
  120. * @param int $queryID
  121. * @param string $orderBy
  122. * @access protected
  123. * @return void
  124. */
  125. protected function buildSearchFormForFeedback($queryID, $orderBy)
  126. {
  127. $rawMethod = $this->app->rawMethod;
  128. $this->config->feedback->search['module'] = $rawMethod . 'Feedback';
  129. $this->config->feedback->search['actionURL'] = inlink($rawMethod, "mode=feedback&browseType=bysearch&param=myQueryID&orderBy={$orderBy}");
  130. $this->config->feedback->search['queryID'] = $queryID;
  131. $this->config->feedback->search['params']['product']['values'] = $this->loadModel('product')->getPairs();
  132. $this->config->feedback->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu(0, 'feedback', 0);
  133. $this->config->feedback->search['params']['processedBy']['values'] = $this->loadModel('feedback')->getFeedbackPairs('admin');
  134. if($rawMethod == 'work')
  135. {
  136. unset($this->config->feedback->search['fields']['assignedTo']);
  137. unset($this->config->feedback->search['fields']['closedBy']);
  138. unset($this->config->feedback->search['fields']['closedDate']);
  139. unset($this->config->feedback->search['fields']['closedReason']);
  140. unset($this->config->feedback->search['fields']['processedBy']);
  141. unset($this->config->feedback->search['fields']['processedDate']);
  142. unset($this->config->feedback->search['fields']['solution']);
  143. }
  144. $this->loadModel('search')->setSearchParams($this->config->feedback->search);
  145. }
  146. /**
  147. * 展示待处理的数量。
  148. * Show to-do work count.
  149. *
  150. * @param int $recTotal
  151. * @param int $recPerPage
  152. * @param int $pageID
  153. * @access public
  154. * @return array
  155. */
  156. public function showWorkCount($recTotal = 0, $recPerPage = 20, $pageID = 1)
  157. {
  158. /* Load pager. */
  159. $this->app->loadClass('pager', true);
  160. if($this->app->getViewType() == 'mhtml') $recPerPage = 10;
  161. $pager = pager::init($recTotal, $recPerPage, $pageID);
  162. $count = array('task' => 0, 'aitask' => 0, 'story' => 0, 'bug' => 0, 'case' => 0, 'testtask' => 0, 'requirement' => 0, 'issue' => 0, 'risk' => 0, 'qa' => 0, 'meeting' => 0, 'ticket' => 0, 'feedback' => 0);
  163. /* Get the number of tasks assigned to me. */
  164. $this->loadModel('task')->getUserTasks($this->app->user->account, 'assignedTo', 0, $pager);
  165. $count['task'] = $pager->recTotal;
  166. /* Get the number of stories assigned to me. */
  167. $pager->recTotal = 0;
  168. $this->loadModel('story')->getUserStories($this->app->user->account, 'assignedTo', 'id_desc', $pager, 'story', false, 'all');
  169. $assignedToStoryCount = $pager->recTotal;
  170. $pager->recTotal = 0;
  171. $this->story->getUserStories($this->app->user->account, 'reviewBy', 'id_desc', $pager, 'story', false, 'all');
  172. $reviewByStoryCount = $pager->recTotal;
  173. $count['story'] = $assignedToStoryCount + $reviewByStoryCount;
  174. $isOpenedURAndSR = $this->config->URAndSR ? 1 : 0;
  175. if($isOpenedURAndSR)
  176. {
  177. /* Get the number of requirements assigned to me. */
  178. $pager->recTotal = 0;
  179. $this->story->getUserStories($this->app->user->account, 'assignedTo', 'id_desc', $pager, 'requirement', false, 'all');
  180. $assignedRequirementCount = $pager->recTotal;
  181. $pager->recTotal = 0;
  182. $this->story->getUserStories($this->app->user->account, 'reviewBy', 'id_desc', $pager, 'requirement', false, 'all');
  183. $reviewByRequirementCount = $pager->recTotal;
  184. $count['requirement'] = $assignedRequirementCount + $reviewByRequirementCount;
  185. }
  186. if($this->config->enableER)
  187. {
  188. $pager->recTotal = 0;
  189. $this->story->getUserStories($this->app->user->account, 'assignedTo', 'id_desc', $pager, 'epic', false, 'all');
  190. $assignedEpicCount = $pager->recTotal;
  191. $pager->recTotal = 0;
  192. $this->story->getUserStories($this->app->user->account, 'reviewBy', 'id_desc', $pager, 'epic', false, 'all');
  193. $reviewByEpicCount = $pager->recTotal;
  194. $count['epic'] = $assignedEpicCount + $reviewByEpicCount;
  195. }
  196. /* Get the number of bugs assigned to me. */
  197. $pager->recTotal = 0;
  198. $this->loadModel('bug')->getUserBugs($this->app->user->account, 'assignedTo', 'id_desc', 0, $pager);
  199. $count['bug'] = $pager->recTotal;
  200. /* Get the number of testcases assigned to me. */
  201. $pager->recTotal = 0;
  202. $this->loadModel('testcase')->getByAssignedTo($this->app->user->account, 'skip', 'id_desc', $pager);
  203. $count['case'] = $pager->recTotal;
  204. /* Get the number of testtasks assigned to me. */
  205. $pager->recTotal = 0;
  206. $this->loadModel('testtask')->getByUser($this->app->user->account, $pager, 'id_desc', 'wait');
  207. $count['testtask'] = $pager->recTotal;
  208. $pager->recTotal = 0;
  209. $count = $this->showWorkCountNotInOpen($count, $pager);
  210. $this->view->todoCount = $count;
  211. $this->view->isOpenedURAndSR = $isOpenedURAndSR;
  212. return $count;
  213. }
  214. /**
  215. * 展示非开源版的待处理的数量。
  216. * Show to-do work count that not in open edition.
  217. *
  218. * @param array $count
  219. * @param object $pager
  220. * @access public
  221. * @return array
  222. */
  223. protected function showWorkCountNotInOpen($count, $pager)
  224. {
  225. $isBiz = $this->config->edition == 'biz' ? 1 : 0;
  226. $isMax = $this->config->edition == 'max' ? 1 : 0;
  227. $isIPD = $this->config->edition == 'ipd' ? 1 : 0;
  228. if($this->config->edition != 'open')
  229. {
  230. if(!empty($this->config->enableAITeammate))
  231. {
  232. $this->loadModel('aitask')->getList(0, 'done', 'id_desc', $pager, $this->app->user->account);
  233. $count['aitask'] = $pager->recTotal;
  234. }
  235. $pager->recTotal = 0;
  236. $this->loadModel('feedback')->getList('assigntome', 'id_desc', $pager);
  237. $count['feedback'] = $pager->recTotal;
  238. $pager->recTotal = 0;
  239. $this->session->set('ticketBrowseType', 'assignedtome', 'feedback');
  240. $this->loadModel('ticket')->getList('assignedtome', 'id_desc', $pager);
  241. $count['ticket'] = $pager->recTotal;
  242. }
  243. if($isMax || $isIPD)
  244. {
  245. if($this->config->vision != 'or')
  246. {
  247. /* Get the number of issues assigned to me. */
  248. $pager->recTotal = 0;
  249. $this->loadModel('issue')->getUserIssues('assignedTo', 0, $this->app->user->account, 'id_desc', $pager);
  250. $count['issue'] = $pager->recTotal;
  251. /* Get the number of risks assigned to me. */
  252. $pager->recTotal = 0;
  253. $this->loadModel('risk')->getUserRisks('assignedTo', $this->app->user->account, 'id_desc', $pager);
  254. $count['risk'] = $pager->recTotal;
  255. /* Get the number of reviewissues assigned to me. */
  256. $pager->recTotal = 0;
  257. $this->loadModel('reviewissue')->getUserReviewissues('assignedTo', $this->app->user->account, 'id_desc', $pager);
  258. $count['reviewissue'] = $pager->recTotal;
  259. /* Get the number of nc assigned to me. */
  260. $pager->recTotal = 0;
  261. $this->my->getNcList('assignedToMe', 'id_desc', $pager, 'active');
  262. $ncCount = $pager->recTotal;
  263. /* Get the number of nc assigned to me. */
  264. $pager->recTotal = 0;
  265. $this->loadModel('auditplan')->getList(0, 'myChecking', '', 'id_desc', $pager);
  266. $auditplanCount = $pager->recTotal;
  267. $count['qa'] = $ncCount + $auditplanCount;
  268. /* Get the number of meetings assigned to me. */
  269. $pager->recTotal = 0;
  270. $this->loadModel('meeting')->getListByUser('futureMeeting', 'id_desc', 0, $pager);
  271. $count['meeting'] = $pager->recTotal;
  272. }
  273. if($isIPD && $this->config->vision == 'or')
  274. {
  275. /* Get the number of demands assigned to me. */
  276. $pager->recTotal = 0;
  277. $this->loadModel('demand')->getUserDemands($this->app->user->account, 'assignedTo', 'id_desc', $pager);
  278. $assignedToDemandCount = $pager->recTotal;
  279. /* Get the number of demands review by me. */
  280. $pager->recTotal = 0;
  281. $this->loadModel('demand')->getUserDemands($this->app->user->account, 'reviewBy', 'id_desc', $pager);
  282. $reviewByDemandCount = $pager->recTotal;
  283. $count['demand'] = $assignedToDemandCount + $reviewByDemandCount;
  284. }
  285. }
  286. $this->view->isBiz = $isBiz;
  287. $this->view->isMax = $isMax;
  288. $this->view->isIPD = $isIPD;
  289. return $count;
  290. }
  291. }