zen.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * The zen file of report 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 report
  9. * @link https://www.zentao.net
  10. */
  11. class reportZen extends report
  12. {
  13. /**
  14. * 获取每日提醒邮件的内容。
  15. * Get the content of daily reminder mail.
  16. *
  17. * @access public
  18. * @return array
  19. */
  20. protected function getReminder()
  21. {
  22. $this->app->loadConfig('message');
  23. $messageSetting = $this->config->message->setting;
  24. if(is_string($messageSetting)) $messageSetting = json_decode($messageSetting, true);
  25. /* Get reminder data. */
  26. $bugs = $tasks = $todos = $testTasks = $cards = array();
  27. if($this->config->report->dailyreminder->bug) $bugs = $this->report->getUserBugs();
  28. if($this->config->report->dailyreminder->task) $tasks = $this->report->getUserTasks();
  29. if($this->config->report->dailyreminder->todo) $todos = $this->report->getUserTodos();
  30. if($this->config->report->dailyreminder->testTask) $testTasks = $this->report->getUserTestTasks();
  31. $cardMailSetting = isset($messageSetting['mail']['setting']['kanbancard']) ? $messageSetting['mail']['setting']['kanbancard'] : array();
  32. $cardMessageSetting = isset($messageSetting['message']['setting']['kanbancard']) ? $messageSetting['message']['setting']['kanbancard'] : array();
  33. if(in_array('nearing', $cardMailSetting)) $cards = $this->report->getUserKanbanCards();
  34. if(in_array('nearing', $cardMessageSetting)) $this->loadModel('kanban')->saveCardNotice($cards);
  35. /* Get user who need reminders, and set reminder data to them. */
  36. $reminder = array();
  37. $users = array_unique(array_merge(array_keys($bugs), array_keys($tasks), array_keys($todos), array_keys($testTasks), array_keys($cards)));
  38. if(!empty($users)) foreach($users as $user) $reminder[$user] = new stdclass();
  39. if(!empty($bugs)) foreach($bugs as $user => $bug) $reminder[$user]->bugs = $bug;
  40. if(!empty($tasks)) foreach($tasks as $user => $task) $reminder[$user]->tasks = $task;
  41. if(!empty($todos)) foreach($todos as $user => $todo) $reminder[$user]->todos = $todo;
  42. if(!empty($testTasks)) foreach($testTasks as $user => $testTask) $reminder[$user]->testTasks = $testTask;
  43. if(!empty($cards)) foreach($cards as $user => $card) $reminder[$user]->cards = $card;
  44. return $reminder;
  45. }
  46. /**
  47. * 指派年度报告。
  48. * Assign annual data.
  49. *
  50. * @param string $year
  51. * @param string $dept
  52. * @param string $account
  53. * @access public
  54. * @return void
  55. */
  56. protected function assignAnnualReport($year, $dept, $account)
  57. {
  58. /* Assign dept, year, years, depts, accounts and users. */
  59. list($years, $userCount, $accounts, $dept, $year) = $this->assignAnnualBaseData($account, $dept, $year);
  60. /* Assign annual data. */
  61. $this->assignAnnualData($year, (int)$dept, $account, $accounts, $userCount);
  62. $deptEmpty = (int)$dept && empty($accounts);
  63. /* Get contribution releated data. */
  64. $contributionGroups = array();
  65. $maxCount = 0;
  66. foreach($years as $yearValue)
  67. {
  68. $contributionList = $deptEmpty ? array() : $this->report->getUserYearContributions($accounts, $yearValue);
  69. $max = 0;
  70. $radarData = array('product' => 0, 'execution' => 0, 'devel' => 0, 'qa' => 0, 'other' => 0);
  71. if(!empty($contributionList))
  72. {
  73. foreach($contributionList as $objectType => $objectContributions)
  74. {
  75. $sum = array_sum($objectContributions);
  76. if($sum > $max) $max = $sum;
  77. foreach($objectContributions as $actionName => $count)
  78. {
  79. $radarTypes = isset($this->config->report->annualData['radar'][$objectType][$actionName]) ? $this->config->report->annualData['radar'][$objectType][$actionName] : array('other');
  80. foreach($radarTypes as $radarType) $radarData[$radarType] += $count;
  81. }
  82. $contributionGroups[$yearValue] = $radarData;
  83. }
  84. }
  85. else
  86. {
  87. $contributionGroups[$yearValue] = $radarData;
  88. }
  89. /* If year value is selected, set maxCount. */
  90. if($yearValue == $year) $maxCount = $max;
  91. }
  92. $this->view->dept = $dept;
  93. $this->view->year = $year;
  94. $this->view->years = $years;
  95. $this->view->months = $this->report->getYearMonths($year);
  96. $this->view->contributionGroups = $contributionGroups;
  97. $this->view->radarData = $contributionGroups[$year];
  98. $this->view->maxCount = $maxCount;
  99. $this->view->contributionCount = $this->report->getUserYearContributionCount($accounts, $year);
  100. }
  101. /**
  102. * 指派年度报告的基础数据。
  103. * Assign annual base data.
  104. *
  105. * @param string $account
  106. * @param string $dept
  107. * @param string $year
  108. * @access protected
  109. * @return array
  110. */
  111. protected function assignAnnualBaseData($account, $dept, $year)
  112. {
  113. /* Get users. */
  114. if($account)
  115. {
  116. $user = $this->loadModel('user')->getByID($account);
  117. $dept = $user->dept;
  118. }
  119. $userPairs = $this->loadModel('dept')->getDeptUserPairs((int)$dept);
  120. $accounts = !empty($user) ? array($user->account) : array_keys($userPairs);
  121. if(!(int)$dept && empty($account)) $accounts = array(); // 如果dept=0,且没有选具体的人,置空让数据查所有人,否则离职的人的数据查不到
  122. $users = array('' => $this->lang->report->annualData->allUser) + $userPairs;
  123. $firstAction = $this->loadModel('action')->getFirstAction();
  124. $currentYear = date('Y');
  125. $firstYear = empty($firstAction) ? $currentYear : substr($firstAction->date, 0, 4);
  126. /* Get years for use zentao. */
  127. $years = array();
  128. for($thisYear = $firstYear; $thisYear <= $currentYear; $thisYear ++) $years[$thisYear] = (string)$thisYear;
  129. /* Init year when year is empty. */
  130. if(empty($year))
  131. {
  132. $year = date('Y');
  133. $month = date('n');
  134. if($month <= $this->config->report->annualData['minMonth'] && isset($years[$year -1])) $year -= 1;
  135. }
  136. /* Get depts. */
  137. $depts = $this->loadModel('dept')->getOptionMenu();
  138. $noDepartment = array('0' => '/' . $this->lang->dept->noDepartment);
  139. if(!common::hasPriv('screen', 'allAnnualData'))
  140. {
  141. $depts = $dept && isset($depts[$dept]) ? array($dept => $depts[$dept]) : $noDepartment;
  142. }
  143. else
  144. {
  145. unset($depts[0]);
  146. $depts = array('0' => $this->lang->report->annualData->allDept) + $depts;
  147. }
  148. $who = '';
  149. if(isset($depts[$dept]))
  150. {
  151. $who = $depts[$dept];
  152. if(strpos($who, '/') !== false) $who = substr($who, strrpos($who, '/') + 1);
  153. }
  154. if($account) $who = zget($users, $account, '');
  155. $this->view->title = sprintf($this->lang->report->annualData->title, $who, $year);
  156. $this->view->depts = $depts;
  157. $this->view->users = $users;
  158. return array($years, count($users) - 1, $accounts, $dept, (string)$year);
  159. }
  160. /**
  161. * 指派年度数据。
  162. * Assign annual data.
  163. *
  164. * @param string $year
  165. * @param string|int $dept
  166. * @param string $account
  167. * @param array $accounts
  168. * @param int $userCount
  169. * @access protected
  170. * @return void
  171. */
  172. protected function assignAnnualData($year, $dept, $account, $accounts, $userCount)
  173. {
  174. $data = array();
  175. if(!$account)
  176. {
  177. $data['users'] = $dept ? count($accounts) : $userCount;
  178. }
  179. else
  180. {
  181. $data['logins'] = $this->report->getUserYearLogins($accounts, $year);
  182. }
  183. $deptEmpty = (int)$dept && empty($accounts);
  184. $data['actions'] = $deptEmpty ? 0 : $this->report->getUserYearActions($accounts, $year);
  185. $data['todos'] = $deptEmpty ? (object)array('count' => 0, 'undone' => 0, 'done' => 0) : $this->report->getUserYearTodos($accounts, $year);
  186. $data['contributions'] = $deptEmpty ? array() : $this->report->getUserYearContributions($accounts, $year);
  187. $data['executionStat'] = $deptEmpty ? array() : $this->report->getUserYearExecutions($accounts, $year);
  188. $data['productStat'] = $deptEmpty ? array() : $this->report->getUserYearProducts($accounts, $year);
  189. $data['storyStat'] = $deptEmpty ? array('statusStat' => array(), 'actionStat' => array()) : $this->report->getYearObjectStat($accounts, $year, 'story');
  190. $data['taskStat'] = $deptEmpty ? array('statusStat' => array(), 'actionStat' => array()) : $this->report->getYearObjectStat($accounts, $year, 'task');
  191. $data['bugStat'] = $deptEmpty ? array('statusStat' => array(), 'actionStat' => array()) : $this->report->getYearObjectStat($accounts, $year, 'bug');
  192. $data['caseStat'] = $deptEmpty ? array('resultStat' => array(), 'actionStat' => array()) : $this->report->getYearCaseStat($accounts, $year);
  193. $yearEfforts = $this->report->getUserYearEfforts($accounts, $year);
  194. $data['consumed'] = $deptEmpty ? 0 : $yearEfforts->consumed;
  195. if(empty($dept) && empty($account)) $data['statusStat'] = $this->report->getAllTimeStatusStat();
  196. $this->view->data = $data;
  197. }
  198. }