zentaomax.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * 获取报告列表。
  4. * Get report list.
  5. *
  6. * @param int $objectID
  7. * @param string $objectType
  8. * @param int $extra
  9. * @param string $orderBy
  10. * @param object $pager
  11. * @access public
  12. * @return array
  13. */
  14. public function getList($objectID, $objectType, $extra = 0, $orderBy = 'id_desc', $pager = null)
  15. {
  16. if(common::isTutorialMode()) return $this->loadModel('tutorial')->getTestReports();
  17. $reports = $this->dao->select('DISTINCT t1.*')->from(TABLE_TESTREPORT)->alias('t1')
  18. ->leftjoin(TABLE_TESTTASKPRODUCT)->alias('t2')->on('t1.tasks=t2.task')
  19. ->where('t1.deleted')->eq(0)
  20. ->beginIF($objectType == 'execution')
  21. ->andWhere('(t1.execution')->eq($objectID)
  22. ->orWhere('t2.execution')->eq($objectID)
  23. ->markRight(1)
  24. ->fi()
  25. ->beginIF($objectType == 'project')
  26. ->andWhere('(t1.project')->eq($objectID)
  27. ->orWhere('t2.project')->eq($objectID)
  28. ->markRight(1)
  29. ->fi()
  30. ->beginIF($objectType == 'product' && $extra)->andWhere('t1.objectID')->eq($extra)->andWhere('t1.objectType')->eq('testtask')->fi()
  31. ->beginIF($objectType == 'product' && !$extra)
  32. ->andWhere('(t1.product')->eq($objectID)
  33. ->orWhere('t2.product')->eq($objectID)
  34. ->markRight(1)
  35. ->fi()
  36. ->orderBy($orderBy)
  37. ->page($pager, 't1.id')
  38. ->fetchAll('id', false);
  39. return $this->appendProductGroup($reports);
  40. }
  41. /**
  42. * 获取测试报告键对。
  43. * Get pairs.
  44. *
  45. * @param int $productID
  46. * @param int $appendID
  47. * @access public
  48. * @return array
  49. */
  50. public function getPairs($productID = 0, $appendID = 0)
  51. {
  52. return $this->dao->select('t1.id,t1.title')->from(TABLE_TESTREPORT)->alias('t1')
  53. ->leftjoin(TABLE_TESTTASKPRODUCT)->alias('t2')->on('t1.tasks=t2.task')
  54. ->where('t1.deleted')->eq(0)
  55. ->beginIF($productID)->andWhere('(t1.product')->eq($productID)->orWhere('t2.product')->in($productID)->markRight(1)->fi()
  56. ->beginIF($appendID)->orWhere('t1.id')->eq($appendID)->fi()
  57. ->orderBy('id_desc')
  58. ->fetchPairs();
  59. }
  60. /**
  61. * 追加测试单产品分组数据。
  62. * Append product group.
  63. *
  64. * @param array $reports
  65. * @access public
  66. * @return array
  67. */
  68. public function appendProductGroup($reports)
  69. {
  70. $taskBuilds = $this->dao->select('t1.task, t2.*, t4.multiple, t3.name as executionName, t4.name as projectName, t5.name as productName')->from(TABLE_TESTTASKPRODUCT)->alias('t1')
  71. ->leftJoin(TABLE_BUILD)->alias('t2')->on('t1.build = t2.id')
  72. ->leftJoin(TABLE_EXECUTION)->alias('t3')->on('t1.execution = t3.id')
  73. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t1.project = t4.id')
  74. ->leftJoin(TABLE_PRODUCT)->alias('t5')->on('t1.product = t5.id')
  75. ->fetchGroup('task', 'id');
  76. foreach($reports as $reportID => $report)
  77. {
  78. foreach(explode(',', $report->tasks) as $taskID)
  79. {
  80. if(empty($taskBuilds[$taskID])) continue;
  81. $builds = $taskBuilds[$taskID];
  82. $executions = array();
  83. foreach($builds as $build)
  84. {
  85. if(!$build->multiple) continue;
  86. if($build->projectName && $build->executionName)
  87. {
  88. $executions[$build->execution] = $build->projectName . '/' . $build->executionName;
  89. }
  90. elseif(!$build->executionName)
  91. {
  92. $executions[$build->project] = $build->projectName;
  93. }
  94. }
  95. $reports[$reportID]->execution = implode(',', $executions);
  96. }
  97. }
  98. return $reports;
  99. }