summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-09-17 14:47:41 +0200
committerFrédéric Guillot <fred@kanboard.net>2014-09-17 14:47:41 +0200
commit243e72474bd0c87b8647efe1edeb1116a0a5fcd0 (patch)
tree11630e7879c012f64c8b457e37110ada67c10e83 /app
parente7a20b9d8f8d7c47173c59782c5bd24a0ba6cac9 (diff)
Improve board API calls
Diffstat (limited to 'app')
-rw-r--r--app/Controller/Board.php2
-rw-r--r--app/Model/Board.php43
2 files changed, 28 insertions, 17 deletions
diff --git a/app/Controller/Board.php b/app/Controller/Board.php
index 2ee43c76..f643408d 100644
--- a/app/Controller/Board.php
+++ b/app/Controller/Board.php
@@ -328,7 +328,7 @@ class Board extends Base
if ($valid) {
- if ($this->board->add($data)) {
+ if ($this->board->addColumn($project['id'], $data['title'])) {
$this->session->flash(t('Board updated successfully.'));
$this->response->redirect('?controller=board&action=edit&project_id='.$project['id']);
}
diff --git a/app/Model/Board.php b/app/Model/Board.php
index f8df4069..ac9cbdf9 100644
--- a/app/Model/Board.php
+++ b/app/Model/Board.php
@@ -83,13 +83,19 @@ class Board extends Base
* Add a new column to the board
*
* @access public
- * @param array $values ['title' => X, 'project_id' => X]
+ * @param integer $project_id Project id
+ * @param string $title Column title
+ * @param integer $task_limit Task limit
* @return boolean
*/
- public function add(array $values)
+ public function addColumn($project_id, $title, $task_limit = 0)
{
- $values['position'] = $this->getLastColumnPosition($values['project_id']) + 1;
- return $this->db->table(self::TABLE)->save($values);
+ return $this->db->table(self::TABLE)->save(array(
+ 'project_id' => $project_id,
+ 'title' => $title,
+ 'task_limit' => $task_limit,
+ 'position' => $this->getLastColumnPosition($project_id) + 1,
+ ));
}
/**
@@ -101,17 +107,18 @@ class Board extends Base
*/
public function update(array $values)
{
- $this->db->startTransaction();
+ $columns = array();
foreach (array('title', 'task_limit') as $field) {
- foreach ($values[$field] as $column_id => $field_value) {
+ foreach ($values[$field] as $column_id => $value) {
+ $columns[$column_id][$field] = $value;
+ }
+ }
- if ($field === 'task_limit' && empty($field_value)) {
- $field_value = 0;
- }
+ $this->db->startTransaction();
- $this->updateColumn($column_id, array($field => $field_value));
- }
+ foreach ($columns as $column_id => $values) {
+ $this->updateColumn($column_id, $values['title'], (int) $values['task_limit']);
}
$this->db->closeTransaction();
@@ -123,13 +130,17 @@ class Board extends Base
* Update a column
*
* @access public
- * @param integer $column_id Column id
- * @param array $values Form values
+ * @param integer $column_id Column id
+ * @param string $title Column title
+ * @param integer $task_limit Task limit
* @return boolean
*/
- public function updateColumn($column_id, array $values)
+ public function updateColumn($column_id, $title, $task_limit = 0)
{
- return $this->db->table(self::TABLE)->eq('id', $column_id)->update($values);
+ return $this->db->table(self::TABLE)->eq('id', $column_id)->update(array(
+ 'title' => $title,
+ 'task_limit' => $task_limit,
+ ));
}
/**
@@ -195,7 +206,7 @@ class Board extends Base
*
* @access public
* @param integer $project_id Project id
- * @param array $filters
+ * @param array $filters
* @return array
*/
public function get($project_id, array $filters = array())