* Fix api of program.
This commit is contained in:
@@ -108,7 +108,7 @@ class productEntry extends Entry
|
||||
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
|
||||
|
||||
$product = $this->product->getByID($productID);
|
||||
$this->send(200, array('product' => $this->format($product, 'createdDate:time')));
|
||||
$this->send(200, $this->format($product, 'createdDate:time'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,4 +11,59 @@
|
||||
*/
|
||||
class programEntry extends Entry
|
||||
{
|
||||
/**
|
||||
* GET method.
|
||||
*
|
||||
* @param int $programID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function get($programID)
|
||||
{
|
||||
$program = $this->loadModel('program')->getByID($programID);
|
||||
if(!$program) return $this->send404();
|
||||
|
||||
$this->send(200, $this->format($program, 'openedDate:time,realBegan:date,realEnd:date,deleted:bool'));
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT method.
|
||||
*
|
||||
* @param int $programID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function put($programID)
|
||||
{
|
||||
$oldProgram = $this->loadModel('program')->getByID($programID);
|
||||
|
||||
/* Set $_POST variables. */
|
||||
$fields = 'name,PM,budget,budgetUnit,desc,begin,end,realBegan,realEnd,ac,whitelist';
|
||||
$this->batchSetPost($fields, $oldProgram);
|
||||
|
||||
$control = $this->loadController('program', 'edit');
|
||||
$control->edit($programID);
|
||||
|
||||
$this->getData();
|
||||
$program = $this->program->getByID($programID);
|
||||
$this->send(200, $this->format($program, 'openedDate:time'));
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE method.
|
||||
*
|
||||
* @param int $programID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function delete($programID)
|
||||
{
|
||||
$control = $this->loadController('program', 'delete');
|
||||
$control->delete(0, $programID, 'true');
|
||||
|
||||
$data = $this->getData();
|
||||
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
|
||||
|
||||
$this->sendSuccess(200, 'success');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class projectsEntry extends entry
|
||||
|
||||
$project = $this->loadModel('project')->getByID($data->id);
|
||||
|
||||
$this->send(201, $this->format($project, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time'));
|
||||
$this->send(201, $this->format($project, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,budget:int'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -589,6 +589,8 @@ class baseEntry
|
||||
return $value;
|
||||
case 'bool':
|
||||
return !empty($value);
|
||||
case 'int':
|
||||
return (int) $value;
|
||||
case 'idList':
|
||||
$values = explode(',', $value);
|
||||
if(empty($values)) return array();
|
||||
|
||||
@@ -386,7 +386,11 @@ class program extends control
|
||||
public function delete($programID, $confirm = 'no')
|
||||
{
|
||||
$childrenCount = $this->dao->select('count(*) as count')->from(TABLE_PROGRAM)->where('parent')->eq($programID)->andWhere('deleted')->eq(0)->fetch('count');
|
||||
if($childrenCount) die(js::alert($this->lang->program->hasChildren));
|
||||
if($childrenCount)
|
||||
{
|
||||
if($this->viewType == 'json' or (defined('RUN_MODE') && RUN_MODE == 'api')) return $this->send(array('result' => 'fail', 'message' => 'Cannot delete the program has children'));
|
||||
die(js::alert($this->lang->program->hasChildren));
|
||||
}
|
||||
|
||||
$productCount = $this->dao->select('count(*) as count')->from(TABLE_PRODUCT)->where('program')->eq($programID)->andWhere('deleted')->eq(0)->fetch('count');
|
||||
if($productCount) die(js::alert($this->lang->program->hasProduct));
|
||||
|
||||
Reference in New Issue
Block a user