summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Guillot <contact@fredericguillot.com>2014-02-16 18:47:11 -0500
committerFrédéric Guillot <contact@fredericguillot.com>2014-02-16 18:47:11 -0500
commitc2f8e1c4360cbdd0c740b747d017034d97d8e053 (patch)
tree0de69c3cbae82cdfa910f1cbbdb87750f8b6fcdc
parente155edd1bdb3c98f240292642c6ee38bf2b1e2cf (diff)
Improve webhook to add a task
-rw-r--r--controllers/task.php12
-rw-r--r--models/board.php6
-rw-r--r--models/project.php5
3 files changed, 21 insertions, 2 deletions
diff --git a/controllers/task.php b/controllers/task.php
index b022f37c..e42d1eec 100644
--- a/controllers/task.php
+++ b/controllers/task.php
@@ -13,15 +13,23 @@ class Task extends Base
$this->response->text('Not Authorized', 401);
}
+ $projectModel = new \Model\Project;
+ $defaultProject = $projectModel->getFirst();
+
$values = array(
'title' => $this->request->getStringParam('title'),
'description' => $this->request->getStringParam('description'),
- 'color_id' => $this->request->getStringParam('color_id'),
- 'project_id' => $this->request->getIntegerParam('project_id'),
+ 'color_id' => $this->request->getStringParam('color_id', 'blue'),
+ 'project_id' => $this->request->getIntegerParam('project_id', $defaultProject['id']),
'owner_id' => $this->request->getIntegerParam('owner_id'),
'column_id' => $this->request->getIntegerParam('column_id'),
);
+ if ($values['column_id'] == 0) {
+ $boardModel = new \Model\Board;
+ $values['column_id'] = $boardModel->getFirstColumn($values['project_id']);
+ }
+
list($valid,) = $this->task->validateCreation($values);
if ($valid && $this->task->create($values)) {
diff --git a/models/board.php b/models/board.php
index 66e6998f..3142a7cc 100644
--- a/models/board.php
+++ b/models/board.php
@@ -88,6 +88,12 @@ class Board extends Base
return $columns;
}
+ // Get first column id for a given project
+ public function getFirstColumn($project_id)
+ {
+ return $this->db->table(self::TABLE)->eq('project_id', $project_id)->asc('position')->findOneColumn('id');
+ }
+
// Get list of columns
public function getColumnsList($project_id)
{
diff --git a/models/project.php b/models/project.php
index 7a0fb2b1..b0c2b2ca 100644
--- a/models/project.php
+++ b/models/project.php
@@ -16,6 +16,11 @@ class Project extends Base
return $this->db->table(self::TABLE)->eq('id', $project_id)->findOne();
}
+ public function getFirst()
+ {
+ return $this->db->table(self::TABLE)->findOne();
+ }
+
public function getAll($fetch_stats = false)
{
if (! $fetch_stats) {