story.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * The story 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 storyEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $storyID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($storyID)
  22. {
  23. $this->resetOpenApp($this->param('tab', 'product'));
  24. $control = $this->loadController('story', 'view');
  25. $control->view($storyID, 0, 0, $this->param('type', 'story'));
  26. $data = $this->getData();
  27. if(!$data or !isset($data->status)) return $this->send400('error');
  28. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  29. $story = $data->data->story;
  30. if(!empty($story->children)) $story->children = array_values((array)$story->children);
  31. if(isset($story->planTitle)) $story->planTitle = array_values((array)$story->planTitle);
  32. if($story->parent > 0) $story->parentPri = $this->dao->select('pri')->from(TABLE_STORY)->where('id')->eq($story->parent)->fetch('pri');
  33. /* Set product name and status*/
  34. $story->productName = $data->data->product->name;
  35. $story->productStatus = $data->data->product->status;
  36. /* Set module title */
  37. $moduleTitle = '';
  38. if(empty($story->module)) $moduleTitle = '/';
  39. if($story->module)
  40. {
  41. $modulePath = $data->data->modulePath;
  42. foreach($modulePath as $key => $module)
  43. {
  44. $moduleTitle .= $module->name;
  45. if(isset($modulePath[$key + 1])) $moduleTitle .= '/';
  46. }
  47. }
  48. $story->moduleTitle = $moduleTitle;
  49. $storyTasks = array();
  50. foreach($story->tasks as $executionTasks)
  51. {
  52. foreach($executionTasks as $task)
  53. {
  54. if(!isset($data->data->executions->{$task->execution})) continue;
  55. $storyTasks[] = $this->filterFields($task, 'id,name,type,status,assignedTo');
  56. }
  57. }
  58. $story->tasks = $this->format($storyTasks, 'assignedTo:user');
  59. $story->bugs = array();
  60. foreach($data->data->bugs as $bug) $story->bugs[] = $this->filterFields($bug, 'id,title,status,pri,severity');
  61. $story->cases = array();
  62. foreach($data->data->cases as $case) $story->cases[] = $this->filterFields($case, 'id,title,pri,status');
  63. $story->requirements = array();
  64. foreach($data->data->relations as $relation) $story->requirements[] = $this->filterFields($relation, 'id,title');
  65. $story->actions = $this->loadModel('action')->processActionForAPI($data->data->actions, $data->data->users, $this->lang->story);
  66. $preAndNext = $data->data->preAndNext;
  67. $story->preAndNext = array();
  68. $story->preAndNext['pre'] = $preAndNext->pre ? $preAndNext->pre->id : '';
  69. $story->preAndNext['next'] = $preAndNext->next ? $preAndNext->next->id : '';
  70. $actionBtnList = $this->loadModel('common')->buildOperateMenu($story, $story->type);
  71. $story->actionBtnList = array_column(zget($actionBtnList, 'mainActions', array()), 'icon');
  72. return $this->send(200, $this->format($story, 'title:decodeHtml,openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,reviewedBy:user,reviewedDate:time,lastEditedBy:user,lastEditedDate:time,closedBy:user,closedDate:time,deleted:bool,mailto:userList'));
  73. }
  74. /**
  75. * PUT method.
  76. *
  77. * @param int $storyID
  78. * @access public
  79. * @return string
  80. */
  81. public function put($storyID)
  82. {
  83. $control = $this->loadController('story', 'edit');
  84. $oldStory = $this->loadModel('story')->getByID($storyID);
  85. /* Set $_POST variables. */
  86. $fields = 'title,product,parent,reviewer,type,plan,module,source,sourceNote,category,pri,estimate,mailto,keywords,uid,stage,notifyEmail,status,needNotReview';
  87. $this->batchSetPost($fields, $oldStory);
  88. /* 设置状态逻辑,与web端保持一致(参考 common.ui.js 中的 clickSubmit 函数) */
  89. $reviewer = $this->request('reviewer');
  90. $status = $this->request('status', $oldStory->status);
  91. $forceReview = $this->loadModel('story')->checkForceReview($oldStory->type);
  92. if($forceReview)
  93. {
  94. $needNotReview = 0;
  95. }
  96. else
  97. {
  98. $needNotReview = empty($reviewer) ? 1 : 0;
  99. }
  100. $this->setPost('reviewer', $reviewer);
  101. $this->setPost('needNotReview', $needNotReview);
  102. /* 如果设置了评审人且满足以下条件之一,则将状态设置为 'reviewing':
  103. * 1. 状态是 'active' 且未勾选不需要评审
  104. * 2. 原状态是 'draft' 或 'changing' 且未在请求中指定状态
  105. */
  106. $hasReviewer = !empty($reviewer);
  107. $isActiveNeedReview = $status == 'active' && !$needNotReview;
  108. $isDraftChangingWithoutStatus = strpos('draft,changing', $oldStory->status) !== false && !isset($this->requestBody->status);
  109. if($hasReviewer && ($isActiveNeedReview || $isDraftChangingWithoutStatus))
  110. {
  111. $this->setPost('status', 'reviewing');
  112. }
  113. $control->edit($storyID);
  114. $data = $this->getData();
  115. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  116. if(!isset($data->data)) return $this->sendError(400, 'error');
  117. $story = $this->story->getByID($storyID);
  118. return $this->send(200, $this->format($story, 'openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,reviewedBy:user,reviewedDate:time,lastEditedBy:user,lastEditedDate:time,closedBy:user,closedDate:time,deleted:bool,mailto:userList'));
  119. }
  120. /**
  121. * DELETE method.
  122. *
  123. * @param int $storyID
  124. * @access public
  125. * @return string
  126. */
  127. public function delete($storyID)
  128. {
  129. $control = $this->loadController('story', 'delete');
  130. $control->delete($storyID, 'yes');
  131. $this->getData();
  132. return $this->sendSuccess(200, 'success');
  133. }
  134. }