* Finish task#41822
This commit is contained in:
46
api/v1/entries/department.php
Normal file
46
api/v1/entries/department.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* 禅道API的department资源类
|
||||
* 版本V1
|
||||
*
|
||||
* The department entry point of zentaopms
|
||||
* Version 1
|
||||
*/
|
||||
class departmentEntry extends Entry
|
||||
{
|
||||
public function get($departmentID)
|
||||
{
|
||||
$dept = $this->loadModel('dept')->getByID($departmentID);
|
||||
|
||||
if(!$dept) return $this->send404();
|
||||
return $this->send(200, $dept);
|
||||
}
|
||||
|
||||
public function put($departmentID)
|
||||
{
|
||||
$oldDept = $this->loadModel('dept')->getByID($departmentID);
|
||||
|
||||
/* Set $_POST variables. */
|
||||
$fields = 'parent,name,manager';
|
||||
$this->batchSetPost($fields, $oldDept);
|
||||
|
||||
$this->requireFields('name');
|
||||
$control = $this->loadController('dept', 'edit');
|
||||
$control->edit($departmentID);
|
||||
|
||||
$this->getData();
|
||||
$department = $this->dept->getByID($departmentID);
|
||||
$this->send(200, $department);
|
||||
}
|
||||
|
||||
public function delete($departmentID)
|
||||
{
|
||||
$control = $this->loadController('dept', 'delete');
|
||||
$control->delete($departmentID, 'true');
|
||||
|
||||
$data = $this->getData();
|
||||
if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
|
||||
|
||||
$this->sendSuccess(200, 'success');
|
||||
}
|
||||
}
|
||||
17
api/v1/entries/departments.php
Normal file
17
api/v1/entries/departments.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* 禅道API的departments资源类
|
||||
* 版本V1
|
||||
*
|
||||
* The departments entry point of zentaopms
|
||||
* Version 1
|
||||
*/
|
||||
class departmentsEntry extends entry
|
||||
{
|
||||
public function get()
|
||||
{
|
||||
$depts = $this->loadModel('dept')->getDataStructure();
|
||||
|
||||
return $this->send(200, $depts);
|
||||
}
|
||||
}
|
||||
@@ -58,4 +58,7 @@ $routes['/projects/:projectID/risks'] = 'risks';
|
||||
$routes['/risks'] = 'risks';
|
||||
$routes['/risks/:id'] = 'risk';
|
||||
|
||||
$routes['/departments'] = 'departments';
|
||||
$routes['/departments/:id'] = 'department';
|
||||
|
||||
$config->routes = $routes;
|
||||
|
||||
@@ -88,6 +88,7 @@ class dept extends control
|
||||
if(!empty($_POST))
|
||||
{
|
||||
$this->dept->update($deptID);
|
||||
if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success'));
|
||||
die(js::alert($this->lang->dept->successSave) . js::reload('parent'));
|
||||
}
|
||||
|
||||
@@ -120,8 +121,16 @@ class dept extends control
|
||||
/* Check this dept when delete. */
|
||||
$sons = $this->dept->getSons($deptID);
|
||||
$users = $this->dept->getUsers('all', $deptID);
|
||||
if($sons) die(js::alert($this->lang->dept->error->hasSons));
|
||||
if($users) die(js::alert($this->lang->dept->error->hasUsers));
|
||||
if($sons)
|
||||
{
|
||||
if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'message' => $this->lang->dept->error->hasSons));
|
||||
die(js::alert($this->lang->dept->error->hasSons));
|
||||
}
|
||||
if($users)
|
||||
{
|
||||
if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'message' => $this->lang->dept->error->hasUsers));
|
||||
die(js::alert($this->lang->dept->error->hasUsers));
|
||||
}
|
||||
|
||||
if($confirm == 'no')
|
||||
{
|
||||
@@ -130,6 +139,7 @@ class dept extends control
|
||||
else
|
||||
{
|
||||
$this->dept->delete($deptID);
|
||||
if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success'));
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user