execution.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * The execution 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 executionEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $executionID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($executionID)
  22. {
  23. $fields = $this->param('fields');
  24. $status = $this->param('status', 'all');
  25. $control = $this->loadController('execution', 'view');
  26. $control->view($executionID);
  27. $data = $this->getData();
  28. if(!$data or !isset($data->status)) return $this->send400('error');
  29. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  30. $execution = $this->format($data->data->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');
  31. $execution->progress = ($execution->totalConsumed + $execution->totalLeft) ? round($execution->totalConsumed / ($execution->totalConsumed + $execution->totalLeft) * 100, 1) : 0;
  32. $execution->teamMembers = array_values((array)$data->data->teamMembers);
  33. $execution->products = array();
  34. foreach($data->data->products as $productID => $executionProduct)
  35. {
  36. if($status == 'noclosed' and $executionProduct->status == 'closed') continue;
  37. $product = new stdclass();
  38. $product->id = $executionProduct->id;
  39. $product->name = $executionProduct->name;
  40. $product->plans = array();
  41. foreach($executionProduct->plans as $planID)
  42. {
  43. $plan = new stdclass();
  44. $plan->id = trim($planID, ',');
  45. $plan->name = $data->data->planGroups->{$productID}->{$plan->id};
  46. $product->plans[] = $plan;
  47. }
  48. $execution->products[] = $product;
  49. }
  50. $this->loadModel('testcase');
  51. $execution->caseReview = ($this->config->testcase->needReview or !empty($this->config->testcase->forceReview));
  52. if(!$fields) $this->send(200, $execution);
  53. $users = $data->data->users;
  54. /* Set other fields. */
  55. $fields = explode(',', strtolower($fields));
  56. foreach($fields as $field)
  57. {
  58. switch($field)
  59. {
  60. case 'modules':
  61. $control = $this->loadController('tree', 'browsetask');
  62. $control->browsetask($executionID);
  63. $data = $this->getData();
  64. if(isset($data->status) and $data->status == 'success')
  65. {
  66. $execution->modules = $data->data->tree;
  67. }
  68. case 'builds':
  69. $execution->builds = $this->loadModel('build')->getBuildPairs(array($productID), 'all', 'noempty,noterminate,nodone', $executionID, 'execution');
  70. break;
  71. case 'moduleoptionmenu':
  72. $execution->moduleOptionMenu = $this->loadModel('tree')->getTaskOptionMenu($executionID, 0, 'allModule');
  73. break;
  74. case 'members':
  75. $execution->members = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution', 'nodeleted');;
  76. unset($execution->members['']);
  77. break;
  78. case 'stories':
  79. $stories = $this->loadModel('story')->getExecutionStories($executionID);
  80. foreach($stories as $storyID => $story) $stories[$storyID] = $this->filterFields($story, 'id,title,module,pri,status,stage,estimate');
  81. $execution->stories = array_values($stories);
  82. break;
  83. case 'actions':
  84. $actions = $data->data->actions;
  85. $execution->actions = $this->loadModel('action')->processActionForAPI($actions, $users, $this->lang->execution);
  86. break;
  87. case "dynamics":
  88. $dynamics = $data->data->dynamics ?? array();
  89. $execution->dynamics = $this->loadModel('action')->processDynamicForAPI($dynamics);
  90. break;
  91. case 'chartdata':
  92. list($dateList, $interval) = $this->loadModel('execution')->getDateList($execution->begin, $execution->end, 'noweekend', 0, 'Y-m-d');
  93. $execution->chartData = $this->execution->buildBurnData($executionID, $dateList, 'left');
  94. break;
  95. }
  96. }
  97. return $this->send(200, $execution);
  98. }
  99. /**
  100. * PUT method.
  101. *
  102. * @param int $executionID
  103. * @access public
  104. * @return string
  105. */
  106. public function put($executionID)
  107. {
  108. $control = $this->loadController('execution', 'edit');
  109. $oldExecution = $this->loadModel('execution')->getByID($executionID);
  110. $useCode = $this->checkCodeUsed();
  111. /* Set $_POST variables. */
  112. $fields = 'project,name,begin,end,lifetime,desc,days,acl,status,PO,PM,QD,RD';
  113. if($useCode) $fields .= ',code';
  114. $this->batchSetPost($fields, $oldExecution);
  115. $this->setPost('whitelist', $this->request('whitelist', explode(',', $oldExecution->whitelist)));
  116. $products = $this->loadModel('product')->getProducts($executionID);
  117. $this->setPost('products', $this->request('products', array_keys($products)));
  118. $control->edit($executionID);
  119. $data = $this->getData();
  120. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  121. if(!isset($data->result)) return $this->sendError(400, 'error');
  122. $execution = $this->execution->getByID($executionID);
  123. return $this->send(200, $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'));
  124. }
  125. /**
  126. * DELETE method.
  127. *
  128. * @param int $executionID
  129. * @access public
  130. * @return string
  131. */
  132. public function delete($executionID)
  133. {
  134. $control = $this->loadController('execution', 'delete');
  135. $control->delete($executionID, 'true');
  136. $this->getData();
  137. return $this->sendSuccess(200, 'success');
  138. }
  139. }