control.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <?php
  2. /**
  3. * The control file of programplan 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 Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package programplan
  9. * @link https://www.zentao.net
  10. */
  11. class programplan extends control
  12. {
  13. /**
  14. * Common action.
  15. *
  16. * @param int $projectID
  17. * @param int $productID
  18. * @access public
  19. * @return int
  20. */
  21. public function commonAction($projectID, $productID = 0)
  22. {
  23. $this->loadModel('product');
  24. $this->loadModel('project');
  25. $products = $this->product->getProductPairsByProject($projectID);
  26. $productID = $this->product->checkAccess($productID, $products);
  27. $project = $this->project->getByID($projectID);
  28. $this->session->set('hasProduct', $project->hasProduct);
  29. $this->project->setMenu($projectID);
  30. return $productID;
  31. }
  32. /**
  33. * 渲染阶段数据页面。
  34. * Browse program plans.
  35. *
  36. * @param int $projectID
  37. * @param int $productID
  38. * @param string $type
  39. * @param string $orderBy
  40. * @param int $baselineID
  41. * @param string $browseType
  42. * @param int $queryID
  43. * @param string $from
  44. * @param int $blockID
  45. * @access public
  46. * @return void
  47. */
  48. public function browse($projectID = 0, $productID = 0, $type = 'gantt', $orderBy = 'id_asc', $baselineID = 0, $browseType = '', $queryID = 0, $from = 'project', $blockID = 0)
  49. {
  50. if($type == 'lists') return $this->locate($this->createLink('project', 'execution', "status=undone&projectID={$projectID}"));
  51. if($from == 'doc')
  52. {
  53. $this->loadModel('doc');
  54. $projects = $this->loadModel('project')->getPairsByModel(array('ipd', 'waterfall', 'waterfallplus'));
  55. if(empty($projects)) return $this->send(array('result' => 'fail', 'message' => $this->config->edition == 'ipd' ? $this->lang->programplan->error->noProject4IPD : $this->lang->programplan->error->noProject));
  56. if(!$projectID) $projectID = key($projects);
  57. $this->view->projects = $projects;
  58. }
  59. $this->app->loadLang('stage');
  60. $this->session->set('projectPlanList', $this->app->getURI(true), 'project');
  61. $this->commonAction($projectID, $productID);
  62. if(!defined('RUN_MODE') || RUN_MODE != 'api') $projectID = $this->project->checkAccess($projectID, $this->project->getPairsByProgram());
  63. /* Get the product under the project and adjust the three-level navigation action button. */
  64. $products = $this->loadModel('product')->getProducts($projectID);
  65. if($this->session->hasProduct) $this->lang->modulePageNav = $this->product->select($products, $productID, 'programplan', 'browse', $type, 0, false);
  66. /* Generate stage list page data. */
  67. $browseType = strtolower($browseType);
  68. $plans = $this->programplanZen->buildStages($projectID, $productID, $baselineID, $type, $orderBy, $browseType, $queryID);
  69. $this->view->from = $from;
  70. $this->view->blockID = $blockID;
  71. /* Build gantt browse view. */
  72. $this->programplanZen->buildBrowseView($projectID, $productID, $plans, $type, $orderBy, $baselineID, $browseType, $queryID);
  73. }
  74. /**
  75. * 创建一个项目阶段。
  76. * Create a project plan/phase.
  77. *
  78. * @param int $projectID
  79. * @param int $productID
  80. * @param int $planID
  81. * @param string $executionType
  82. * @param string $from
  83. * @param int $syncData
  84. * @access public
  85. * @return void
  86. */
  87. public function create($projectID = 0, $productID = 0, $planID = 0, $executionType = 'stage', $from = '', $syncData = 0)
  88. {
  89. $this->loadModel('review');
  90. $this->productID = $this->commonAction($projectID, $productID);
  91. if($_POST)
  92. {
  93. $plans = $this->programplanZen->buildPlansForCreate($projectID, $planID);
  94. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  95. $this->programplan->create($plans, $projectID, $this->productID, $planID, $syncData);
  96. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  97. $locate = $this->session->projectPlanList ? $this->session->projectPlanList : $this->createLink('project', 'execution', "status=all&projectID={$projectID}&orderBy=order_asc&productID={$productID}");
  98. if($from == 'projectCreate') $locate = $this->createLink('project', 'create', "model=&programID=0&copyProjectID=0&extra=showTips=1,project=$projectID");
  99. $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $locate));
  100. }
  101. $project = $this->project->getById($projectID);
  102. $programPlan = $this->project->getById($planID);
  103. $productList = $this->session->hasProduct ? $this->product->getProductPairsByProject($projectID) : array();
  104. $plans = $this->programplan->getStage($projectID, $this->productID, 'all', 'grade_asc,order_asc');
  105. if($planID)
  106. {
  107. foreach($plans as $planID => $plan)
  108. {
  109. if($plan->path == $programPlan->path || strpos($plan->path, $programPlan->path) !== 0) unset($plans[$planID]);
  110. }
  111. }
  112. $plans = $this->programplanZen->sortPlans($plans);
  113. /* Set programplan typeList. */
  114. if($executionType != 'stage') unset($this->lang->execution->typeList[''], $this->lang->execution->typeList['stage']);
  115. /* Unset percent for create IPD project.*/
  116. if($project->model == 'ipd') $this->config->programplan->list->customCreateFields = str_replace(',percent', '', $this->config->programplan->list->customCreateFields);
  117. $viewData = new stdclass();
  118. $viewData->productID = $productID;
  119. $viewData->planID = $planID;
  120. $viewData->executionType = $executionType;
  121. $viewData->programPlan = $programPlan;
  122. $viewData->productList = $productList;
  123. $viewData->project = $project;
  124. $viewData->plans = $plans;
  125. $viewData->syncData = $syncData;
  126. $this->programplanZen->buildCreateView($viewData);
  127. $this->display();
  128. }
  129. /**
  130. * 编辑阶段内容。
  131. * Edit a project plan.
  132. *
  133. * @param int $planID
  134. * @param int $projectID
  135. * @access public
  136. * @return void
  137. */
  138. public function edit($planID = 0, $projectID = 0)
  139. {
  140. if($_POST)
  141. {
  142. $this->loadModel('execution');
  143. if(!empty($this->config->setCode) && strpos(",{$this->config->execution->edit->requiredFields},", ',code,') !== false) $this->config->programplan->form->edit['code']['required'] = true;
  144. $plan = form::data()->get();
  145. /* 设置计划和真实起始日期间隔时间。 */
  146. /* Set planDuration and realDuration. */
  147. if(in_array($this->config->edition, array('max', 'ipd')))
  148. {
  149. $plan->planDuration = $this->programplan->getDuration($plan->begin, $plan->end);
  150. $plan->realDuration = $this->programplan->getDuration($plan->realBegan, $plan->realEnd);
  151. }
  152. if($plan->parent)
  153. {
  154. $parentStage = $this->programplan->getByID($plan->parent);
  155. $plan->acl = $parentStage->acl;
  156. if($parentStage->attribute != 'mix') $plan->attribute = $parentStage->attribute;
  157. }
  158. if(empty($plan->realBegan)) $plan->realBegan = null;
  159. if(empty($plan->realEnd)) $plan->realEnd = null;
  160. if(empty($plan->percent)) $plan->percent = 0;
  161. $plan = $this->programplanZen->prepareEditPlan($planID, $projectID, $plan, isset($parentStage) ? $parentStage : null);
  162. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  163. $this->programplan->update($planID, $projectID, $plan);
  164. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  165. $newPlan = $this->programplan->fetchByID($planID);
  166. if($plan->parent != $newPlan->parent)
  167. {
  168. $this->programplan->computeProgress($planID, 'edit');
  169. $this->programplan->computeProgress($plan->parent, 'edit', true);
  170. }
  171. if($this->app->rawModule == 'marketresearch') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->session->marketstageList));
  172. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'callback' => 'loadCurrentPage', 'closeModal' => true));
  173. }
  174. $plan = $this->programplan->getByID($planID);
  175. $this->programplanZen->buildEditView($plan);
  176. }
  177. /**
  178. * 通过ajax请求保存自定义设置。
  179. * Save custom settings via ajax.
  180. *
  181. * @access public
  182. * @return void
  183. */
  184. public function ajaxCustom()
  185. {
  186. $owner = $this->app->user->account;
  187. $module = 'programplan';
  188. $this->app->loadLang('execution');
  189. $this->loadModel('datatable');
  190. $this->loadModel('setting');
  191. if($_POST)
  192. {
  193. $settings = form::data($this->config->programplan->form->ajaxCustom)->get();
  194. $this->programplan->saveCustomSetting($settings, $owner, $module);
  195. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => true));
  196. }
  197. /* Set Custom. */
  198. foreach(explode(',', $this->config->programplan->custom->customGanttFields) as $field) $customFields[$field] = $this->lang->programplan->ganttCustom[$field];
  199. $this->programplanZen->buildAjaxCustomView($owner, $module, $customFields);
  200. }
  201. /**
  202. * 处理甘特图拖拽事件数据。
  203. * Response gantt drag event.
  204. *
  205. * @access public
  206. */
  207. public function ajaxResponseGanttDragEvent()
  208. {
  209. if(!$this->post->id || !$this->post->type) return $this->send(array('result' => 'fail', 'message' => ''));
  210. $postData = form::data($this->config->programplan->form->updateDateByGantt)->get();
  211. $this->loadModel('task')->updateEsDateByGantt($postData);
  212. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  213. return $this->send(array('result' => 'success'));
  214. }
  215. /**
  216. * 处理甘特图删除连线事件。
  217. * Response gantt delete link.
  218. *
  219. * @access public
  220. * @return void
  221. */
  222. public function ajaxResponseGanttDeleteRelationEvent()
  223. {
  224. if(!empty($_POST['id'])) $this->loadModel('execution')->deleteRelation((int)$this->post->id);
  225. return $this->send(array('result' => 'success'));
  226. }
  227. /**
  228. * 处理甘特图移动事件数据。
  229. * Response gantt move event.
  230. *
  231. * @access public
  232. */
  233. public function ajaxResponseGanttMoveEvent()
  234. {
  235. if(!$this->post->id) return $this->send(array('result' => 'fail', 'message' => ''));
  236. $idList = explode('-', $this->post->id);
  237. $taskID = !empty($idList[1]) ? $idList[1] : 0;
  238. if(empty($taskID)) return $this->send(array('result' => 'fail', 'message' => ''));
  239. $postData = form::data($this->config->programplan->form->updateTaskOrderByGantt)->get();
  240. $this->loadModel('task')->updateOrderByGantt($postData);
  241. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  242. $this->loadModel('action')->create('task', (int)$taskID, 'ganttMove');
  243. return $this->send(array('result' => 'success'));
  244. }
  245. /**
  246. * ajax请求:获取阶段ID的属性。
  247. * AJAX: Get stageID attributes.
  248. *
  249. * @param int $stageID
  250. * @param string $attribute
  251. * @param string $projectModel
  252. * @access public
  253. * @return int
  254. */
  255. public function ajaxGetAttribute($stageID, $attribute, $projectModel = '')
  256. {
  257. $this->app->loadLang('stage');
  258. if($projectModel == 'ipd') $this->lang->stage->typeList = $this->lang->stage->ipdTypeList;
  259. $stageAttribute = $this->programplan->getStageAttribute($stageID);
  260. if(empty($stageAttribute) || $stageAttribute == 'mix') return print(html::select('attribute', $this->lang->stage->typeList, $attribute, "class='form-control chosen'"));
  261. return print(zget($this->lang->stage->typeList, $stageAttribute));
  262. }
  263. /**
  264. * ajax请求:获取阶段ID的属性。
  265. * AJAX: Get stageID attribute.
  266. *
  267. * @param int $stageID
  268. * @access public
  269. * @return int
  270. */
  271. public function ajaxGetStageAttr($stageID)
  272. {
  273. $stageAttribute = $this->programplan->getStageAttribute($stageID);
  274. return print($stageAttribute);
  275. }
  276. /**
  277. * 项目下维护任务关系。
  278. * Show relation of project.
  279. *
  280. * @param int $projectID
  281. * @param int $recTotal
  282. * @param int $recPerPage
  283. * @param int $pageID
  284. * @access public
  285. * @return void
  286. */
  287. public function relation($projectID = 0, $recTotal = 0, $recPerPage = 25, $pageID = 1)
  288. {
  289. echo $this->fetch('execution', 'relation', "executionID=$projectID&recTotal=$recTotal&recPerPage=$recPerPage&pageID=$pageID");
  290. }
  291. /**
  292. * 项目下创建任务关系。
  293. * Create relation of project.
  294. *
  295. * @param int $projectID
  296. * @access public
  297. * @return void
  298. */
  299. public function createRelation($projectID = 0)
  300. {
  301. echo $this->fetch('execution', 'createRelation', "executionID=$projectID");
  302. }
  303. /**
  304. * 项目下编辑任务关系。
  305. * Edit relation of project.
  306. *
  307. * @param int $relationID
  308. * @param int $projectID
  309. * @access public
  310. * @return void
  311. */
  312. public function editRelation($relationID, $projectID = 0)
  313. {
  314. echo $this->fetch('execution', 'editRelation', "relationID=$relationID&projectID=$projectID&executionID=0");
  315. }
  316. /**
  317. * 项目下批量编辑任务关系。
  318. * Batch edit relations of project.
  319. *
  320. * @param int $projectID
  321. * @access public
  322. * @return void
  323. */
  324. public function batchEditRelation($projectID = 0)
  325. {
  326. echo $this->fetch('execution', 'batchEditRelation', "projectID=$projectID&executionID=0");
  327. }
  328. /**
  329. * 项目下删除任务关系。
  330. * Delete relation of project.
  331. *
  332. * @param int $id
  333. * @param int $projectID
  334. * @access public
  335. * @return void
  336. * @param int $relationID
  337. */
  338. public function deleteRelation($relationID, $projectID)
  339. {
  340. $this->loadModel('execution')->deleteRelation($relationID);
  341. return $this->sendSuccess(array('load' => inlink('relation', "project=$projectID")));
  342. }
  343. /**
  344. * 项目下批量删除任务关系。
  345. * Batch delete relations of project.
  346. *
  347. * @param int $executionID
  348. * @access public
  349. * @return void
  350. * @param int $projectID
  351. */
  352. public function batchDeleteRelation($projectID)
  353. {
  354. $this->loadModel('execution');
  355. foreach($this->post->relationIdList as $relationID) $this->execution->deleteRelation((int)$relationID);
  356. return $this->sendSuccess(array('load' => inlink('relation', "projectID=$projectID")));
  357. }
  358. }