zen.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. <?php
  2. /**
  3. * The zen file of testreport 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 testreport
  9. * @link https://www.zentao.net
  10. */
  11. class testreportZen extends testreport
  12. {
  13. /**
  14. * 检查相关权限,并且设置相关菜单。
  15. * Check related access and set menu.
  16. *
  17. * @param int $objectID
  18. * @param string $objectType
  19. * @access public
  20. * @return int
  21. */
  22. protected function commonAction($objectID, $objectType = 'product')
  23. {
  24. if($objectType == 'product')
  25. {
  26. $productID = $this->product->checkAccess($objectID, $this->products);
  27. if($this->app->apiVersion && $objectID != $productID) return $this->sendError('Cannot access this product.');
  28. $this->loadModel('qa')->setMenu($productID);
  29. $this->view->productID = $productID;
  30. return $productID;
  31. }
  32. if($objectType == 'execution')
  33. {
  34. $executions = $this->execution->getPairs();
  35. $executionID = $this->execution->checkAccess($objectID, $executions);
  36. if($this->app->apiVersion && $objectID != $executionID) return $this->sendError('Cannot access this execution.');
  37. $this->execution->setMenu($executionID);
  38. $this->view->executionID = $executionID;
  39. return $executionID;
  40. }
  41. if($objectType == 'project')
  42. {
  43. $projects = $this->project->getPairsByProgram();
  44. $projectID = $this->project->checkAccess($objectID, $projects);
  45. if($this->app->apiVersion && $objectID != $projectID) return $this->sendError('Cannot access this project.');
  46. $this->project->setMenu($projectID);
  47. $this->view->projectID = $projectID;
  48. return $projectID;
  49. }
  50. }
  51. /**
  52. * 为浏览页面获取报告
  53. * Get reports for browse.
  54. *
  55. * @param int $objectID
  56. * @param string $objectType
  57. * @param int $extra
  58. * @param string $orderBy
  59. * @param int $recTotal
  60. * @param int $recPerPage
  61. * @param int $pageID
  62. * @access protected
  63. * @return array
  64. */
  65. protected function getReportsForBrowse($objectID = 0, $objectType = 'product', $extra = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  66. {
  67. /* Load pager. */
  68. $this->app->loadClass('pager', $static = true);
  69. if($this->app->getViewType() == 'mhtml') $recPerPage = 10;
  70. $pager = pager::init($recTotal, $recPerPage, $pageID);
  71. $reports = $this->testreport->getList($objectID, $objectType, $extra, $orderBy, $pager);
  72. if(strpos('|project|execution|', $objectType) !== false && ($extra || isset($_POST['taskIdList'])))
  73. {
  74. $taskIdList = isset($_POST['taskIdList']) ? $_POST['taskIdList'] : array($extra);
  75. foreach($reports as $reportID => $report)
  76. {
  77. $tasks = explode(',', $report->tasks);
  78. if(count($tasks) != count($taskIdList) || array_diff($tasks, $taskIdList)) unset($reports[$reportID]);
  79. }
  80. $pager->setRecTotal(count($reports));
  81. }
  82. $this->view->pager = $pager;
  83. return $reports;
  84. }
  85. /**
  86. * 为创建获取任务键值。
  87. * Get task pairs for creation.
  88. *
  89. * @param int $objectID
  90. * @param string $extra
  91. * @access protected
  92. * @return array
  93. */
  94. protected function assignTaskParisForCreate($objectID = 0, $extra = '')
  95. {
  96. if(!$objectID && $extra) $productID = (int)$extra;
  97. if($objectID)
  98. {
  99. $task = $this->testtask->getByID($objectID);
  100. $productID = !empty($_SESSION['product']) && !empty($task->joint) ? $this->session->product : $task->product;
  101. $productID = $this->commonAction($productID, 'product');
  102. }
  103. $taskPairs = array();
  104. $tasks = $this->testtask->getProductTasks($productID, empty($objectID) ? 'all' : $task->branch, 'local,totalStatus', '', '', 'id_desc', null);
  105. foreach($tasks as $testTask)
  106. {
  107. if($testTask->build != 'trunk') $taskPairs[$testTask->id] = $testTask->name;
  108. }
  109. if(!$taskPairs)
  110. {
  111. $confirmedURL = $this->createLink('testtask', 'create', "proudctID={$productID}" . ($this->app->tab == 'execution' ? "&executionID={$this->session->execution}" : ''));
  112. return $this->send(array('result' => 'fail', 'load' => array('confirm' => $this->lang->testreport->noTestTask, 'confirmed' => $confirmedURL, 'canceled' => inlink('browse', "proudctID={$productID}"))));
  113. }
  114. if(!$objectID)
  115. {
  116. $objectID = key($taskPairs);
  117. $task = $this->testtask->getByID($objectID);
  118. $productID = !empty($_SESSION['product']) && !empty($task->joint) ? $this->session->product : $task->product;
  119. $productID = $this->commonAction($productID, 'product');
  120. }
  121. $this->view->taskPairs = $taskPairs;
  122. $this->view->productID = $productID;
  123. return array($objectID, $task, $productID);
  124. }
  125. /**
  126. * 获取测试单的测试报告数据。
  127. * Get testtask report data.
  128. *
  129. * @param int $objectID
  130. * @param string $begin
  131. * @param string $end
  132. * @param int $productID
  133. * @param object $task
  134. * @param string $method
  135. * @access public
  136. * @return array
  137. */
  138. public function assignTesttaskReportData($objectID, $begin = '', $end = '', $productID = 0, $task = null, $method = 'create')
  139. {
  140. $begin = !empty($begin) ? date("Y-m-d", strtotime($begin)) : $task->begin;
  141. $end = !empty($end) ? date("Y-m-d", strtotime($end)) : $task->end;
  142. $productIdList[$productID] = $productID;
  143. $build = $this->build->getById((int)$task->build);
  144. $builds = !empty($build->id) ? array($build->id => $build) : array();
  145. $bugs = $this->testreport->getBugs4Test($builds, $productID, $begin, $end);
  146. $tasks = array($task->id => $task);
  147. $owner = $task->owner;
  148. $stories = empty($build->stories) ? array() : $this->story->getByList($build->stories);
  149. $execution = $this->execution->getById($task->execution ? $task->execution : $task->project);
  150. $this->setChartDatas($objectID);
  151. if($method == 'create')
  152. {
  153. if($this->app->tab == 'execution') $this->execution->setMenu($task->execution);
  154. if($this->app->tab == 'project') $this->project->setMenu($task->project);
  155. $this->view->title = $task->name . $this->lang->testreport->create;
  156. $this->view->reportTitle = date('Y-m-d') . " TESTTASK#{$task->id} {$task->name} {$this->lang->testreport->common}";
  157. }
  158. $this->app->loadLang('bug');
  159. $this->app->loadLang('story');
  160. $reportData = array('begin' => $begin, 'end' => $end, 'builds' => $builds, 'tasks' => $tasks, 'owner' => $owner, 'stories' => $stories, 'bugs' => $bugs, 'execution' => $execution, 'productIdList' => $productIdList);
  161. return $reportData;
  162. }
  163. /**
  164. * 获取创建项目 / 执行的测试报告数据。
  165. * Get project or execution report data for creation.
  166. *
  167. * @param int $objectID
  168. * @param string $objectType
  169. * @param string $extra
  170. * @param string $begin
  171. * @param string $end
  172. * @param int $executionID
  173. * @access public
  174. * @return array
  175. */
  176. public function assignProjectReportDataForCreate($objectID, $objectType, $extra, $begin = '', $end = '', $executionID = 0)
  177. {
  178. $owners = array();
  179. $buildIdList = array();
  180. $productIdList = array();
  181. $tasks = $this->testtask->getExecutionTasks($executionID, 0, $objectType);
  182. $taskBegin = '';
  183. $taskEnd = '';
  184. foreach($tasks as $i => $task)
  185. {
  186. if($extra && strpos(",{$extra},", ",{$task->id},") === false)
  187. {
  188. unset($tasks[$i]);
  189. continue;
  190. }
  191. $owners[$task->owner] = $task->owner;
  192. $productIdList[$task->product] = $task->product;
  193. $this->setChartDatas($task->id);
  194. if($task->build != 'trunk') $buildIdList[$task->build] = $task->build;
  195. if(empty($taskBegin)) $taskBegin = $task->begin;
  196. if(empty($taskEnd)) $taskEnd = $task->end;
  197. if($taskBegin > $task->begin) $taskBegin = $task->begin;
  198. if($taskEnd < $task->end) $taskEnd = $task->end;
  199. }
  200. $task = $objectID ? $this->testtask->getByID((int)$extra) : key($tasks);
  201. $begin = !empty($begin) ? date("Y-m-d", strtotime($begin)) : (string)$taskBegin;
  202. $end = !empty($end) ? date("Y-m-d", strtotime($end)) : (string)$taskEnd;
  203. $builds = $this->build->getByList($buildIdList);
  204. $bugs = $this->testreport->getBugs4Test($builds, $productIdList, $begin, $end, 'execution');
  205. $execution = $this->execution->getById($executionID);
  206. $stories = !empty($builds) ? $this->testreport->getStories4Test($builds) : $this->story->getExecutionStories($execution->id);;
  207. $owner = current($owners);
  208. if($this->app->tab == 'qa')
  209. {
  210. $productID = $this->product->checkAccess(key($productIdList), $this->products);
  211. $this->loadModel('qa')->setMenu($productID);
  212. }
  213. elseif($this->app->tab == 'project')
  214. {
  215. $projects = $this->project->getPairsByProgram();
  216. $projectID = $this->project->checkAccess($execution->id, $projects);
  217. $this->project->setMenu($projectID);
  218. }
  219. $this->view->title = $execution->name . $this->lang->testreport->create;
  220. $this->view->reportTitle = date('Y-m-d') . ' ' . strtoupper($objectType) . "#{$execution->id} {$execution->name} {$this->lang->testreport->common}";
  221. return array('begin' => $begin, 'end' => $end, 'builds' => $builds, 'tasks' => $tasks, 'owner' => $owner, 'stories' => $stories, 'bugs' => $bugs, 'execution' => $execution, 'productIdList' => $productIdList);
  222. }
  223. /**
  224. * 获取编辑项目 / 执行的测试报告数据。
  225. * Get project or execution report data for edit.
  226. *
  227. * @param object $report
  228. * @param string $begin
  229. * @param string $end
  230. * @access protected
  231. * @return array
  232. */
  233. protected function assignProjectReportDataForEdit($report, $begin = '', $end = '')
  234. {
  235. $begin = !empty($begin) ? date("Y-m-d", strtotime($begin)) : $report->begin;
  236. $end = !empty($end) ? date("Y-m-d", strtotime($end)) : $report->end;
  237. $productIdList[$report->product] = $report->product;
  238. $tasks = $this->testtask->getByList(explode(',', $report->tasks));
  239. foreach($tasks as $task) $this->setChartDatas($task->id);
  240. $execution = $this->execution->getById($report->execution);
  241. $builds = $this->build->getByList(explode(',', $report->builds));
  242. $stories = !empty($builds) ? $this->testreport->getStories4Test($builds) : $this->story->getExecutionStories($report->execution);
  243. $bugs = $this->testreport->getBugs4Test($builds, $productIdList, $begin, $end, 'execution');
  244. return array('begin' => $begin, 'end' => $end, 'builds' => $builds, 'tasks' => $tasks, 'stories' => $stories, 'bugs' => $bugs, 'execution' => $execution, 'productIdList' => $productIdList);
  245. }
  246. /**
  247. * 展示测试报告数据。
  248. * Assign report data.
  249. *
  250. * @param array $reportData
  251. * @param string $method
  252. * @access protected
  253. * @return void
  254. */
  255. protected function assignReportData($reportData, $method, $pager = null)
  256. {
  257. foreach($reportData as $key => $value)
  258. {
  259. if(strpos(',productIdList,tasks,', ",{$key},") !== false)
  260. {
  261. $this->view->{$key} = join(',', array_keys($value));
  262. }
  263. else
  264. {
  265. $this->view->{$key} = $value;
  266. }
  267. }
  268. if($method == 'create')
  269. {
  270. /* Get testtasks members. */
  271. $tasks = $reportData['tasks'];
  272. $taskMembers = '';
  273. foreach($tasks as $testtask)
  274. {
  275. if(!empty($testtask->members)) $taskMembers .= ',' . (string)$testtask->members;
  276. }
  277. $taskMembers = explode(',', $taskMembers);
  278. $members = $this->dao->select('DISTINCT lastRunner')->from(TABLE_TESTRUN)->where('task')->in(array_keys($tasks))->fetchPairs('lastRunner', 'lastRunner');
  279. $this->view->members = implode(',', array_merge($members, $taskMembers));
  280. }
  281. $this->view->storySummary = $this->product->summary($reportData['stories']);
  282. $this->view->users = $this->user->getPairs('noletter|noclosed|nodeleted');
  283. $cases = $this->testreport->getTaskCases($reportData['tasks'], $reportData['begin'], $reportData['end'], zget($reportData, 'cases', ''));
  284. $this->view->cases = $cases;
  285. $this->view->caseSummary = $this->testreport->getResultSummary($reportData['tasks'], $cases, $reportData['begin'], $reportData['end']);
  286. $caseList = array();
  287. $maxRunDate = '';
  288. foreach($cases as $casesList)
  289. {
  290. foreach($casesList as $caseID => $case)
  291. {
  292. $case->caseID = $caseID;
  293. $caseList[$caseID] = $case;
  294. if($case->maxRunDate > $maxRunDate) $maxRunDate = $case->maxRunDate;
  295. }
  296. }
  297. $this->view->caseList = $caseList;
  298. $this->view->maxRunDate = substr($maxRunDate, 0, 10);
  299. $caseIdList = isset($reportData['cases']) ? $reportData['cases'] : array_keys($caseList);
  300. $perCaseResult = $this->testreport->getPerCaseResult4Report($reportData['tasks'], $caseIdList, $reportData['begin'], $reportData['end']);
  301. $perCaseRunner = $this->testreport->getPerCaseRunner4Report($reportData['tasks'], $caseIdList, $reportData['begin'], $reportData['end']);
  302. $this->view->datas['testTaskPerRunResult'] = $this->loadModel('report')->computePercent($perCaseResult);
  303. $this->view->datas['testTaskPerRunner'] = $this->report->computePercent($perCaseRunner);
  304. list($bugInfo, $bugSummary) = $this->buildReportBugData($reportData['tasks'], $reportData['productIdList'], $reportData['begin'], $reportData['end'], $reportData['builds']);
  305. if($method == 'view') $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', false);
  306. $this->view->bugInfo = $bugInfo;
  307. $this->view->legacyBugs = $bugSummary['legacyBugs'];
  308. $this->view->bugSummary = $bugSummary;
  309. if($method == 'view') $this->view->pager = $pager;
  310. }
  311. /**
  312. * 为创建查看测试报告数据构建报告数据。
  313. * Build testreport data for view.
  314. *
  315. * @param object $report
  316. * @access public
  317. * @return array
  318. */
  319. public function buildReportDataForView($report)
  320. {
  321. $reportData = array();
  322. $reportData['begin'] = $report->begin;
  323. $reportData['end'] = $report->end;
  324. $reportData['cases'] = $report->cases;
  325. $reportData['productIdList'] = array($report->product);
  326. $reportData['execution'] = $this->execution->getById($report->execution);
  327. $reportData['stories'] = $report->stories ? $this->story->getByList($report->stories) : array();
  328. $reportData['tasks'] = $report->tasks ? $this->testtask->getByList(explode(',', $report->tasks)) : array();
  329. $reportData['builds'] = $report->builds ? $this->build->getByList(explode(',', $report->builds)) : array();
  330. $reportData['bugs'] = $report->bugs ? $this->bug->getByIdList($report->bugs) : array();
  331. $reportData['report'] = $report;
  332. return $reportData;
  333. }
  334. /**
  335. * 为创建准备测试报告数据。
  336. * Prepare testreport data for creation.
  337. *
  338. * @access protected
  339. * @return object
  340. */
  341. protected function prepareTestreportForCreate()
  342. {
  343. /* Build testreport. */
  344. $execution = $this->execution->getByID((int)$this->post->execution);
  345. $testreport = form::data($this->config->testreport->form->create)
  346. ->setDefault('project', empty($execution) ? 0 : ($execution->type == 'project' ? $execution->id : $execution->project))
  347. ->get();
  348. $testreport = $this->loadModel('file')->processImgURL($testreport, $this->config->testreport->editor->create['id'], $this->post->uid);
  349. $testreport->members = trim($testreport->members, ',');
  350. /* Check reuqired. */
  351. $reportErrors = array();
  352. foreach(explode(',', $this->config->testreport->create->requiredFields) as $field)
  353. {
  354. $field = trim($field);
  355. if($field && empty($testreport->{$field}))
  356. {
  357. $fieldName = $this->config->testreport->form->create[$field]['type'] != 'array' ? "{$field}" : "{$field}[]";
  358. $reportErrors[$fieldName][] = sprintf($this->lang->error->notempty, $this->lang->testreport->{$field});
  359. }
  360. }
  361. if($testreport->end < $testreport->begin) $reportErrors['end'][] = sprintf($this->lang->error->ge, $this->lang->testreport->end, $testreport->begin);
  362. if(!empty($reportErrors)) dao::$errors = $reportErrors;
  363. return $testreport;
  364. }
  365. /**
  366. * 为编辑准备测试报告数据。
  367. * Prepare testreport data for edit.
  368. *
  369. * @param int $reportID
  370. * @access protected
  371. * @return object
  372. */
  373. protected function prepareTestreportForEdit($reportID)
  374. {
  375. /* Build testreport. */
  376. $testreport = form::data($this->config->testreport->form->edit)->add('id', $reportID)->get();
  377. $testreport = $this->loadModel('file')->processImgURL($testreport, $this->config->testreport->editor->edit['id'], $this->post->uid);
  378. $testreport->members = trim($testreport->members, ',');
  379. /* Check reuqired. */
  380. $reportErrors = array();
  381. foreach(explode(',', $this->config->testreport->edit->requiredFields) as $field)
  382. {
  383. $field = trim($field);
  384. if($field && empty($testreport->{$field}))
  385. {
  386. $fieldName = $this->config->testreport->form->edit[$field]['type'] != 'array' ? "{$field}" : "{$field}[]";
  387. $reportErrors[$fieldName][] = sprintf($this->lang->error->notempty, $this->lang->testreport->{$field});
  388. }
  389. }
  390. if($testreport->end < $testreport->begin) $reportErrors['end'][] = sprintf($this->lang->error->ge, $this->lang->testreport->end, $testreport->begin);
  391. if(!empty($reportErrors)) dao::$errors = $reportErrors;
  392. return $testreport;
  393. }
  394. /**
  395. * 构建测试报告的 bug 信息和汇总信息。
  396. * build bug info and summary of test report.
  397. *
  398. * @param array $tasks
  399. * @param array $productIdList
  400. * @param string $begin
  401. * @param string $end
  402. * @param array $builds
  403. * @access public
  404. * @return array
  405. */
  406. public function buildReportBugData($tasks, $productIdList, $begin, $end, $builds)
  407. {
  408. /* Get activated bugs. */
  409. $buildIdList = array_keys($builds) + array_keys($this->testreport->getChildBuilds($builds));
  410. $activatedBugs = $this->bug->getActivatedBugs($productIdList, $begin, $end, $buildIdList);
  411. /* Get stage and handle groups. */
  412. list($stageGroups, $handleGroups) = $this->getStageAndHandleGroups($productIdList, $begin, $end, $buildIdList);
  413. /* Get the generated and leagcy bug data, and its groups. */
  414. list($foundBugs, $legacyBugs, $stageGroups, $handleGroups, $byCaseNum) = $this->getGeneratedAndLegacyBugData(array_keys($tasks), $productIdList, $begin, $end, $buildIdList, $stageGroups, $handleGroups);
  415. /* Get the found bug's groups. */
  416. list($severityGroups, $typeGroups, $statusGroups, $openedByGroups, $moduleGroups, $resolvedByGroups, $resolutionGroups, $resolvedBugs) = $this->getFoundBugGroups($foundBugs);
  417. /* Set bug summary. */
  418. $bugSummary['foundBugs'] = count($foundBugs);
  419. $bugSummary['legacyBugs'] = $legacyBugs;
  420. $bugSummary['activatedBugs'] = count($activatedBugs);
  421. $bugSummary['countBugByTask'] = $byCaseNum;
  422. $bugSummary['bugConfirmedRate'] = empty($resolvedBugs) ? 0 : round((zget($resolutionGroups, 'fixed', 0) + zget($resolutionGroups, 'postponed', 0)) / $resolvedBugs * 100, 2);
  423. $bugSummary['bugCreateByCaseRate'] = empty($byCaseNum) ? 0 : round($byCaseNum / count($foundBugs) * 100, 2);
  424. /* Set bug info. */
  425. $bugInfo = $this->buildBugInfo($stageGroups, $handleGroups, $severityGroups, $typeGroups, $statusGroups, $openedByGroups, $moduleGroups, $resolvedByGroups, $resolutionGroups, $productIdList);
  426. return array($bugInfo, $bugSummary);
  427. }
  428. /**
  429. * 构建 bug 信息。
  430. * Build bug info.
  431. *
  432. * @param array $stageGroups
  433. * @param array $handleGroups
  434. * @param array $severityGroups
  435. * @param array $typeGroups
  436. * @param array $statusGroups
  437. * @param array $openedByGroups
  438. * @param array $moduleGroups
  439. * @param array $resolvedByGroups
  440. * @param array $resolutionGroups
  441. * @param array $productIdList
  442. * @access protected
  443. * @return array
  444. */
  445. protected function buildBugInfo($stageGroups, $handleGroups, $severityGroups, $typeGroups, $statusGroups, $openedByGroups, $moduleGroups, $resolvedByGroups, $resolutionGroups, $productIdList)
  446. {
  447. $bugInfo['bugStageGroups'] = $stageGroups;
  448. $bugInfo['bugHandleGroups'] = $handleGroups;
  449. $this->app->loadLang('bug');
  450. $fields = array('severityGroups' => 'severityList', 'typeGroups' => 'typeList', 'statusGroups' => 'statusList', 'resolutionGroups' => 'resolutionList', 'openedByGroups' => 'openedBy', 'resolvedByGroups' => 'resolvedBy');
  451. $users = $this->loadModel('user')->getPairs('noclosed|noletter|nodeleted');
  452. foreach($fields as $variable => $fieldType)
  453. {
  454. $data = array();
  455. foreach(${$variable} as $type => $count)
  456. {
  457. $data[$type] = new stdclass();
  458. $data[$type]->name = strpos($fieldType, 'By') === false ? zget($this->lang->bug->{$fieldType}, $type) : zget($users, $type);
  459. $data[$type]->value = $count;
  460. }
  461. $bugInfo['bug' . ucfirst($variable)] = $data;
  462. }
  463. $this->loadModel('tree');
  464. $modules = array();
  465. if(!is_array($productIdList)) $productIdList = explode(',', $productIdList);
  466. foreach($productIdList as $productID) $modules += $this->tree->getOptionMenu($productID, 'bug');
  467. $data = array();
  468. foreach($moduleGroups as $moduleID => $count)
  469. {
  470. $data[$moduleID] = new stdclass();
  471. $data[$moduleID]->name = zget($modules, $moduleID);
  472. $data[$moduleID]->value = $count;
  473. }
  474. $bugInfo['bugModuleGroups'] = $data;
  475. return $bugInfo;
  476. }
  477. /**
  478. * 获取阶段和状态分组。
  479. * Get stage and handle groups.
  480. *
  481. * @param array $productIdList
  482. * @param string $begin
  483. * @param string $end
  484. * @access protected
  485. * @return array
  486. * @param mixed[] $buildIdList
  487. */
  488. protected function getStageAndHandleGroups($productIdList, $begin, $end, $buildIdList)
  489. {
  490. /* Init stageGroups. */
  491. $stageGroups = array();
  492. foreach($this->lang->bug->priList as $priKey => $priValue)
  493. {
  494. $stageGroups[$priKey]['generated'] = 0;
  495. $stageGroups[$priKey]['legacy'] = 0;
  496. $stageGroups[$priKey]['resolved'] = 0;
  497. }
  498. /* Init handleGroups. */
  499. $handleGroups = array();
  500. $beginTimeStamp = strtotime($begin);
  501. $endTimeStamp = strtotime($end);
  502. for($i = $beginTimeStamp; $i <= $endTimeStamp; $i += 86400)
  503. {
  504. $date = date('m-d', $i);
  505. $handleGroups['generated'][$date] = 0;
  506. $handleGroups['legacy'][$date] = 0;
  507. $handleGroups['resolved'][$date] = 0;
  508. }
  509. /* Get the resolved bug data. */
  510. $resolvedBugs = $this->bug->getProductBugs($productIdList, 'resolved', $begin, $end);
  511. foreach($resolvedBugs as $bug)
  512. {
  513. if(array_intersect(explode(',', $bug->openedBuild), $buildIdList))
  514. {
  515. $resolvedDate = date('m-d', strtotime($bug->resolvedDate));
  516. $stageGroups[$bug->pri]['resolved'] += 1;
  517. $handleGroups['resolved'][$resolvedDate] += 1;
  518. }
  519. }
  520. return array($stageGroups, $handleGroups);
  521. }
  522. /**
  523. * 获取产生和遗留的 bug。
  524. * Get generated and legacy bugs.
  525. *
  526. * @param array $taskIdList
  527. * @param array $productIdList
  528. * @param string $begin
  529. * @param string $end
  530. * @param array $buildIdList
  531. * @param array $stageGroups
  532. * @param array $handleGroups
  533. * @access protected
  534. * @return array
  535. */
  536. protected function getGeneratedAndLegacyBugData($taskIdList, $productIdList, $begin, $end, $buildIdList, $stageGroups, $handleGroups)
  537. {
  538. $byCaseNum = 0;
  539. $foundBugs = $legacyBugs = array();
  540. $beginTimeStamp = strtotime($begin);
  541. $endTimeStamp = strtotime($end);
  542. $generatedBugs = $this->bug->getProductBugs($productIdList, 'opened', $begin, $end);
  543. foreach($generatedBugs as $bug)
  544. {
  545. if(array_intersect(explode(',', $bug->openedBuild), $buildIdList))
  546. {
  547. $openedDate = date('m-d', strtotime($bug->openedDate));
  548. /* Set generated bugs. */
  549. $foundBugs[$bug->id] = $bug;
  550. $stageGroups[$bug->pri]['generated'] += 1;
  551. $handleGroups['generated'][$openedDate] += 1;
  552. /* Set legacy bugs. */
  553. if($bug->status == 'active' || $bug->resolvedDate > "{$end} 23:59:59")
  554. {
  555. $legacyBugs[$bug->id] = $bug;
  556. $stageGroups[$bug->pri]['legacy'] += 1;
  557. for($currentTimeStamp = $beginTimeStamp; $currentTimeStamp <= $endTimeStamp; $currentTimeStamp += 86400)
  558. {
  559. $dateTime = date('Y-m-d 23:59:59', $currentTimeStamp);
  560. if($bug->openedDate <= $dateTime && (helper::isZeroDate($bug->resolvedDate) || $bug->resolvedDate > $dateTime))
  561. {
  562. $date = date('m-d', $currentTimeStamp);
  563. $handleGroups['legacy'][$date] += 1;
  564. }
  565. }
  566. }
  567. if($bug->case && !empty($bug->testtask) && in_array($bug->testtask, $taskIdList)) $byCaseNum ++;
  568. }
  569. }
  570. return array($foundBugs, $legacyBugs, $stageGroups, $handleGroups, $byCaseNum);
  571. }
  572. /**
  573. * 获取产生的 bug 分组数据。
  574. * Get found bug groups.
  575. *
  576. * @param array $foundBugs
  577. * @access protected
  578. * @return array
  579. */
  580. protected function getFoundBugGroups($foundBugs)
  581. {
  582. $resolvedBugs = 0;
  583. $severityGroups = $typeGroups = $statusGroups = $openedByGroups = $moduleGroups = $resolvedByGroups = $resolutionGroups = array();
  584. foreach($foundBugs as $bug)
  585. {
  586. $severityGroups[$bug->severity] = isset($severityGroups[$bug->severity]) ? $severityGroups[$bug->severity] + 1 : 1;
  587. $typeGroups[$bug->type] = isset($typeGroups[$bug->type]) ? $typeGroups[$bug->type] + 1 : 1;
  588. $statusGroups[$bug->status] = isset($statusGroups[$bug->status]) ? $statusGroups[$bug->status] + 1 : 1;
  589. $openedByGroups[$bug->openedBy] = isset($openedByGroups[$bug->openedBy]) ? $openedByGroups[$bug->openedBy] + 1 : 1;
  590. $moduleGroups[$bug->module] = isset($moduleGroups[$bug->module]) ? $moduleGroups[$bug->module] + 1 : 1;
  591. if($bug->resolvedBy) $resolvedByGroups[$bug->resolvedBy] = isset($resolvedByGroups[$bug->resolvedBy]) ? $resolvedByGroups[$bug->resolvedBy] + 1 : 1;
  592. if($bug->resolution) $resolutionGroups[$bug->resolution] = isset($resolutionGroups[$bug->resolution]) ? $resolutionGroups[$bug->resolution] + 1 : 1;
  593. if($bug->status == 'resolved' || $bug->status == 'closed') $resolvedBugs ++;
  594. }
  595. return array($severityGroups, $typeGroups, $statusGroups, $openedByGroups, $moduleGroups, $resolvedByGroups, $resolutionGroups, $resolvedBugs);
  596. }
  597. /**
  598. * 设置用例的报告数据。
  599. * Set chart datas of cases.
  600. *
  601. * @param int $taskID
  602. * @access public
  603. * @return void
  604. */
  605. protected function setChartDatas($taskID)
  606. {
  607. $this->loadModel('report');
  608. foreach($this->lang->testtask->report->charts as $chart => $title)
  609. {
  610. if(strpos($chart, 'testTask') === false) continue;
  611. $chartFunc = 'getDataOf' . $chart;
  612. $chartData = $this->testtask->$chartFunc($taskID);
  613. $chartOption = $this->config->testtask->report->options;
  614. $this->view->charts[$chart] = $chartOption;
  615. if(isset($this->view->datas[$chart]))
  616. {
  617. $existDatas = $this->view->datas[$chart];
  618. $sum = 0;
  619. foreach($chartData as $key => $data)
  620. {
  621. if(isset($existDatas[$key]))
  622. {
  623. $data->value += $existDatas[$key]->value;
  624. unset($existDatas[$key]);
  625. }
  626. $sum += $data->value;
  627. }
  628. foreach($existDatas as $key => $data)
  629. {
  630. $chartData[$key] = $data;
  631. $sum += $data->value;
  632. }
  633. if($sum)
  634. {
  635. foreach($chartData as $data) $data->percent = round($data->value / $sum, 2);
  636. }
  637. ksort($chartData);
  638. $this->view->datas[$chart] = $chartData;
  639. }
  640. else
  641. {
  642. $this->view->datas[$chart] = $this->report->computePercent($chartData);
  643. }
  644. }
  645. }
  646. }