Skip to content

Commit

Permalink
Improve webhook to add a task
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Guillot committed Feb 16, 2014
1 parent e155edd commit c2f8e1c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
12 changes: 10 additions & 2 deletions controllers/task.php
Expand Up @@ -13,15 +13,23 @@ public function add()
$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)) {
Expand Down
6 changes: 6 additions & 0 deletions models/board.php
Expand Up @@ -88,6 +88,12 @@ public function get($project_id)
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)
{
Expand Down
5 changes: 5 additions & 0 deletions models/project.php
Expand Up @@ -16,6 +16,11 @@ public function get($project_id)
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) {
Expand Down

0 comments on commit c2f8e1c

Please sign in to comment.