summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2019-02-08 13:53:13 -0800
committerFrédéric Guillot <fred@kanboard.net>2019-02-08 13:53:13 -0800
commit029538846181309e9135a17f893e874b2e90f72b (patch)
treeb6e19516836c67d35a0ec842d321a7c9213d5952 /app/Model
parentba5878e7869655feda1983967ba80e7c2e811676 (diff)
Add new actions to reorder tasks by column
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/TaskReorderModel.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/app/Model/TaskReorderModel.php b/app/Model/TaskReorderModel.php
new file mode 100644
index 00000000..db72274c
--- /dev/null
+++ b/app/Model/TaskReorderModel.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace Kanboard\Model;
+
+use Kanboard\Core\Base;
+
+class TaskReorderModel extends Base
+{
+ public function reorderByPriority($projectID, $swimlaneID, $columnID, $direction)
+ {
+ $this->db->startTransaction();
+
+ $taskIDs = $this->db->table(TaskModel::TABLE)
+ ->eq('project_id', $projectID)
+ ->eq('swimlane_id', $swimlaneID)
+ ->eq('column_id', $columnID)
+ ->orderBy('priority', $direction)
+ ->asc('id')
+ ->findAllByColumn('id');
+
+ $this->reorderTasks($taskIDs);
+
+ $this->db->closeTransaction();
+ }
+
+ public function reorderByAssigneeAndPriority($projectID, $swimlaneID, $columnID, $direction)
+ {
+ $this->db->startTransaction();
+
+ $taskIDs = $this->db->table(TaskModel::TABLE)
+ ->eq('tasks.project_id', $projectID)
+ ->eq('tasks.swimlane_id', $swimlaneID)
+ ->eq('tasks.column_id', $columnID)
+ ->asc('u.name')
+ ->asc('u.username')
+ ->orderBy('tasks.priority', $direction)
+ ->left(UserModel::TABLE, 'u', 'id', TaskModel::TABLE, 'owner_id')
+ ->findAllByColumn('tasks.id');
+
+ $this->reorderTasks($taskIDs);
+
+ $this->db->closeTransaction();
+ }
+
+ public function reorderByAssignee($projectID, $swimlaneID, $columnID, $direction)
+ {
+ $this->db->startTransaction();
+
+ $taskIDs = $this->db->table(TaskModel::TABLE)
+ ->eq('tasks.project_id', $projectID)
+ ->eq('tasks.swimlane_id', $swimlaneID)
+ ->eq('tasks.column_id', $columnID)
+ ->orderBy('u.name', $direction)
+ ->orderBy('u.username', $direction)
+ ->orderBy('u.id', $direction)
+ ->left(UserModel::TABLE, 'u', 'id', TaskModel::TABLE, 'owner_id')
+ ->findAllByColumn('tasks.id');
+
+ $this->reorderTasks($taskIDs);
+
+ $this->db->closeTransaction();
+ }
+
+ protected function reorderTasks(array $taskIDs)
+ {
+ $i = 1;
+ foreach ($taskIDs as $taskID) {
+ $this->db->table(TaskModel::TABLE)
+ ->eq('id', $taskID)
+ ->update(['position' => $i]);
+ $i++;
+ }
+ }
+}