From 74a4cd7470552d059e256f9c2d56d6e751272ba7 Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Wed, 1 Dec 2021 10:00:06 +0800 Subject: [PATCH] + Add productplan methods for api. --- api/v1/entries/productplan.php | 6 +- api/v1/entries/productplanlinkbug.php | 50 +++++++++++++++ api/v1/entries/productplanlinkstory.php | 50 +++++++++++++++ api/v1/entries/productplans.php | 30 +++++++++ api/v1/entries/productplanunlinkbug.php | 45 ++++++++++++++ api/v1/entries/productplanunlinkstory.php | 45 ++++++++++++++ config/routes.php | 10 ++- framework/api/entry.class.php | 74 ++++++++++++----------- module/productplan/control.php | 2 + 9 files changed, 273 insertions(+), 39 deletions(-) create mode 100644 api/v1/entries/productplanlinkbug.php create mode 100644 api/v1/entries/productplanlinkstory.php create mode 100644 api/v1/entries/productplanunlinkbug.php create mode 100644 api/v1/entries/productplanunlinkstory.php diff --git a/api/v1/entries/productplan.php b/api/v1/entries/productplan.php index ab10d35d26..0ae5653eab 100644 --- a/api/v1/entries/productplan.php +++ b/api/v1/entries/productplan.php @@ -29,7 +29,11 @@ class productplanEntry extends Entry if(!$data or !isset($data->status)) return $this->send400('error'); if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); - $plan = $this->format($data->data->plan, 'begin:date,end:date,deleted:bool'); + $plan = $data->data->plan; + $plan->stories = $data->data->planStories; + $plan->bugs = $data->data->planBugs; + + $plan = $this->format($plan, 'begin:date,end:date,deleted:bool,stories:array,bugs:array'); return $this->send(200, $plan); } diff --git a/api/v1/entries/productplanlinkbug.php b/api/v1/entries/productplanlinkbug.php new file mode 100644 index 0000000000..b553a092b4 --- /dev/null +++ b/api/v1/entries/productplanlinkbug.php @@ -0,0 +1,50 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class productplanLinkBugEntry extends entry +{ + /** + * POST method. + * + * @param int $planID + * @access public + * @return void + */ + public function post($planID) + { + $fields = 'bugs'; + $this->batchSetPost($fields); + + $control = $this->loadController('productplan', 'linkBug'); + $control->linkBug($planID); + + $data = $this->getData(); + if(isset($data->result) and $data->result == 'success') + { + $control = $this->loadController('productplan', 'view'); + $control->view($planID); + + $data = $this->getData(); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $plan = $data->data->plan; + $plan->stories = $data->data->planStories; + $plan->bugs = $data->data->planBugs; + + $plan = $this->format($plan, 'begin:date,end:date,deleted:bool,stories:array,bugs:array'); + + return $this->send(200, $plan); + } + + $this->sendError(400, array('message' => isset($data->message) ? $data->message : 'error')); + } +} diff --git a/api/v1/entries/productplanlinkstory.php b/api/v1/entries/productplanlinkstory.php new file mode 100644 index 0000000000..c7956c3a4f --- /dev/null +++ b/api/v1/entries/productplanlinkstory.php @@ -0,0 +1,50 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class productplanLinkStoryEntry extends entry +{ + /** + * POST method. + * + * @param int $planID + * @access public + * @return void + */ + public function post($planID) + { + $fields = 'stories'; + $this->batchSetPost($fields); + + $control = $this->loadController('productplan', 'linkStory'); + $control->linkStory($planID); + + $data = $this->getData(); + if(isset($data->result) and $data->result == 'success') + { + $control = $this->loadController('productplan', 'view'); + $control->view($planID); + + $data = $this->getData(); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $plan = $data->data->plan; + $plan->stories = $data->data->planStories; + $plan->bugs = $data->data->planBugs; + + $plan = $this->format($plan, 'begin:date,end:date,deleted:bool,stories:array,bugs:array'); + + return $this->send(200, $plan); + } + + $this->sendError(400, array('message' => isset($data->message) ? $data->message : 'error')); + } +} diff --git a/api/v1/entries/productplans.php b/api/v1/entries/productplans.php index e2f0296c32..5fe3ace5e0 100644 --- a/api/v1/entries/productplans.php +++ b/api/v1/entries/productplans.php @@ -57,4 +57,34 @@ class productplansEntry extends entry return $this->sendError(400, 'error'); } + + /** + * POST method. + * + * @param int $productID + * @access public + * @return void + */ + public function post($productID = 0) + { + if(!$productID) $productID = $this->param('product', 0); + if(!$productID) return $this->sendError(400, 'No product id.'); + + $fields = 'branch,begin,end,title,desc'; + $this->batchSetPost($fields); + + $control = $this->loadController('productplan', 'create'); + $control->create($productID, $this->param('branch', 0), $this->param('parent', 0)); + + $data = $this->getData(); + if(isset($data->result) and $data->result == 'success') + { + $plan = $this->loadModel('productplan')->getByID($data->id); + $plan->stories = array(); + $plan->bugs = array(); + return $this->send(200, $plan); + } + + $this->sendError(400, array('message' => isset($data->message) ? $data->message : 'error')); + } } diff --git a/api/v1/entries/productplanunlinkbug.php b/api/v1/entries/productplanunlinkbug.php new file mode 100644 index 0000000000..12b05f9982 --- /dev/null +++ b/api/v1/entries/productplanunlinkbug.php @@ -0,0 +1,45 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class productplanUnlinkBugEntry extends entry +{ + /** + * POST method. + * + * @param int $planID + * @access public + * @return void + */ + public function post($planID) + { + $productplan = $this->loadModel('productplan'); + foreach($this->request('bugs', array()) as $bugID) + { + $productplan->unlinkBug($bugID, $planID); + if(dao::isError()) return $this->sendError('error'); + } + + $control = $this->loadController('productplan', 'view'); + $control->view($planID); + + $data = $this->getData(); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $plan = $data->data->plan; + $plan->stories = $data->data->planStories; + $plan->bugs = $data->data->planBugs; + + $plan = $this->format($plan, 'begin:date,end:date,deleted:bool,stories:array,bugs:array'); + + return $this->send(200, $plan); + } +} diff --git a/api/v1/entries/productplanunlinkstory.php b/api/v1/entries/productplanunlinkstory.php new file mode 100644 index 0000000000..94d24e7676 --- /dev/null +++ b/api/v1/entries/productplanunlinkstory.php @@ -0,0 +1,45 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class productplanUnlinkStoryEntry extends entry +{ + /** + * POST method. + * + * @param int $planID + * @access public + * @return void + */ + public function post($planID) + { + $productplan = $this->loadModel('productplan'); + foreach($this->request('stories', array()) as $storyID) + { + $productplan->unlinkStory($storyID, $planID); + if(dao::isError()) return $this->sendError('error'); + } + + $control = $this->loadController('productplan', 'view'); + $control->view($planID); + + $data = $this->getData(); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $plan = $data->data->plan; + $plan->stories = $data->data->planStories; + $plan->bugs = $data->data->planBugs; + + $plan = $this->format($plan, 'begin:date,end:date,deleted:bool,stories:array,bugs:array'); + + return $this->send(200, $plan); + } +} diff --git a/config/routes.php b/config/routes.php index 36e75c4167..089e444419 100644 --- a/config/routes.php +++ b/config/routes.php @@ -23,9 +23,13 @@ $routes['/products/:id'] = 'product'; $routes['/productlines'] = 'productLines'; $routes['/productlines/:id'] = 'productLine'; -$routes['/productplans'] = 'productPlans'; -$routes['/products/:id/plans'] = 'productPlans'; -$routes['/productplans/:id'] = 'productPlan'; +$routes['/productplans'] = 'productPlans'; +$routes['/products/:id/plans'] = 'productPlans'; +$routes['/productplans/:id'] = 'productPlan'; +$routes['/productplans/:id/linkstory'] = 'productPlanLinkStory'; +$routes['/productplans/:id/unlinkstory'] = 'productPlanUnlinkStory'; +$routes['/productplans/:id/linkbug'] = 'productPlanLinkBug'; +$routes['/productplans/:id/unlinkbug'] = 'productPlanUnlinkBug'; $routes['/releases'] = 'releases'; $routes['/products/:id/releases'] = 'releases'; diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php index f88046f590..08a140f4a5 100644 --- a/framework/api/entry.class.php +++ b/framework/api/entry.class.php @@ -576,43 +576,47 @@ class baseEntry { switch($type) { - case 'time': - $timeFormat = $this->param('timeFormat', 'utc'); - if($timeFormat == 'utc') - { - if(!$value or $value == '0000-00-00 00:00:00') return null; - return gmdate("Y-m-d\TH:i:s\Z", strtotime($value)); - } - return $value; - case 'date': - if(!$value or $value == '0000-00-00') return null; - return $value; - case 'bool': - return !empty($value); - case 'int': - return (int) $value; - case 'idList': - $values = explode(',', $value); - if(empty($values)) return array(); + case 'time': + $timeFormat = $this->param('timeFormat', 'utc'); + if($timeFormat == 'utc') + { + if(!$value or $value == '0000-00-00 00:00:00') return null; + return gmdate("Y-m-d\TH:i:s\Z", strtotime($value)); + } + return $value; + case 'date': + if(!$value or $value == '0000-00-00') return null; + return $value; + case 'bool': + return !empty($value); + case 'int': + return (int) $value; + case 'idList': + $values = explode(',', $value); + if(empty($values)) return array(); - $idList = array(); - foreach($values as $val) - { - if($val !== '') $idList[] = (int) $val; - } - return $idList; - case 'stringList': - $values = explode(',', $value); - if(empty($values)) return array(); + $idList = array(); + foreach($values as $val) + { + if($val !== '') $idList[] = (int) $val; + } + return $idList; + case 'stringList': + $values = explode(',', $value); + if(empty($values)) return array(); - $stringList = array(); - foreach($values as $val) - { - if($val !== '') $stringList[] = $val; - } - return $stringList; - default: - return $value; + $stringList = array(); + foreach($values as $val) + { + if($val !== '') $stringList[] = $val; + } + return $stringList; + case 'array': + $array = array(); + if(!empty($value)) foreach($value as $v) $array[] = $v; + return $array; + default: + return $value; } } diff --git a/module/productplan/control.php b/module/productplan/control.php index 008a027c55..32cebc6bb3 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -394,6 +394,7 @@ class productplan extends control if(!empty($_POST['stories'])) { $this->productplan->linkStory($planID); + if($this->viewType == 'json') return $this->send(array('result' => 'success')); die(js::locate(inlink('view', "planID=$planID&type=story&orderBy=$orderBy"), 'parent')); } @@ -531,6 +532,7 @@ class productplan extends control if(!empty($_POST['bugs'])) { $this->productplan->linkBug($planID); + if($this->viewType == 'json') return $this->send(array('result' => 'success')); die(js::locate(inlink('view', "planID=$planID&type=bug&orderBy=$orderBy"), 'parent')); }