issue.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * The issue 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 issueEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int|string $issueID. Issues id for Gitlab has '-', such as task-1, bug-1.
  18. * @access public
  19. * @return string
  20. */
  21. public function get($issueID)
  22. {
  23. /* If $issueID has '-', go to productIssue entry point for Gitlab. */
  24. if(strpos($issueID, '-') !== FALSE) return $this->fetch('productIssue', 'get', array('issueID' => $issueID));
  25. /* Otherwise, get issue of project. */
  26. $control = $this->loadController('issue', 'view');
  27. $control->view($issueID);
  28. $data = $this->getData();
  29. if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404();
  30. if(isset($data->status) and $data->status == 'success') return $this->send(200, $this->format($data->data->issue, 'createdDate:time,editedDate:time,assignedDate:time'));
  31. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  32. $this->sendError(400, 'error');
  33. }
  34. /**
  35. * PUT method.
  36. *
  37. * @param int $issueID
  38. * @access public
  39. * @return string
  40. */
  41. public function put($issueID)
  42. {
  43. $control = $this->loadController('issue', 'edit');
  44. $oldIssue = $this->loadModel('issue')->getByID($issueID);
  45. /* Set $_POST variables. */
  46. $fields = 'type,title,severity,pri,assignedTo,deadline,desc';
  47. $this->batchSetPost($fields, $oldIssue);
  48. $control->edit($issueID);
  49. $data = $this->getData();
  50. if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404();
  51. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  52. $issue = $this->issue->getByID($issueID);
  53. return $this->send(200, $this->format($issue, 'createdDate:time,editedDate:time,assignedDate:time'));
  54. }
  55. /**
  56. * DELETE method.
  57. *
  58. * @param int $issueID
  59. * @access public
  60. * @return string
  61. */
  62. public function delete($issueID)
  63. {
  64. $control = $this->loadController('issue', 'delete');
  65. $control->delete($issueID, 'true');
  66. $this->getData();
  67. return $this->sendSuccess(200, 'success');
  68. }
  69. }