bugs.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * The bugs 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 bugsEntry 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(empty($productID)) $productID = $this->param('product', 0);
  24. if(empty($productID)) return $this->sendError(400, 'Need product id.');
  25. $control = $this->loadController('bug', 'browse');
  26. $control->browse($productID, $this->param('branch', 'all'), $this->param('status', ''), 0, $this->param('order', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1));
  27. $data = $this->getData();
  28. if(isset($data->status) and $data->status == 'success')
  29. {
  30. $bugs = $data->data->bugs;
  31. $pager = $data->data->pager;
  32. $result = array();
  33. $this->loadModel('product');
  34. foreach($bugs as $bug)
  35. {
  36. $product = $this->product->getById($bug->product);
  37. $bug->statusName = $this->lang->bug->statusList[$bug->status];
  38. $bug->productStatus = $product->status;
  39. $result[$bug->id] = $this->format($bug, 'activatedDate:time,openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,mailto:userList,resolvedBy:user,resolvedDate:time,closedBy:user,closedDate:time,lastEditedBy:user,lastEditedDate:time,deadline:date,deleted:bool');
  40. }
  41. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'bugs' => array_values($result)));
  42. }
  43. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  44. return $this->sendError(400, 'error');
  45. }
  46. /**
  47. * POST method.
  48. *
  49. * @param int $productID
  50. * @access public
  51. * @return string
  52. */
  53. public function post($productID = 0)
  54. {
  55. if(!$productID) $productID = $this->param('product');
  56. if(!$productID and isset($this->requestBody->product)) $productID = $this->requestBody->product;
  57. if(!$productID) return $this->sendError(400, 'Need product id.');
  58. $control = $this->loadController('bug', 'create');
  59. $fields = 'title,project,execution,browser,branch,os,assignedTo,pri,module,severity,type,story,task,mailto,keywords,steps,uid,deadline,plan,feedbackBy';
  60. $this->batchSetPost($fields);
  61. $this->setPost('openedBuild', $this->request('openedBuild', ["trunk"]));
  62. $caseID = $this->request('case', 0);
  63. if($caseID)
  64. {
  65. $case = $this->loadModel('testcase')->getById($caseID);
  66. if($case)
  67. {
  68. $this->setPost('case', $case->id);
  69. $this->setPost('caseVersion', $case->version);
  70. }
  71. }
  72. $this->setPost('product', $productID);
  73. $this->setPost('notifyEmail', implode(',', $this->request('notifyEmail', array())));
  74. $this->requireFields('title,pri,severity,type,openedBuild');
  75. $control->create($productID);
  76. $data = $this->getData();
  77. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  78. if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
  79. $bug = $this->loadModel('bug')->getByID($data->id);
  80. return $this->send(201, $this->format($bug, 'activatedDate:time,openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,mailto:userList,resolvedBy:user,resolvedDate:time,closedBy:user,closedDate:time,lastEditedBy:user,lastEditedDate:time,deadline:date,deleted:bool'));
  81. }
  82. }