diff --git a/api/v1/entries/taskbatchcreate.php b/api/v1/entries/taskbatchcreate.php new file mode 100644 index 0000000000..a992624e18 --- /dev/null +++ b/api/v1/entries/taskbatchcreate.php @@ -0,0 +1,89 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class taskBatchCreateEntry extends Entry +{ + /** + * POST method. + * + * @param int $executionID + * @access public + * @return void + */ + public function post($executionID = 0) + { + if(!$executionID) $executionID = $this->param('execution', 0); + if(!$executionID) return $this->send400('Need execution id.'); + + $storyID = $this->param('story', 0); + $moduleID = $this->param('module', 0); + $taskID = $this->param('task', 0); + + if(!isset($this->requestBody->tasks)) + { + return $this->send400('Need tasks.'); + } + + $modules = array(); + $parents = array(); + $names = array(); + $colors = array(); + $types = array(); + $estimates = array(); + $estStarted = array(); + $deadlines = array(); + $desc = array(); + $pri = array(); + $stories = array(); + foreach($this->request('tasks') as $task) + { + if(!isset($task->name) or !isset($task->type)) return $this->send400('Task must have name and type.'); + + $modules[] = isset($task->module) ? $task->module : $moduleID; + $parents[] = isset($task->parent) ? $task->parent : $taskID; + $names[] = $task->name; + $colors[] = isset($task->color) ? $task->color : ''; + $types[] = $task->type; + $estimates[] = isset($task->estimate) ? $task->estimate : 0; + $estStarted[] = isset($task->estStarted) ? $task->estStarted : 0; + $deadlines[] = isset($task->deadline) ? $task->deadline : null; + $desc[] = isset($task->desc) ? $task->desc : ''; + $pri[] = isset($task->pri) ? $task->pri : ''; + $stories[] = isset($task->story) ? $task->story : $storyID; + } + $this->setPost('module', $modules); + $this->setPost('parent', $parents); + $this->setPost('name', $names); + $this->setPost('color', $colors); + $this->setPost('type', $types); + $this->setPost('estimate', $estimates); + $this->setPost('estStarted', $estStarted); + $this->setPost('deadline', $deadlines); + $this->setPost('desc', $desc); + $this->setPost('pri', $pri); + $this->setPost('story', $stories); + + $control = $this->loadController('task', 'batchCreate'); + $control->batchCreate($executionID, $storyID, $moduleID, $taskID); + + exit; + $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); + + $this->send(200, array()); + } + + public function setArrayPost($field) + { + $_POST[$field] = array('0' => $_POST[$field]); + } +} diff --git a/api/v1/entries/taskcomponent.php b/api/v1/entries/taskcomponent.php deleted file mode 100644 index 6921b7e5b1..0000000000 --- a/api/v1/entries/taskcomponent.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @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/api/v1/entries/testsuite.php b/api/v1/entries/testsuite.php index 4ac05ec019..a3074a07d9 100644 --- a/api/v1/entries/testsuite.php +++ b/api/v1/entries/testsuite.php @@ -29,11 +29,11 @@ class testsuiteEntry extends entry if(!isset($data->data->suite)) $this->sendError(400, 'error'); $suite = $this->format($data->data->suite, 'addedBy:user,addedDate:time,lastEditedBy:user,lastEditedDate:time,deleted:bool'); - $suite->cases = array(); + $suite->testcases = array(); foreach($data->data->cases as $case) { - $suite->cases[] = $this->format($case, 'openedBy:user,openedDate:time,lastEditedBy:user,lastEditedDate:time,lastRunDate:time,scriptedDate:date,reviewedBy:user,reviewedDate:date,deleted:bool'); + $suite->testcases[] = $this->format($case, 'openedBy:user,openedDate:time,lastEditedBy:user,lastEditedDate:time,lastRunDate:time,scriptedDate:date,reviewedBy:user,reviewedDate:date,deleted:bool'); } $this->send(200, $suite); diff --git a/config/routes.php b/config/routes.php index df7cda86a9..324765ae4d 100644 --- a/config/routes.php +++ b/config/routes.php @@ -68,10 +68,12 @@ $routes['/projects/:id/executions'] = 'executions'; $routes['/executions'] = 'executions'; $routes['/executions/:id'] = 'execution'; +$routes['/executions/:id/tasks/batchCreate'] = 'taskBatchCreate'; +$routes['/tasks/batchCreate'] = 'taskBatchCreate'; + $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';