stories.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * The stories 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 storiesEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $productID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($productID = 0)
  22. {
  23. if(!$productID) $productID = $this->param('product');
  24. if(!$productID) return $this->sendError(400, 'Need product id.');
  25. $control = $this->loadController('product', 'browse');
  26. $control->browse($productID, $this->param('branch', ''), $this->param('status', 'unclosed'), 0, $this->param('type', 'story'), $this->param('order', 'id_desc'), 0, $this->param('limit', 500), $this->param('page', 1));
  27. $data = $this->getData();
  28. if(!$data or !isset($data->status)) return $this->sendError(400, 'error');
  29. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  30. $stories = $data->data->stories;
  31. $pager = $data->data->pager;
  32. $requirements = $this->loadModel('story')->getRequirements($productID);
  33. if(!empty($requirements)) $requirements = $this->story->getByList(array_keys($requirements));
  34. $result = array();
  35. $this->loadModel('product');
  36. foreach($stories as $story)
  37. {
  38. $product = $this->product->getById($story->product);
  39. $story->productStatus = $product->status;
  40. if(isset($story->children))
  41. {
  42. $story->children = array_values((array)$story->children);
  43. foreach($story->children as $id => $children)
  44. {
  45. $childrenProduct = $this->product->getById($children->product);
  46. $story->children[$id]->productStatus = $childrenProduct->status;
  47. }
  48. }
  49. $result[] = $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');
  50. }
  51. return $this->send(201, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'stories' => $result, 'requirements' => $requirements));
  52. }
  53. /**
  54. * POST method.
  55. *
  56. * @param int $productID
  57. * @access public
  58. * @return string
  59. */
  60. public function post($productID = 0)
  61. {
  62. if(!$productID) $productID = $this->param('product', 0);
  63. if(!$productID and isset($this->requestBody->product)) $productID = $this->requestBody->product;
  64. if(!$productID) return $this->sendError(400, 'Need product id.');
  65. $control = $this->loadController('story', 'create');
  66. $fields = 'title,spec,verify,module,reviewer,type,parent,moduleOptionMenu,source,sourceNote,category,pri,estimate,mailto,keywords,notifyemail,uid,status';
  67. $this->batchSetPost($fields);
  68. $module = $this->request('module', 0) ? $this->request('module', 0) : 0;
  69. $this->setPost('plans', array($this->request('plan', 0)));
  70. $this->setPost('branches', array($this->request('branch')));
  71. $this->setPost('modules', array($module));
  72. $this->setPost('product', $productID);
  73. $this->setPost('type', $this->request('type', 'story'));
  74. $this->setPost('grade', $this->request('grade', ''));
  75. /* 获取评审相关参数 */
  76. $reviewer = $this->request('reviewer');
  77. $status = $this->request('status', 'active'); // 创建时默认状态为 'active'
  78. $forceReview = $this->loadModel('story')->checkForceReview($this->request('type', 'story'));
  79. if($forceReview)
  80. {
  81. $needNotReview = 0;
  82. }
  83. else
  84. {
  85. $needNotReview = empty($reviewer) ? 1 : 0;
  86. }
  87. $this->setPost('reviewer', $reviewer);
  88. $this->setPost('needNotReview', $needNotReview);
  89. /* 设置状态逻辑,与web端保持一致(参考 common.ui.js 中的 clickSubmit 函数) */
  90. /* 如果状态是 'active' 且有评审人且未勾选不需要评审,则将状态设置为 'reviewing' */
  91. $hasReviewer = !empty($reviewer);
  92. $isActiveNeedReview = $status == 'active' && !$needNotReview;
  93. if($hasReviewer && $isActiveNeedReview)
  94. {
  95. $this->setPost('status', 'reviewing');
  96. }
  97. else
  98. {
  99. /* 如果未指定状态,保持默认值 'active';如果指定了 'draft',保持 'draft' */
  100. $this->setPost('status', $status);
  101. }
  102. $this->requireFields('title,spec,pri,category');
  103. $control->create($productID, $this->param('branch', 0), $this->param('moduleID', 0), $this->param('storyID', 0), $this->param('objectID', 0), $this->param('bugID', 0), 0, 0, '', $this->param('type', 'story'));
  104. $data = $this->getData();
  105. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  106. if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
  107. $story = $this->loadModel('story')->getByID($data->id);
  108. 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'));
  109. }
  110. }