executions.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * The executions entry point 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 entries
  9. * @version 1
  10. * @link https://www.zentao.net
  11. */
  12. class executionsEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $projectID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($projectID = 0)
  22. {
  23. $appendFields = $this->param('fields', '');
  24. $withProject = $this->param('withProject', '');
  25. $mergeChildren = $this->param('mergeChildren', 0);
  26. if(strpos(strtolower(",{$appendFields},"), ',dropmenu,') !== false) return $this->getDropMenu();
  27. if($projectID)
  28. {
  29. $control = $this->loadController('project', 'execution');
  30. $control->execution($this->param('status', 'undone'), $projectID, $this->param('order', 'id_desc'), $this->param('product', 0), 0, $this->param('limit', 20), $this->param('page', 1));
  31. /* Response */
  32. $data = $this->getData();
  33. if(!$data or !isset($data->status)) return $this->sendError(400, 'error');
  34. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  35. $executions = $data->data->executionStats;
  36. $pager = $data->data->pager;
  37. $projects = $data->data->projects;
  38. }
  39. else
  40. {
  41. $control = $this->loadController('execution', 'all');
  42. $control->all($this->param('status', 'all'), $this->param('order', 'id_desc'), 0, '', 0, $this->param('limit', 20), $this->param('page', 1));
  43. $data = $this->getData();
  44. if(!$data or !isset($data->status)) return $this->sendError(400, 'error');
  45. if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
  46. $executions = $data->data->executionStats;
  47. $pager = $data->data->pager;
  48. $projects = $data->data->projects;
  49. }
  50. $result = array();
  51. $executionsMap = array();
  52. foreach($data->data->executionStats as $execution)
  53. {
  54. $execution = $this->filterFields($execution, 'id,name,project,code,type,parent,begin,end,status,openedBy,openedDate,delay,progress,children,isParent,' . $appendFields);
  55. $execution = $this->format($execution, 'openedBy:user,openedDate:time,lastEditedBy:user,lastEditedDate:time,closedBy:user,closedDate:time,canceledBy:user,canceledDate:time,PM:user,PO:user,RD:user,QD:user,whitelist:userList,begin:date,end:date,realBegan:date,realEnd:date,deleted:bool');
  56. if($mergeChildren)
  57. {
  58. $executionsMap[$execution->id] = $execution;
  59. }
  60. else
  61. {
  62. $result[] = $execution;
  63. }
  64. }
  65. if($mergeChildren)
  66. {
  67. foreach($executionsMap as $execution)
  68. {
  69. if(empty($execution->parent))
  70. {
  71. $result[$execution->id] = $execution;
  72. }
  73. elseif((!empty($execution->parent) and $execution->parent != 0 and $execution->parent != '0') and isset($executionsMap[$execution->parent]))
  74. {
  75. $parentExecution = $executionsMap[$execution->parent];
  76. if(!isset($parentExecution->children)) $parentExecution->children = array();
  77. $parentExecution->children[] = $execution;
  78. }
  79. else
  80. {
  81. $result[$execution->id] = $execution;
  82. }
  83. }
  84. $result = array_values($result);
  85. }
  86. $data = array();
  87. $data['page'] = $pager->pageID;
  88. $data['total'] = $pager->recTotal;
  89. $data['limit'] = $pager->recPerPage;
  90. $data['executions'] = $result;
  91. if(!empty($withProject)) $data['projects'] = $projects;
  92. return $this->send(200, $data);
  93. }
  94. /**
  95. * POST method.
  96. *
  97. * @param int $projectID
  98. * @access public
  99. * @return string
  100. */
  101. public function post($projectID = 0)
  102. {
  103. $useCode = $this->checkCodeUsed();
  104. $control = $this->loadController('execution', 'create');
  105. $fields = 'project,name,begin,end,lifetime,desc,days,percent,parent';
  106. if($useCode) $fields .= ',code';
  107. $this->batchSetPost($fields);
  108. $projectID = $this->param('project', $projectID);
  109. $this->setPost('project', $projectID);
  110. $this->setPost('acl', $this->request('acl', 'private'));
  111. $this->setPost('PO', $this->request('PO', ''));
  112. $this->setPost('PM', $this->request('PM', ''));
  113. $this->setPost('QD', $this->request('QD', ''));
  114. $this->setPost('RD', $this->request('RD', ''));
  115. $this->setPost('whitelist', $this->request('whitelist', array()));
  116. $this->setPost('products', $this->request('products', array()));
  117. $this->setPost('plans', $this->request('plans', array()));
  118. $this->setPost('teamMembers', $this->request('teamMembers', array()));
  119. $requireFields = 'name,begin,end';
  120. if($useCode) $requireFields .= ',code';
  121. $this->requireFields($requireFields);
  122. $control->create($projectID);
  123. $data = $this->getData();
  124. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  125. $execution = $this->loadModel('execution')->getByID($data->id);
  126. return $this->send(201, $this->format($execution, 'openedBy:user,openedDate:time,lastEditedBy:user,lastEditedDate:time,closedBy:user,closedDate:time,canceledBy:user,canceledDate:time,PM:user,PO:user,RD:user,QD:user,whitelist:userList,begin:date,end:date,realBegan:date,realEnd:date,deleted:bool'));
  127. }
  128. /**
  129. * Get drop menu.
  130. *
  131. * @access public
  132. * @return string
  133. */
  134. public function getDropMenu()
  135. {
  136. $control = $this->loadController('execution', 'ajaxGetDropMenu');
  137. $control->ajaxGetDropMenu($this->request('executionID', 0), $this->request('module', 'execution'), $this->request('method', 'task'), $this->request('extra', ''));
  138. $data = $this->getData();
  139. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  140. $account = $this->app->user->account;
  141. $dropMenu = array('involved' => array(), 'other' => array(), 'closed' => array());
  142. foreach($data->data->projects as $projectID => $projectName)
  143. {
  144. if(!isset($data->data->projectExecutions->$projectID)) continue;
  145. foreach($data->data->projectExecutions->$projectID as $execution)
  146. {
  147. if(helper::diffDate(date('Y-m-d'), $execution->end) > 0) $execution->delay = true;
  148. $teams = $execution->teams;
  149. $execution = $this->filterFields($execution, 'id,project,model,type,name,code,status,PM,delay');
  150. $execution->name = $projectName . '/' . $execution->name;
  151. if($execution->status == 'closed')
  152. {
  153. $dropMenu['closed'][] = $execution;
  154. }
  155. elseif($execution->status != 'done' and $execution->status != 'closed' and ($execution->PM == $account or isset($teams->$account)))
  156. {
  157. $dropMenu['involved'][] = $execution;
  158. }
  159. else
  160. {
  161. $dropMenu['other'][] = $execution;
  162. }
  163. }
  164. }
  165. return $this->send(200, $dropMenu);
  166. }
  167. }