zentaomax.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. public function getDocumentList()
  3. {
  4. return $document = $this->dao->select("t1.id, CONCAT_WS(' / ', t2.name, t1.name) as name")->from(TABLE_ZOUTPUT)->alias('t1')
  5. ->leftJoin(TABLE_ACTIVITY)->alias('t2')->on('t1.activity = t2.id')
  6. ->where('t1.deleted')->eq(0)
  7. ->fetchPairs('id', 'name');
  8. }
  9. /**
  10. * @param int $executionID
  11. * @param int $productID
  12. * @param string $orderBy
  13. */
  14. public function getPlans($executionID = 0, $productID = 0, $orderBy = 'id_asc')
  15. {
  16. $plans = $this->getStage($executionID, $productID, 'all', $orderBy);
  17. $documentList = $this->getDocumentList();
  18. $parents = array();
  19. foreach($plans as $planID => $plan)
  20. {
  21. $document = '';
  22. if(!empty($plan->output))
  23. {
  24. $output = explode(',', $plan->output);
  25. foreach($output as $title) if(isset($documentList[$title])) $document .= $documentList[$title];
  26. }
  27. $plan->output = empty($plan->output) ? '' : $document;
  28. $plan->grade == 1 ? $parents[$planID] = $plan : $children[$plan->parent][] = $plan;
  29. }
  30. foreach($parents as $planID => $plan) $parents[$planID]->children = isset($children[$planID]) ? $children[$planID] : array();
  31. return $parents;
  32. }
  33. /**
  34. * Get the stage set to milestone.
  35. *
  36. * @param int $projectID
  37. * @access public
  38. * @return array
  39. */
  40. public function getMilestones($projectID = 0)
  41. {
  42. $milestones = $this->dao->select('id, path')->from(TABLE_PROJECT)
  43. ->where('project')->eq($projectID)
  44. ->andWhere('type')->eq('stage')
  45. ->andWhere('milestone')->eq(1)
  46. ->andWhere('deleted')->eq(0)
  47. ->orderBy('begin_desc,path')
  48. ->fetchPairs();
  49. return $this->formatMilestones($milestones, $projectID);
  50. }
  51. /**
  52. * 根据product获取里程碑。
  53. * Get milestone by product.
  54. *
  55. * @param int $productID
  56. * @param int $projectID
  57. * @access public
  58. * @return array
  59. */
  60. public function getMilestoneByProduct($productID, $projectID)
  61. {
  62. $milestones = $this->dao->select('t1.id, t1.path')->from(TABLE_PROJECT)->alias('t1')
  63. ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.id=t2.project')
  64. ->where('t2.product')->eq($productID)
  65. ->andWhere('t1.project')->eq($projectID)
  66. ->andWhere('t1.milestone')->eq(1)
  67. ->andWhere('t1.deleted')->eq(0)
  68. ->orderBy('t1.begin asc,path')
  69. ->fetchPairs();
  70. return $this->formatMilestones($milestones, $projectID);
  71. }
  72. /**
  73. * Format milestones use '/'.
  74. *
  75. * @param array $milestones
  76. * @param int $projectID
  77. * @access private
  78. * @return array
  79. */
  80. private function formatMilestones($milestones, $projectID)
  81. {
  82. $allStages = $this->dao->select('id,name')->from(TABLE_EXECUTION)
  83. ->where('project')->eq($projectID)
  84. ->andWhere('type')->notin('program,project')
  85. ->fetchPairs();
  86. foreach($milestones as $id => $path)
  87. {
  88. $paths = explode(',', trim($path, ','));
  89. $stageName = '';
  90. foreach($paths as $stage)
  91. {
  92. if(isset($allStages[$stage])) $stageName .= '/' . $allStages[$stage];
  93. }
  94. $milestones[$id] = trim($stageName, '/');
  95. }
  96. return $milestones;
  97. }