taskbatchcreate.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * The task batch create 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 taskBatchCreateEntry extends entry
  13. {
  14. /**
  15. * POST method.
  16. *
  17. * @param int $executionID
  18. * @access public
  19. * @return string
  20. */
  21. public function post($executionID = 0)
  22. {
  23. if(!$executionID) $executionID = $this->param('execution', 0);
  24. if(!$executionID) return $this->send400('Need execution id.');
  25. $control = $this->loadController('task', 'batchCreate');
  26. $storyID = $this->param('story', 0);
  27. $moduleID = $this->param('module', 0);
  28. $taskID = $this->param('task', 0);
  29. if(!isset($this->requestBody->tasks))
  30. {
  31. return $this->send400('Need tasks.');
  32. }
  33. $modules = array();
  34. $parents = array();
  35. $names = array();
  36. $colors = array();
  37. $types = array();
  38. $estimates = array();
  39. $estStarted = array();
  40. $deadlines = array();
  41. $desc = array();
  42. $pri = array();
  43. $stories = array();
  44. foreach($this->request('tasks') as $key => $task)
  45. {
  46. $number = $key + 1;
  47. if(!isset($task->name) or !isset($task->type)) return $this->send400('Task must have name and type.');
  48. $modules[$number] = isset($task->module) ? $task->module : $moduleID;
  49. $parents[$number] = isset($task->parent) ? $task->parent : $taskID;
  50. $names[$number] = $task->name;
  51. $colors[$number] = isset($task->color) ? $task->color : '';
  52. $types[$number] = $task->type;
  53. $estimates[$number] = isset($task->estimate) ? $task->estimate : 0;
  54. $estStarted[$number] = isset($task->estStarted) ? $task->estStarted : 0;
  55. $deadlines[$number] = isset($task->deadline) ? $task->deadline : null;
  56. $desc[$number] = isset($task->desc) ? $task->desc : '';
  57. $pri[$number] = isset($task->pri) ? $task->pri : 0;
  58. $stories[$number] = isset($task->story) ? $task->story : $storyID;
  59. }
  60. $this->setPost('module', $modules);
  61. $this->setPost('parent', $parents);
  62. $this->setPost('name', $names);
  63. $this->setPost('color', $colors);
  64. $this->setPost('type', $types);
  65. $this->setPost('estimate', $estimates);
  66. $this->setPost('estStarted', $estStarted);
  67. $this->setPost('deadline', $deadlines);
  68. $this->setPost('desc', $desc);
  69. $this->setPost('pri', $pri);
  70. $this->setPost('story', $stories);
  71. $control->batchCreate($executionID, $storyID, $moduleID, $taskID);
  72. $data = $this->getData();
  73. if(!$data) return $this->send400('error');
  74. if(isset($data->data->result) and $data->data->result == 'fail') return $this->sendError(400, $data->data->message);
  75. $tasks = $this->loadModel('task')->getByIdList((array)$data->idList);
  76. return $this->send(200, array('task' => $tasks));
  77. }
  78. }