productplans.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * The productplans 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 productplansEntry 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', 0);
  24. if(!$productID) return $this->sendError(400, 'No product id.');
  25. $control = $this->loadController('productplan', 'browse');
  26. $control->browse($productID, $this->param('branch', 0), $this->param('status', 'all'), $this->param('query', 0), $this->param('order', 'begin_desc'), 0, $this->param('limit', 20), $this->param('page', 1));
  27. /* Response */
  28. $data = $this->getData();
  29. if(isset($data->status) and $data->status == 'success')
  30. {
  31. $result = array();
  32. $plans = $data->data->plans;
  33. $pager = $data->data->pager;
  34. foreach($plans as $plan)
  35. {
  36. if($plan->parent > 0 and isset($result[$plan->parent]))
  37. {
  38. $parentPlan = $result[$plan->parent];
  39. if(!isset($parentPlan->children) or !is_array($parentPlan->children)) $parentPlan->children = array();
  40. $parentPlan->children[] = $plan;
  41. $result[$plan->parent] = $parentPlan;
  42. }
  43. else
  44. {
  45. $result[$plan->id] = $this->format($plan, 'begin:date,end:date,deleted:bool,project:int');
  46. }
  47. }
  48. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'plans' => array_values($result)));
  49. }
  50. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  51. return $this->sendError(400, 'error');
  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) return $this->sendError(400, 'No product id.');
  64. $control = $this->loadController('productplan', 'create');
  65. $fields = 'branch,begin,end,title,desc';
  66. $this->batchSetPost($fields);
  67. $this->setPost('product', $productID);
  68. $this->setPost('parent', $this->request('parent', 0));
  69. $this->setPost('branch', $this->request('branch', 0));
  70. $control->create($productID, $this->param('branch', 0), $this->param('parent', 0));
  71. $data = $this->getData();
  72. if(isset($data->result) and $data->result == 'success')
  73. {
  74. $plan = $this->loadModel('productplan')->getByID($data->id);
  75. $plan->stories = array();
  76. $plan->bugs = array();
  77. return $this->send(201, $this->format($plan, 'begin:date,end:date,deleted:bool,project:int'));
  78. }
  79. $this->sendError(400, array('message' => isset($data->message) ? $data->message : 'error'));
  80. }
  81. }