testtasks.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * The testtasks 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 testtasksEntry 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->getProjectTesttasks($projectID);
  24. /* Get all testtasks. */
  25. $control = $this->loadController('testtask', 'browse');
  26. $productID = $this->param('product', 0);
  27. $control->browse($productID, $this->param('branch', ''), ($productID > 0 ? 'local' : 'all') . ',' . $this->param('status', 'totalStatus'), $this->param('order', 'id_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1), $this->param('begin', ''), $this->param('end', ''));
  28. $data = $this->getData();
  29. if(!isset($data->status)) return $this->sendError(400, 'error');
  30. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  31. $pager = $data->data->pager;
  32. $result = array();
  33. foreach($data->data->tasks as $testtask)
  34. {
  35. $result[] = $this->format($testtask, 'begin:date,end:date,mailto:userList,owner:user,realFinishedDate:time');
  36. }
  37. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testtasks' => $result));
  38. }
  39. /**
  40. * Get testtasks of project.
  41. *
  42. * @param int $projectID
  43. * @access public
  44. * @return string
  45. */
  46. private function getProjectTesttasks($projectID)
  47. {
  48. $project = $this->loadModel('project')->getByID($projectID);
  49. if(!$project) return $this->send404();
  50. $this->app->loadClass('pager', $static = true);
  51. $pager = pager::init($this->param('total', 0), $this->param('limit', 20), $this->param('page', 1));
  52. $testtasks = $this->loadModel('testtask')->getProjectTasks($projectID, $this->param('order', 'id_desc'), $pager);
  53. $result = array();
  54. foreach($testtasks as $testtask)
  55. {
  56. $result[] = $this->format($testtask, 'realFinishedDate:time');
  57. }
  58. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testtasks' => $result));
  59. }
  60. /**
  61. * POST method.
  62. *
  63. * @access public
  64. * @param int $projectID
  65. * @return string
  66. */
  67. public function post($projectID = 0)
  68. {
  69. $control = $this->loadController('testtask', 'create');
  70. if(!$projectID) $projectID = $this->param('project', 0);
  71. $productID = $this->request('product', 0);
  72. $executionID = $this->request('execution', 0);
  73. $buildID = $this->request('build', 0);
  74. if(empty($projectID)) return $this->sendError(400, 'need project id!');
  75. if(empty($productID)) return $this->sendError(400, 'need product id!');
  76. if(empty($executionID)) return $this->sendError(400, 'need execution id!');
  77. if(empty($buildID)) return $this->sendError(400, 'need build id!');
  78. /* Check whether executionID and buildID is valid. */
  79. $executions = $this->loadModel('product')->getExecutionPairsByProduct($productID, '', $projectID);
  80. $builds = $this->loadModel('build')->getBuildPairs(array($productID), 'all', 'notrunk');
  81. if(!isset($executions[$executionID])) return $this->sendError(400, 'error execution id!');
  82. if(!isset($builds[$buildID])) return $this->sendError(400, 'error build id!');
  83. $fields = 'product,execution,build,name,begin,end,owner,type,pri,status,desc';
  84. $this->batchSetPost($fields);
  85. $this->requireFields('name,begin,end');
  86. $control->create($productID, $executionID, $build, $projectID);
  87. $data = $this->getData();
  88. if(!isset($data->id)) return $this->sendError(400, $data->message);
  89. $testtask = $this->loadModel('testtask')->getByID($data->id);
  90. return $this->send(201, $testtask);
  91. }
  92. }