From 9d39943bd43e2e0651bda3df7a32940a26f5e8ec Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Mon, 8 Sep 2014 19:40:13 +0200 Subject: Fix bug when moving tasks position in the same column --- app/Model/Task.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/Model/Task.php b/app/Model/Task.php index d326c382..6eb24281 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -560,23 +560,30 @@ class Task extends Base ->eq('project_id', $project_id) ->findAll(); - // We sort everything by column and position $board = $this->board->getColumnsList($project_id); $columns = array(); + $task_id = (int) $task_id; + // Prepare the columns foreach ($board as $board_column_id => $board_column_name) { $columns[$board_column_id] = array(); } + // The column must exists + if (! isset($columns[$column_id])) { + return false; + } + + // Sort everything by column foreach ($tasks as &$task) { if ($task['id'] != $task_id) { $columns[$task['column_id']][$task['position'] - 1] = (int) $task['id']; } } - // The column must exists - if (! isset($columns[$column_id])) { - return false; + // Sort all tasks by position + foreach ($columns as &$column) { + ksort($column); } // We put our task to the new position @@ -601,7 +608,6 @@ class Task extends Base foreach ($columns as $column_id => $column) { $position = 1; - ksort($column); foreach ($column as $task_id) { -- cgit v1.2.3