summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-07-05 14:10:03 -0400
committerFrederic Guillot <fred@kanboard.net>2015-07-05 14:10:03 -0400
commit67b9a56469b406b44cd1baad4445ddb6d707794f (patch)
tree7b7c31a6d8fbbebbf3d0a1a60d271d215040f5b2 /app
parentafab68b130ccdd97a7575a682683d6df71006748 (diff)
Add urls in api response for tasks and projects
Diffstat (limited to 'app')
-rw-r--r--app/Api/Project.php30
-rw-r--r--app/Api/Task.php26
2 files changed, 50 insertions, 6 deletions
diff --git a/app/Api/Project.php b/app/Api/Project.php
index 2451cd9c..faf2a3da 100644
--- a/app/Api/Project.php
+++ b/app/Api/Project.php
@@ -12,17 +12,17 @@ class Project extends Base
{
public function getProjectById($project_id)
{
- return $this->project->getById($project_id);
+ return $this->formatProject($this->project->getById($project_id));
}
public function getProjectByName($name)
{
- return $this->project->getByName($name);
+ return $this->formatProject($this->project->getByName($name));
}
public function getAllProjects()
{
- return $this->project->getAll();
+ return $this->formatProjects($this->project->getAll());
}
public function removeProject($project_id)
@@ -82,4 +82,28 @@ class Project extends Base
list($valid,) = $this->project->validateModification($values);
return $valid && $this->project->update($values);
}
+
+ private function formatProject($project)
+ {
+ if (! empty($project)) {
+ $project['url'] = array(
+ 'board' => $this->helper->url->base().$this->helper->url->to('board', 'show', array('project_id' => $project['id'])),
+ 'calendar' => $this->helper->url->base().$this->helper->url->to('calendar', 'show', array('project_id' => $project['id'])),
+ 'list' => $this->helper->url->base().$this->helper->url->to('listing', 'show', array('project_id' => $project['id'])),
+ );
+ }
+
+ return $project;
+ }
+
+ private function formatProjects($projects)
+ {
+ if (! empty($projects)) {
+ foreach ($projects as &$project) {
+ $project = $this->formatProject($project);
+ }
+ }
+
+ return $projects;
+ }
}
diff --git a/app/Api/Task.php b/app/Api/Task.php
index e06c012b..ade49a6d 100644
--- a/app/Api/Task.php
+++ b/app/Api/Task.php
@@ -14,17 +14,17 @@ class Task extends Base
{
public function getTask($task_id)
{
- return $this->taskFinder->getById($task_id);
+ return $this->formatTask($this->taskFinder->getById($task_id));
}
public function getTaskByReference($project_id, $reference)
{
- return $this->taskFinder->getByReference($project_id, $reference);
+ return $this->formatTask($this->taskFinder->getByReference($project_id, $reference));
}
public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN)
{
- return $this->taskFinder->getAll($project_id, $status_id);
+ return $this->formatTasks($this->taskFinder->getAll($project_id, $status_id));
}
public function getOverdueTasks()
@@ -115,4 +115,24 @@ class Task extends Base
list($valid) = $this->taskValidator->validateApiModification($values);
return $valid && $this->taskModification->update($values);
}
+
+ private function formatTask($task)
+ {
+ if (! empty($task)) {
+ $task['url'] = $this->helper->url->base().$this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']));
+ }
+
+ return $task;
+ }
+
+ private function formatTasks($tasks)
+ {
+ if (! empty($tasks)) {
+ foreach ($tasks as &$task) {
+ $task = $this->formatTask($task);
+ }
+ }
+
+ return $tasks;
+ }
}