From ca8de6eea26ede859aa27627ef12711f3806204c Mon Sep 17 00:00:00 2001 From: songchenxuan Date: Wed, 16 Mar 2022 15:15:31 +0800 Subject: [PATCH] *Create a children task. --- api/v1/entries/taskcomponent.php | 45 ++++++++++++++++++++++++++++++++ config/routes.php | 1 + 2 files changed, 46 insertions(+) create mode 100644 api/v1/entries/taskcomponent.php diff --git a/api/v1/entries/taskcomponent.php b/api/v1/entries/taskcomponent.php new file mode 100644 index 0000000000..6921b7e5b1 --- /dev/null +++ b/api/v1/entries/taskcomponent.php @@ -0,0 +1,45 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class taskComponentEntry extends Entry +{ + /** + * POST method. + * + * @param int $taskID + * @access public + * @return void + */ + public function post($taskID) + { + $fields = 'name,type,assignedTo,parent,estimate,story,module,pri,desc,estStarted,deadline'; + $this->batchSetPost($fields); + + $fields = explode(',', $fields); + foreach($fields as $field) $this->setArrayPost($field); + $task = $this->loadModel('task')->getById($taskID); + + $control = $this->loadController('task', 'batchCreate'); + $control->batchCreate($task->execution, 0, 0, $taskID); + + $data = $this->getData(); + if(!$data) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $task = $this->task->getById($data->idList[0]); + $this->send(200, $this->format($task, 'deadline:date,openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,realStarted:time,finishedBy:user,finishedDate:time,closedBy:user,closedDate:time,canceledBy:user,canceledDate:time,lastEditedBy:user,lastEditedDate:time,deleted:bool,mailto:userList')); + } + + public function setArrayPost($field) + { + $_POST[$field] = array('0' => $_POST[$field]); + } +} diff --git a/config/routes.php b/config/routes.php index 95da122a32..fc96a8da72 100644 --- a/config/routes.php +++ b/config/routes.php @@ -66,6 +66,7 @@ $routes['/executions/:id'] = 'execution'; $routes['/executions/:id/tasks'] = 'tasks'; $routes['/tasks'] = 'tasks'; $routes['/tasks/:id'] = 'task'; +$routes['/tasks/:id/component'] = 'taskComponent'; $routes['/tasks/:id/assignto'] = 'taskAssignTo'; $routes['/tasks/:id/start'] = 'taskStart'; $routes['/tasks/:id/pause'] = 'taskPause';