ipd.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. /**
  3. * 根据项目获取可用的评审点。
  4. * Get review point by project.
  5. *
  6. * @param int $projectID
  7. * @access public
  8. * @return array
  9. */
  10. public function getReviewPointByProject($projectID = 0)
  11. {
  12. $project = $this->loadModel('project')->getByID($projectID);
  13. if($project->model != 'ipd') return array();
  14. $enabledPoints = $this->getPointsByProjectID($projectID, 'category');
  15. $pointList = array();
  16. foreach($enabledPoints as $category => $enabledPoint) $pointList[$category] = array('value' => $category, 'text' => $enabledPoint->title, 'disabled' => 1);
  17. $stages = $this->dao->select('*')->from(TABLE_EXECUTION)
  18. ->where('project')->eq($projectID)
  19. ->andWhere('type')->eq('stage')
  20. ->andWhere('parent')->eq($projectID)
  21. ->orderBy('order_asc')
  22. ->fetchAll('id');
  23. if(empty($stages)) return $pointList;
  24. return $this->checkPoints($stages, $enabledPoints, $pointList);
  25. }
  26. /**
  27. * 检查评审点是否可用。
  28. * Check points is available.
  29. *
  30. * @param array $stage
  31. * @param array $enabledPoints
  32. * @param array $pointList
  33. *
  34. * @access public
  35. * @return array
  36. * @param mixed[] $stages
  37. */
  38. public function checkPoints($stages = array(), $enabledPoints = array(), $pointList = array())
  39. {
  40. $prePoint = '';
  41. $ipdReviewPoint = array();
  42. foreach($enabledPoints as $enabledPoint)
  43. {
  44. if(!isset($ipdReviewPoint[$enabledPoint->execution])) $ipdReviewPoint[$enabledPoint->execution] = array();
  45. $ipdReviewPoint[$enabledPoint->execution][] = $enabledPoint->category;
  46. }
  47. foreach($stages as $stageID => $stage)
  48. {
  49. if(!$stageID || !isset($ipdReviewPoint[$stageID])) continue;
  50. foreach($ipdReviewPoint[$stageID] as $point)
  51. {
  52. if($stage->enabled == 'off')
  53. {
  54. unset($pointList[$point]);
  55. continue;
  56. }
  57. if(!isset($pointList[$point])) continue;
  58. $pointResult = isset($enabledPoints[$point]) ? $enabledPoints[$point]->result : '';
  59. $prePointResult = isset($enabledPoints[$prePoint]) ? $enabledPoints[$prePoint]->result : '';
  60. $pointList[$point]['disabled'] = false;
  61. /* 如果阶段还未开始,则评审点置灰。*/
  62. if($stage->status == 'wait')
  63. {
  64. $pointList[$point]['disabled'] = true;
  65. $pointList[$point]['message'] = $this->lang->review->stageNotStartTip;
  66. $prePoint = $point;
  67. continue;
  68. }
  69. /* 如果前一个评审点评审未通过, 则评审点置灰。*/
  70. if($prePoint && $prePointResult != 'pass')
  71. {
  72. $pointList[$point]['disabled'] = true;
  73. $pointList[$point]['message'] = $this->lang->review->prePointNotPassTip;
  74. $prePoint = $point;
  75. continue;
  76. }
  77. /* 如果评审点已经评审通过,或者已经发起了评审,还未被评审,则评审点置灰。*/
  78. if($pointResult == 'pass' || ($enabledPoints[$point]->review && !$pointResult && $enabledPoints[$point]->status != 'draft')) $pointList[$point]['disabled'] = true;
  79. $prePoint = $point;
  80. }
  81. }
  82. return $pointList;
  83. }
  84. /**
  85. * 根据评审点类型获取阶段。
  86. * Get stage by point.
  87. *
  88. * @param string $category
  89. * @param int $projectID
  90. * @access public
  91. * @return object|false
  92. */
  93. public function getStageByPoint($category = '', $projectID = 0)
  94. {
  95. if(!$category) return false;
  96. $object = $this->dao->select('*')->from(TABLE_OBJECT)->where('project')->eq($projectID)->andWhere('category')->eq($category)->fetch();
  97. $attribute = '';
  98. foreach($this->config->review->ipdReviewPoint as $type => $point)
  99. {
  100. if(!in_array($object->category, $point)) continue;
  101. $attribute = $type;
  102. }
  103. return $this->dao->select('*')->from(TABLE_EXECUTION)->where('project')->eq($object->project)->andWhere('type')->eq('stage')->andWhere('grade')->eq(1)->andWhere('attribute')->eq($attribute)->fetch();
  104. }
  105. /**
  106. * Get stage by review.
  107. *
  108. * @param int $reviewID
  109. * @access public
  110. * @return object
  111. */
  112. public function getStageByReview($reviewID = 0)
  113. {
  114. $object = $this->dao->select('t1.*')->from(TABLE_OBJECT)->alias('t1')
  115. ->leftJoin(TABLE_REVIEW)->alias('t2')->on('t2.object=t1.id')
  116. ->where('t2.id')->eq($reviewID)
  117. ->fetch();
  118. $stageType = '';
  119. foreach($this->config->review->ipdReviewPoint as $type => $point)
  120. {
  121. if(in_array($object->category, $point))
  122. {
  123. $stageType = $type;
  124. break;
  125. }
  126. }
  127. return $this->dao->select('*')->from(TABLE_EXECUTION)
  128. ->where('project')->eq($object->project)
  129. ->andWhere('type')->eq('stage')
  130. ->andWhere('attribute')->eq($stageType)
  131. ->fetch();
  132. }
  133. /**
  134. * In ipd project, create default review points after create a stage.
  135. *
  136. * @param int $projectID
  137. * @param int $stageID
  138. * @param array $defaultPoint
  139. * @access public
  140. * @return void
  141. */
  142. public function createDefaultPoint($projectID, $stageID, $defaultPoint)
  143. {
  144. $defaultPointList = $this->dao->select('*')->from(TABLE_DECISION)->where('id')->in($defaultPoint)->fetchAll('id');
  145. $object = new stdclass();
  146. $object->project = $projectID;
  147. $object->execution = $stageID;
  148. $object->product = 0;
  149. $object->type = 'decision';
  150. $object->version = '';
  151. $object->createdBy = $this->app->user->account;
  152. $object->createdDate = helper::today();
  153. foreach($defaultPoint as $pointID)
  154. {
  155. $object->title = $defaultPointList[$pointID]->title;
  156. $object->categoryTitle = $defaultPointList[$pointID]->title;
  157. $object->category = $pointID;
  158. $this->dao->insert(TABLE_OBJECT)->data($object)->exec();
  159. }
  160. }
  161. /**
  162. * 更新评审日期。
  163. * Update review date.
  164. *
  165. * @param int $objectID
  166. * @param string $type
  167. * @access public
  168. * @return void
  169. */
  170. public function updateReviewDate($objectID, $type)
  171. {
  172. if($type == 'point')
  173. {
  174. $end = $_POST['startDate'];
  175. $this->dao->update(TABLE_OBJECT)->set('end')->eq($end)->where('id')->eq($objectID)->exec();
  176. }
  177. }
  178. /**
  179. * Get latest reviews for project's review points.
  180. *
  181. * @param int $projectID
  182. * @access public
  183. * @return array
  184. */
  185. public function getPointLatestReviews($projectID)
  186. {
  187. $this->app->loadLang('baseline');
  188. $pointList = $this->lang->baseline->ipd->pointList;
  189. unset($pointList['other']);
  190. unset($pointList['']);
  191. $reviews = $this->dao->select('t1.*, t2.category as category')->from(TABLE_REVIEW)->alias('t1')
  192. ->leftJoin(TABLE_OBJECT)->alias('t2')->on('t1.object = t2.id')
  193. ->where('t1.deleted')->eq(0)
  194. ->andWhere('t1.project')->eq($projectID)
  195. ->andWhere('t2.category')->in(array_keys($pointList))
  196. ->orderBy('id_asc')
  197. ->fetchAll('category');
  198. return $reviews;
  199. }
  200. /**
  201. * 获取IPD项目已启用的评审点列表。
  202. * Get IPD points.
  203. *
  204. * @param int $projectID
  205. * @param string $groupBy id|category
  206. * @access public
  207. * @return array
  208. */
  209. public function getPointsByProjectID($projectID = 0, $groupBy = '')
  210. {
  211. $points = $this->dao->select('*')->from(TABLE_OBJECT)
  212. ->where('project')->eq($projectID)
  213. ->andWhere('type')->eq('decision')
  214. ->andWhere('deleted')->eq('0')
  215. ->andWhere('enabled')->eq('1')
  216. ->orderby('id')
  217. ->fetchAll('id');
  218. $reviews = $this->dao->select('*')->from(TABLE_REVIEW)
  219. ->where('deleted')->eq(0)
  220. ->andWhere('object')->in(array_keys($points))
  221. ->fetchAll('object');
  222. foreach($points as $id => $point)
  223. {
  224. $point->status = isset($reviews[$point->id]) ? $reviews[$point->id]->status : '';
  225. $point->realBegan = isset($reviews[$point->id]) ? $reviews[$point->id]->createdDate : null;
  226. $point->deadline = isset($reviews[$point->id]) ? $reviews[$point->id]->deadline : '';
  227. $point->review = isset($reviews[$point->id]) ? $reviews[$point->id]->id : 0;
  228. $point->lastReviewedDate = isset($reviews[$point->id]) ? $reviews[$point->id]->lastReviewedDate : '';
  229. $point->result = isset($reviews[$point->id]) ? $reviews[$point->id]->result : '';
  230. $point->disabled = in_array($point->status, array('reviewing', 'pass')) ? true : false;
  231. }
  232. if(empty($groupBy)) return $points;
  233. $pointGroup = array();
  234. foreach($points as $id => $point) $pointGroup[$point->$groupBy] = $point;
  235. return $pointGroup;
  236. }
  237. /**
  238. * Get point pairs by project id.
  239. *
  240. * @param int $projectID
  241. * @access public
  242. * @return void
  243. */
  244. public function getPointPairsByProjectID($projectID)
  245. {
  246. return $this->dao->select('category, categoryTitle')->from(TABLE_OBJECT)->where('project')->eq($projectID)->andWhere('type')->eq('decision')->fetchPairs();
  247. }