+ Add my risk api task#41819
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* 禅道API的risk资源类
|
||||
* 版本V1
|
||||
*
|
||||
* The risk entry point of zentaopms
|
||||
* Version 1
|
||||
*/
|
||||
class riskEntry extends Entry
|
||||
{
|
||||
public function get($riskID)
|
||||
{
|
||||
$control = $this->loadController('risk', 'view');
|
||||
$control->view($riskID);
|
||||
|
||||
$data = $this->getData();
|
||||
if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404();
|
||||
if(isset($data->status) and $data->status == 'success') $this->send(200, $this->format($data->data->risk, 'createdDate:time,editedDate:time'));
|
||||
if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
|
||||
|
||||
$this->sendError(400, 'error');
|
||||
}
|
||||
|
||||
public function put($riskID)
|
||||
{
|
||||
$oldRisk = $this->loadModel('risk')->getByID($riskID);
|
||||
|
||||
/* Set $_POST variables. */
|
||||
$fields = 'source,name,category,strategy,status,impact,probability,rate,identifiedDate,plannedClosedDate,actualClosedDate,resolvedBy,assignedTo,prevention,remedy,resolution';
|
||||
$this->batchSetPost($fields, $oldRisk);
|
||||
|
||||
$control = $this->loadController('risk', 'edit');
|
||||
$control->edit($riskID);
|
||||
|
||||
$this->getData();
|
||||
$risk = $this->risk->getByID($riskID);
|
||||
$this->send(200, $this->format($risk, 'createdDate:time,editedDate:time'));
|
||||
}
|
||||
|
||||
public function delete($riskID)
|
||||
{
|
||||
$control = $this->loadController('risk', 'delete');
|
||||
$control->delete($riskID, 'true');
|
||||
|
||||
$this->getData();
|
||||
$this->sendSuccess(200, 'success');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 禅道API的risks资源类
|
||||
* 版本V1
|
||||
*
|
||||
* The risks entry point of zentaopms
|
||||
* Version 1
|
||||
*/
|
||||
class risksEntry extends entry
|
||||
{
|
||||
public function get()
|
||||
{
|
||||
$control = $this->loadController('my', 'risk');
|
||||
$control->risk($this->param('type', 'assignedTo'), $this->param('order', 'id_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1));
|
||||
$data = $this->getData();
|
||||
|
||||
if(!isset($data->status)) return $this->sendError(400, 'error');
|
||||
if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
|
||||
|
||||
$pager = $data->data->pager;
|
||||
$result = array();
|
||||
foreach($data->data->risks as $risk)
|
||||
{
|
||||
$result[] = $this->format($risk, 'createdDate:time,editedDate:time');
|
||||
}
|
||||
return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'risks' => $result));
|
||||
}
|
||||
|
||||
public function post($projectID = 0)
|
||||
{
|
||||
if((int)$projectID <= 0) $this->sendError(400, 'The id of project is wrong.');
|
||||
|
||||
$fields = 'source,name,category,strategy,status,impact,probability,rate,identifiedDate,plannedClosedDate,actualClosedDate,resolvedBy,assignedTo,prevention,remedy,resolution';
|
||||
$this->batchSetPost($fields);
|
||||
|
||||
$this->setPost('impact', $this->request('impact', 3));
|
||||
$this->setPost('probability', $this->request('probability', 3));
|
||||
$this->setPost('rate', $this->request('rate', 9));
|
||||
$this->setPost('pri', 'middle');
|
||||
|
||||
$control = $this->loadController('risk', 'create');
|
||||
$this->requireFields('name');
|
||||
|
||||
$control->create($projectID);
|
||||
|
||||
$data = $this->getData();
|
||||
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
|
||||
if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
|
||||
|
||||
$risk = $this->loadModel('risk')->getByID($data->id);
|
||||
|
||||
$this->send(201, $this->format($risk, 'createdDate:time,editedDate:time'));
|
||||
}
|
||||
}
|
||||
@@ -51,4 +51,8 @@ $routes['/todos/:id'] = 'todo';
|
||||
$routes['/testtasks'] = 'testtasks';
|
||||
$routes['/testtasks/:id'] = 'testtask';
|
||||
|
||||
$routes['/projects/:project/risks'] = 'risks';
|
||||
$routes['/risks'] = 'risks';
|
||||
$routes['/risks/:id'] = 'risk';
|
||||
|
||||
$config->routes = $routes;
|
||||
|
||||
Reference in New Issue
Block a user