* Batch create tasks.

This commit is contained in:
zhujinyong
2022-03-21 14:54:03 +08:00
parent 8432f93094
commit 56bb77baa9
4 changed files with 94 additions and 48 deletions

View File

@@ -0,0 +1,89 @@
<?php
/**
* The task batch create entry point of ZenTaoPMS.
*
* @copyright Copyright 2009-2021 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @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]);
}
}

View File

@@ -1,45 +0,0 @@
<?php
/**
* The task component entry point of ZenTaoPMS.
*
* @copyright Copyright 2009-2021 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @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]);
}
}

View File

@@ -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);

View File

@@ -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';