projectreleases.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * The projectreleases 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 projectReleasesEntry 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(empty($projectID)) $projectID = $this->param('project');
  24. if(empty($projectID)) return $this->sendError(400, 'Need project id.');
  25. $page = intval($this->param('page', 1));
  26. $limit = intval($this->param('limit', 20));
  27. $control = $this->loadController('projectrelease', 'browse');
  28. $control->browse($projectID, $this->param('execution', 0), $this->param('status', 'all'), $this->param('order', 't1.date_desc'), 0, $limit, $page);
  29. /* Response */
  30. $data = $this->getData();
  31. if(isset($data->status) and $data->status == 'success')
  32. {
  33. $result = array();
  34. $releases = $data->data->releases;
  35. $pager = $data->data->pager;
  36. foreach($releases as $release) $result[] = $this->format($release, 'deleted:bool,date:date,mailto:userList');
  37. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'releases' => $result));
  38. }
  39. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  40. return $this->sendError(400, 'error');
  41. }
  42. /**
  43. * POST method.
  44. *
  45. * @param int $projectID
  46. * @access public
  47. * @return string
  48. */
  49. public function post($projectID = 0)
  50. {
  51. $control = $this->loadController('projectrelease', 'create');
  52. $project = $this->loadModel('project')->getByID($projectID);
  53. if(!$project) return $this->send404();
  54. $fields = 'name,build,product,date,notify,mailto';
  55. $this->batchSetPost($fields);
  56. $this->setPost('desc', $this->request('desc', ''));
  57. $this->requireFields('name,date');
  58. $control->create($projectID);
  59. $data = $this->getData();
  60. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  61. if(isset($data->result) and!isset($data->id)) return $this->sendError(400, $data->message);
  62. $release = $this->loadModel('projectrelease')->getByID($data->id);
  63. return $this->send(201, $release);
  64. }
  65. }