diff --git a/api/v1/entries/product.php b/api/v1/entries/product.php index c59ea57f78..80c03aed25 100644 --- a/api/v1/entries/product.php +++ b/api/v1/entries/product.php @@ -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')); } /** diff --git a/api/v1/entries/program.php b/api/v1/entries/program.php index 17a023d90b..7245b2405d 100644 --- a/api/v1/entries/program.php +++ b/api/v1/entries/program.php @@ -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'); + } } diff --git a/api/v1/entries/projects.php b/api/v1/entries/projects.php index 4dfcd56b23..9c55caff1d 100644 --- a/api/v1/entries/projects.php +++ b/api/v1/entries/projects.php @@ -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')); } /** diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php index a68bd080e0..86e3a5feb9 100644 --- a/framework/api/entry.class.php +++ b/framework/api/entry.class.php @@ -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(); diff --git a/module/program/control.php b/module/program/control.php index 2c659df5ce..8283df5908 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -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));