issues.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * The issues 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 issuesEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $projectID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($projectID = 0)
  22. {
  23. if($projectID) return $this->getProjectIssues($projectID);
  24. /* Get my issues defaultly. */
  25. $control = $this->loadController('my', 'issue');
  26. $control->issue($this->param('type', 'assignedTo'), $this->param('order', 'id_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1));
  27. $data = $this->getData();
  28. if(!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. $pager = $data->data->pager;
  31. $result = array();
  32. foreach($data->data->issues as $issue)
  33. {
  34. $result[] = $this->format($issue, 'createdDate:time,editedDate:time,assignedDate:time');
  35. }
  36. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'issues' => $result));
  37. }
  38. /**
  39. * Get issues of project.
  40. *
  41. * @param int $projectID
  42. * @access public
  43. * @return string
  44. */
  45. private function getProjectIssues($projectID)
  46. {
  47. $control = $this->loadController('issue', 'browse');
  48. $project = $this->loadModel('project')->getByID($projectID);
  49. if(!$project) return $this->send404();
  50. $control->browse($projectID, $this->param('type', 'all'), 0, $this->param('order', ''), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1));
  51. $data = $this->getData();
  52. if(!isset($data->status)) return $this->sendError(400, 'error');
  53. if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
  54. $pager = $data->data->pager;
  55. $result = array();
  56. foreach($data->data->issueList as $issue)
  57. {
  58. $result[] = $this->format($issue, 'createdDate:time,editedDate:time,assignedDate:time');
  59. }
  60. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'issues' => $result));
  61. }
  62. /**
  63. * POST method.
  64. *
  65. * @param int $projectID
  66. * @access public
  67. * @return string
  68. */
  69. public function post($projectID = 0)
  70. {
  71. $control = $this->loadController('issue', 'create');
  72. $project = $this->loadModel('project')->getByID($projectID);
  73. if(!$project) return $this->send404();
  74. $fields = 'type,title,severity,pri,assignedTo,deadline,desc';
  75. $this->batchSetPost($fields);
  76. $this->requireFields('type,title,severity');
  77. $control->create($projectID);
  78. $data = $this->getData();
  79. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  80. if(isset($data->result) and!isset($data->id)) return $this->sendError(400, $data->message);
  81. $issue = $this->loadModel('issue')->getByID($data->id);
  82. return $this->send(201, $this->format($issue, 'createdDate:time,editedDate:time,assignedDate:time'));
  83. }
  84. }