diff --git a/api/v1/entries/issues.php b/api/v1/entries/issues.php index 5697355fbf..b51b49d5e5 100644 --- a/api/v1/entries/issues.php +++ b/api/v1/entries/issues.php @@ -8,8 +8,11 @@ */ class issuesEntry extends entry { - public function get() + public function get($projectID = 0) { + if($projectID) return $this->getProjectIssues($projectID); + + /* Get my issues defaultly. */ $control = $this->loadController('my', 'issue'); $control->issue($this->param('type', 'assignedTo'), $this->param('order', 'id_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1)); $data = $this->getData(); @@ -27,6 +30,28 @@ class issuesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'issues' => $result)); } + private function getProjectIssues($projectID) + { + $project = $this->loadModel('project')->getByID($projectID); + if(!$project) return $this->send404(); + + $control = $this->loadController('issue', 'browse'); + $control->browse($projectID, $this->param('type', 'all'), 0, $this->param('order', ''), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1)); + $data = $this->getData(); + + if(!isset($data->status)) return $this->sendError(400, 'error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + + $pager = $data->data->pager; + $result = array(); + foreach($data->data->issueList as $issue) + { + $result[] = $this->format($issue, 'createdDate:time,editedDate:time,assignedDate:time'); + } + + return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'issues' => $result)); + } + public function post($projectID = 0) { if((int) $projectID <= 0) $this->sendError(400, 'The id of project is wrong.'); diff --git a/api/v1/entries/risks.php b/api/v1/entries/risks.php index e40a6fc157..9d66757519 100644 --- a/api/v1/entries/risks.php +++ b/api/v1/entries/risks.php @@ -8,11 +8,25 @@ */ class risksEntry extends entry { - public function get() + public function get($projectID = 0) { - $control = $this->loadController('my', 'risk'); - $control->risk($this->param('type', 'assignedTo'), $this->param('order', 'id_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1)); - $data = $this->getData(); + if(!$projectID) + { + /* Get my risks defaultly. */ + $control = $this->loadController('my', 'risk'); + $control->risk($this->param('type', 'assignedTo'), $this->param('order', 'id_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1)); + $data = $this->getData(); + } + else + { + $project = $this->loadModel('project')->getByID($projectID); + if(!$project) return $this->send404(); + + /* Get risks by project. */ + $control = $this->loadController('risk', 'browse'); + $control->browse($projectID, $this->param('type', 'all'), '', $this->param('order', ''), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1)); + $data = $this->getData(); + } if(!isset($data->status)) return $this->sendError(400, 'error'); if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); diff --git a/api/v1/entries/testtasks.php b/api/v1/entries/testtasks.php index bcfb90e213..5a7da5b00e 100644 --- a/api/v1/entries/testtasks.php +++ b/api/v1/entries/testtasks.php @@ -8,10 +8,14 @@ */ class testtasksEntry extends entry { - public function get() + public function get($projectID = 0) { - $control = $this->loadController('testtask', 'browse'); - $control->browse($this->param('productID', 0), $this->param('branch', ''), ($this->param('productID', 0) > 0 ? 'local' : 'all') . ',' . $this->param('status', 'totalStatus'), $this->param('order', 'date_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1), $this->param('begin', ''), $this->param('end', '')); + if($projectID) return $this->getProjectTesttasks($projectID); + + /* Get all testtasks. */ + $control = $this->loadController('testtask', 'browse'); + $productID = $this->param('productID', 0); + $control->browse($productID, $this->param('branch', ''), ($productID > 0 ? 'local' : 'all') . ',' . $this->param('status', 'totalStatus'), $this->param('order', 'id_desc'), $this->param('total', 0), $this->param('limit', 20), $this->param('page', 1), $this->param('begin', ''), $this->param('end', '')); $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); @@ -26,4 +30,23 @@ class testtasksEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testtasks' => $result)); } + + private function getProjectTesttasks($projectID) + { + $project = $this->loadModel('project')->getByID($projectID); + if(!$project) return $this->send404(); + + $this->app->loadClass('pager', $static = true); + $pager = pager::init($this->param('total', 0), $this->param('limit', 20), $this->param('page', 1)); + + $testtasks = $this->loadModel('testtask')->getProjectTasks($projectID, $this->param('order', 'id_desc'), $pager); + + $result = array(); + foreach($testtasks as $testtask) + { + $result[] = $this->format($testtask, 'realFinishedDate:time'); + } + + return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testtasks' => $result)); + } } diff --git a/config/routes.php b/config/routes.php index 97d2116f0e..f451094201 100644 --- a/config/routes.php +++ b/config/routes.php @@ -50,11 +50,12 @@ $routes['/issues/:issueID'] = 'issue'; $routes['/todos'] = 'todos'; $routes['/todos/:id'] = 'todo'; -$routes['/testtasks'] = 'testtasks'; -$routes['/testtasks/:id'] = 'testtask'; +$routes['/projects/:projectID/testtasks'] = 'testtasks'; +$routes['/testtasks'] = 'testtasks'; +$routes['/testtasks/:id'] = 'testtask'; -$routes['/projects/:project/risks'] = 'risks'; -$routes['/risks'] = 'risks'; -$routes['/risks/:id'] = 'risk'; +$routes['/projects/:projectID/risks'] = 'risks'; +$routes['/risks'] = 'risks'; +$routes['/risks/:id'] = 'risk'; $config->routes = $routes;