From 5afccaf4172a5cd414d18411466df56dd8624d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A1=E6=A0=8B?= Date: Fri, 19 Nov 2021 09:22:02 +0800 Subject: [PATCH] * code for task #44314. --- api/v1/entries/releases.php | 22 ++++++---------------- config/routes.php | 4 ++-- module/release/control.php | 5 +++-- module/release/model.php | 5 +++-- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/api/v1/entries/releases.php b/api/v1/entries/releases.php index 207da6b80d..688551ab67 100644 --- a/api/v1/entries/releases.php +++ b/api/v1/entries/releases.php @@ -15,26 +15,16 @@ class releasesEntry extends entry * GET method. * * @param int $productID - * @param int $projectID * @access public * @return void */ - public function get($productID = 0, $projectID = 0) + public function get($productID = 0) { - if(!$productID) $productID = $this->param('product'); - if(!$projectID) $projectID = $this->param('project'); - if(!$productID and !$projectID) return $this->sendError(400, 'Need product or project id.'); + if(empty($productID)) $productID = $this->param('product'); + if(empty($productID)) return $this->sendError(400, 'Need product id.'); - if($projectID) - { - $control = $this->loadController('projectrelease', 'browse'); - $control->browse($projectID, 0, $this->param('status', 'all')); - } - else - { - $control = $this->loadController('release', 'browse'); - $control->browse($productID, $this->param('branch', 0), $this->param('status', 'all')); - } + $control = $this->loadController('release', 'browse'); + $control->browse($productID, $this->param('branch', 0), $this->param('status', 'all'), $this->param('order', 't1.date_desc')); /* Response */ $data = $this->getData(); @@ -44,7 +34,7 @@ class releasesEntry extends entry $releases = $data->data->releases; foreach($releases as $release) $result[] = $this->format($release, 'deleted:bool,date:date'); - return $this->send(200, array('releases' => $result)); + return $this->send(200, array('total' => count($result), 'releases' => $result)); } if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); diff --git a/config/routes.php b/config/routes.php index 2e44c76381..9fe83eef7e 100644 --- a/config/routes.php +++ b/config/routes.php @@ -28,8 +28,8 @@ $routes['/products/:id/plans'] = 'productPlans'; $routes['/productplans/:id'] = 'productPlan'; $routes['/releases'] = 'releases'; -$routes['/product/:id/releases'] = 'releases'; -$routes['/projects/:id/releases'] = 'projectreleases'; +$routes['/products/:id/releases'] = 'releases'; +$routes['/projects/:id/releases'] = 'projectReleases'; $routes['/releases/:id'] = 'release'; $routes['/stories'] = 'stories'; diff --git a/module/release/control.php b/module/release/control.php index 346f0c06d3..6b381f4de1 100644 --- a/module/release/control.php +++ b/module/release/control.php @@ -37,17 +37,18 @@ class release extends control * @param int $productID * @param int $branch * @param string $type + * @param string $orderBy * @access public * @return void */ - public function browse($productID, $branch = 0, $type = 'all') + public function browse($productID, $branch = 0, $type = 'all', $orderBy = 't1.date_desc') { $this->commonAction($productID, $branch); $this->session->set('releaseList', $this->app->getURI(true), 'product'); $this->view->title = $this->view->product->name . $this->lang->colon . $this->lang->release->browse; $this->view->position[] = $this->lang->release->browse; - $this->view->releases = $this->release->getList($productID, $branch, $type); + $this->view->releases = $this->release->getList($productID, $branch, $type, $orderBy); $this->view->type = $type; $this->display(); } diff --git a/module/release/model.php b/module/release/model.php index da4afb63c3..afaaa2c65a 100644 --- a/module/release/model.php +++ b/module/release/model.php @@ -46,10 +46,11 @@ class releaseModel extends model * @param int $productID * @param int $branch * @param string $type + * @param string $orderBy * @access public * @return array */ - public function getList($productID, $branch = 0, $type = 'all') + public function getList($productID, $branch = 0, $type = 'all', $orderBy = 't1.date_desc') { return $this->dao->select('t1.*, t2.name as productName, t3.id as buildID, t3.name as buildName, t3.project, t4.name as projectName') ->from(TABLE_RELEASE)->alias('t1') @@ -60,7 +61,7 @@ class releaseModel extends model ->beginIF($branch)->andWhere('t1.branch')->eq($branch)->fi() ->beginIF($type != 'all')->andWhere('t1.status')->eq($type)->fi() ->andWhere('t1.deleted')->eq(0) - ->orderBy('t1.date DESC') + ->orderBy($orderBy) ->fetchAll(); }