ipd.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * 判断IPD项目阶段是否允许并行。
  4. * Determine whether parallelism is allowed in the IPD project phase.
  5. *
  6. * @param int $projectID
  7. * @access public
  8. * @return int
  9. */
  10. public function checkParallel($projectID)
  11. {
  12. $started = $this->dao->select('count(id) as count')->from(TABLE_PROJECT)
  13. ->where('project')->eq($projectID)
  14. ->andWhere('status')->ne('wait')
  15. ->fetch('count');
  16. return $started > 0;
  17. }
  18. /**
  19. * 检查单个编辑IPD阶段的开始时间和结束时间是否符合规则。
  20. * Check whether the start and end time of a single edit IPD phase is in accordance with the rules.
  21. *
  22. * @param object $currentStage
  23. * @access public
  24. * @return bool
  25. */
  26. public function checkIpdStageDate($currentStage)
  27. {
  28. if($currentStage->grade > 1) return true;
  29. $stages = $this->loadModel('execution')->getList($currentStage->project);
  30. if($stages) $stages = array_reverse($stages, true);
  31. $preDate = $nextDate = '';
  32. $isCurrent = false;
  33. foreach($stages as $stage)
  34. {
  35. if($stage->grade > 1) continue;
  36. if(!$stage->enabled) continue;//阶段是否启用
  37. if($isCurrent)
  38. {
  39. $nextDate = $stage->begin;
  40. break;
  41. }
  42. if($stage->attribute == $currentStage->attribute)
  43. {
  44. $isCurrent = true;
  45. continue;
  46. }
  47. $preDate = $stage->end;
  48. }
  49. if($preDate and $preDate > $_POST['begin']) dao::$errors['begin'] = $this->lang->programplan->error->outOfDate . ': ' . $preDate;
  50. if($nextDate and $nextDate < $_POST['end']) dao::$errors['end'] = $this->lang->programplan->error->lessOfDate . ': ' . $nextDate;
  51. return !dao::isError();
  52. }
  53. /**
  54. * 根据action获取excution。
  55. * Get new parent and action.
  56. *
  57. * @param array $statusCount
  58. * @param object $parent
  59. * @param int $startTasks
  60. * @param string $action
  61. * @param object $project
  62. * @access protected
  63. * @return array
  64. */
  65. protected function getNewParentAndAction($statusCount, $parent, $startTasks, $action, $project)
  66. {
  67. $result = parent::getNewParentAndAction($statusCount, $parent, $startTasks, $action, $project);
  68. $newParent = $result['newParent'];
  69. $parentAction = $result['parentAction'];
  70. /* 阶段串行IPD项目的一级阶段的子阶段全部关闭时,需要检查评审点是否全部通过,只有全部通过才可以自动关闭。 */
  71. if($parentAction == 'closedbychild' && !empty($project->model) && $project->model == 'ipd' && !$project->parallel && $parent->grade =='1')
  72. {
  73. if(!isset($parent->projectModel)) $parent->projectModel = $project->model;
  74. $points = $this->loadModel('review')->getPointsByProjectID($project->id);
  75. list($parent) = $this->loadModel('execution')->buildExecutionTree(array($parent), $points);
  76. /* 当前阶段评审点都通过,当前阶段才可以关闭。 */
  77. if(!empty($parent->points))
  78. {
  79. foreach($parent->points as $point)
  80. {
  81. if($point->result == 'pass') continue;
  82. if($parent->status == 'doing') return array('newParent' => null, 'parentAction' => '');
  83. $status = $statusCount == 1 ? 'wait' : 'doing';
  84. $newParent = $this->execution->buildExecutionByStatus($status);
  85. $parentAction = $parent->status == 'wait' ? 'startbychildstart' : 'startbychild' . $action;
  86. break;
  87. }
  88. }
  89. }
  90. return array('newParent' => $newParent, 'parentAction' => $parentAction);
  91. }