control.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. /**
  3. * The control file of stage currentModule of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://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 stage
  9. * @version $Id: control.php 5107 2013-07-12 01:46:12Z chencongzhi520@gmail.com $
  10. * @link https://www.zentao.net
  11. */
  12. class stage extends control
  13. {
  14. /**
  15. * 瀑布模型阶段列表页。
  16. * Waterfall model stage list page.
  17. *
  18. * @param int $groupID
  19. * @param string $orderBy
  20. * @access public
  21. * @return void
  22. */
  23. public function browse($groupID = 0, $orderBy = "order_asc")
  24. {
  25. if($this->config->edition != 'open')
  26. {
  27. $workflowGroup = $this->loadModel('workflowgroup')->getByID($groupID);
  28. if($workflowGroup->projectModel == 'ipd')
  29. {
  30. $this->config->stage->dtable->fieldList['type']['statusMap'] = $this->lang->stage->ipdTypeList;
  31. $this->config->stage->dtable->fieldList['TRpoint']['title'] = $this->lang->stage->TRpoint;
  32. $this->config->stage->dtable->fieldList['TRpoint']['type'] = 'desc';
  33. $this->config->stage->dtable->fieldList['TRpoint']['width'] = 100;
  34. $this->config->stage->dtable->fieldList['TRpoint']['flex'] = false;
  35. $this->config->stage->dtable->fieldList['TRpoint']['group'] = 3;
  36. $this->config->stage->dtable->fieldList['DCPpoint']['title'] = $this->lang->stage->DCPpoint;
  37. $this->config->stage->dtable->fieldList['DCPpoint']['type'] = 'desc';
  38. $this->config->stage->dtable->fieldList['DCPpoint']['width'] = 100;
  39. $this->config->stage->dtable->fieldList['DCPpoint']['flex'] = false;
  40. $this->config->stage->dtable->fieldList['DCPpoint']['group'] = 4;
  41. if(common::hasPriv('stage', 'setTRpoint'))
  42. {
  43. $this->config->stage->actionList['setTRpoint']['icon'] = 'tr-box';
  44. $this->config->stage->actionList['setTRpoint']['hint'] = $this->lang->stage->setTRpoint;
  45. $this->config->stage->actionList['setTRpoint']['url'] = array('module' => 'stage', 'method' => 'setTRpoint', 'params' => 'stageID={id}');
  46. $this->config->stage->actionList['setTRpoint']['data-toggle'] = 'modal';
  47. }
  48. if(common::hasPriv('stage', 'setDCPpoint'))
  49. {
  50. $this->config->stage->actionList['setDCPpoint']['icon'] = 'dcp-box';
  51. $this->config->stage->actionList['setDCPpoint']['hint'] = $this->lang->stage->setDCPpoint;
  52. $this->config->stage->actionList['setDCPpoint']['url'] = array('module' => 'stage', 'method' => 'setDCPpoint', 'params' => 'stageID={id}');
  53. $this->config->stage->actionList['setDCPpoint']['data-toggle'] = 'modal';
  54. }
  55. $this->config->stage->dtable->fieldList['actions']['menu'] = array('setTRpoint', 'setDCPpoint', 'edit', 'delete');
  56. $this->config->stage->dtable->fieldList['actions']['list'] = $this->config->stage->actionList;
  57. }
  58. }
  59. $this->view->title = $this->lang->stage->common . $this->lang->hyphen . $this->lang->stage->browseAB;
  60. $this->view->stages = $this->stage->getStages($orderBy, 0, $groupID);
  61. $this->view->orderBy = $orderBy;
  62. $this->view->groupID = $groupID;
  63. $this->display();
  64. }
  65. /**
  66. * 创建一个阶段。
  67. * Create a stage.
  68. *
  69. * @param int $groupID
  70. * @access public
  71. * @return void
  72. */
  73. public function create($groupID = 0)
  74. {
  75. $flow = $this->config->edition == 'open' ? new stdClass() : $this->loadModel('workflowgroup')->getByID($groupID);
  76. if($_POST)
  77. {
  78. if(isset($flow->projectModel) && $flow->projectModel == 'ipd') $this->config->stage->create->requiredFields = 'name,type';
  79. $stageData = form::data()
  80. ->setDefault('workflowGroup', $groupID)
  81. ->setDefault('createdBy', $this->app->user->account)
  82. ->setDefault('createdDate', helper::now())
  83. ->get();
  84. $stageID = $this->stage->create($stageData);
  85. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  86. $this->loadModel('action')->create('stage', $stageID, 'Opened');
  87. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => true));
  88. }
  89. unset($this->lang->stage->ipdTypeList['lifecycle']);
  90. $this->view->title = $this->lang->stage->common . $this->lang->hyphen . $this->lang->stage->create;
  91. $this->view->groupID = $groupID;
  92. $this->view->flow = $flow;
  93. $this->display();
  94. }
  95. /**
  96. * 批量创建阶段。
  97. * Batch create stages.
  98. *
  99. * @param int $groupID
  100. * @access public
  101. * @return void
  102. */
  103. public function batchCreate($groupID = 0)
  104. {
  105. $flow = $this->config->edition == 'open' ? new stdClass() : $this->loadModel('workflowgroup')->getByID($groupID);
  106. if($_POST)
  107. {
  108. if(isset($flow->projectModel) && $flow->projectModel == 'ipd')
  109. {
  110. $this->config->stage->create->requiredFields = 'name,type';
  111. if(isset($this->config->setPercent) && $this->config->setPercent == 1) $this->config->stage->form->batchcreate['percent']['required'] = false;
  112. }
  113. $stages = form::batchData()->get();
  114. $this->stage->batchCreate($groupID, $stages);
  115. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  116. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => inlink('browse', "groupID={$groupID}")));
  117. }
  118. unset($this->lang->stage->ipdTypeList['lifecycle']);
  119. $this->view->title = $this->lang->stage->common . $this->lang->hyphen . $this->lang->stage->batchCreate;
  120. $this->view->groupID = $groupID;
  121. $this->view->flow = $flow;
  122. $this->display();
  123. }
  124. /**
  125. * 编辑一个阶段。
  126. * Edit a stage.
  127. *
  128. * @param int $stageID
  129. * @access public
  130. * @return void
  131. */
  132. public function edit($stageID = 0)
  133. {
  134. $stage = $this->stage->getByID($stageID);
  135. $flow = $this->config->edition == 'open' ? new stdClass() : $this->loadModel('workflowgroup')->getByID($stage->workflowGroup);
  136. if($_POST)
  137. {
  138. if(isset($flow->projectModel) && $flow->projectModel == 'ipd') $this->config->stage->edit->requiredFields = 'name,type';
  139. $stageData = form::data()
  140. ->setDefault('editedBy', $this->app->user->account)
  141. ->setDefault('editedDate', helper::now())
  142. ->get();
  143. $changes = $this->stage->update($stageID, $stageData);
  144. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  145. $actionID = $this->loadModel('action')->create('stage', $stageID, 'Edited');
  146. if(!empty($changes)) $this->action->logHistory($actionID, $changes);
  147. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => true));
  148. }
  149. unset($this->lang->stage->ipdTypeList['lifecycle']);
  150. $this->view->title = $this->lang->stage->common . $this->lang->hyphen . $this->lang->stage->edit;
  151. $this->view->stage = $stage;
  152. $this->view->flow = $flow;
  153. $this->display();
  154. }
  155. /**
  156. * 设置阶段的类型。
  157. * Custom settings stage type.
  158. *
  159. * @param string lang2Set
  160. * @access public
  161. * @return void
  162. */
  163. public function setType($lang2Set = '')
  164. {
  165. $this->loadModel('custom');
  166. if(empty($lang2Set)) $lang2Set = $this->app->getClientLang();
  167. $currentLang = $this->app->getClientLang();
  168. $fieldList = zget($this->lang->stage, 'typeList', '');
  169. if($lang2Set == 'all')
  170. {
  171. $fieldList = array();
  172. $items = $this->custom->getItems("lang=all&module=stage&section=typeList&vision={$this->config->vision}");
  173. foreach($items as $key => $item) $fieldList[$key] = $item->value;
  174. }
  175. /* Check whether the current language has been customized. */
  176. $dbFields = $this->custom->getItems("lang=$lang2Set&module=stage&section=typeList&vision={$this->config->vision}");
  177. if(empty($dbFields)) $dbFields = $this->custom->getItems("lang=" . ($lang2Set == $currentLang ? 'all' : $currentLang) . "&module=stage&section=typeList");
  178. if($dbFields)
  179. {
  180. $dbField = reset($dbFields);
  181. if($lang2Set != $dbField->lang)
  182. {
  183. $lang2Set = $dbField->lang;
  184. foreach($fieldList as $key => $value)
  185. {
  186. if(isset($dbFields[$key]) && $value != $dbFields[$key]->value) $fieldList[$key] = $dbFields[$key]->value;
  187. }
  188. }
  189. }
  190. if($_POST)
  191. {
  192. $data = form::data()->get();
  193. $this->custom->deleteItems("lang={$this->post->lang}&module=stage&section=typeList");
  194. if($data->lang == 'all') $this->custom->deleteItems("lang={$currentLang}&module=stage&section=typeList");
  195. foreach($data->keys as $index => $key)
  196. {
  197. $value = empty($data->values[$index]) ? '' : $data->values[$index];
  198. if(!$value || !$key) continue;
  199. $this->custom->setItem("{$data->lang}.stage.typeList.{$key}", $value);
  200. }
  201. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
  202. }
  203. $this->view->title = $this->lang->stage->common . $this->lang->hyphen . $this->lang->stage->setType;
  204. $this->view->currentLang = $currentLang;
  205. $this->view->lang2Set = !empty($lang2Set) ? $lang2Set : $lang;
  206. $this->view->fieldList = $fieldList;
  207. $this->display();
  208. }
  209. /**
  210. * 删除一个阶段。
  211. * Delete a stage.
  212. *
  213. * @param int $stageID
  214. * @access public
  215. * @return void
  216. */
  217. public function delete($stageID)
  218. {
  219. $stage = $this->stage->getByID($stageID);
  220. $this->stage->delete(TABLE_STAGE, $stageID);
  221. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  222. return $this->sendSuccess(array('closeModal' => true, 'load' => true));
  223. }
  224. /**
  225. * 设置TR评审点。
  226. * Set TR point of stage.
  227. *
  228. * @param int $stageID
  229. * @access public
  230. * @return void
  231. */
  232. public function setTRpoint($stageID)
  233. {
  234. $this->app->loadLang('review');
  235. if(!empty($_POST))
  236. {
  237. $this->lang->stage->title = $this->lang->stage->TRname;
  238. $points = form::batchData()->get();
  239. $this->stage->setPoint('TR', $stageID, $points);
  240. if(dao::isError()) return $this->sendError(dao::getError());
  241. return $this->sendSuccess(array('closeModal' => true, 'load' => true));
  242. }
  243. $this->view->type = 'TR';
  244. $this->view->approvals = $this->loadModel('approvalflow')->getPairs('project');
  245. $this->view->stagePoints = $this->stage->getStagePoints('TR', $stageID);
  246. $this->display('stage', 'setPoint');
  247. }
  248. /**
  249. * 设置DCP评审点。
  250. * Set point of stage.
  251. *
  252. * @param int $stageID
  253. * @access public
  254. * @return void
  255. */
  256. public function setDCPpoint($stageID)
  257. {
  258. $this->app->loadLang('review');
  259. if(!empty($_POST))
  260. {
  261. $this->lang->stage->title = $this->lang->stage->DCPname;
  262. $points = form::batchData()->get();
  263. $this->stage->setPoint('DCP', $stageID, $points);
  264. if(dao::isError()) return $this->sendError(dao::getError());
  265. return $this->sendSuccess(array('closeModal' => true, 'load' => true));
  266. }
  267. $this->view->type = 'DCP';
  268. $this->view->approvals = $this->loadModel('approvalflow')->getPairs('project');
  269. $this->view->stagePoints = $this->stage->getStagePoints('DCP', $stageID);
  270. $this->display('stage', 'setPoint');
  271. }
  272. /**
  273. * 更新排序。
  274. * Update order.
  275. *
  276. * @access public
  277. * @return void
  278. */
  279. public function updateOrder()
  280. {
  281. $sortedIdList = json_decode($this->post->sortedIdList, true);
  282. $this->stage->updateOrder($sortedIdList);
  283. }
  284. }