From 029538846181309e9135a17f893e874b2e90f72b Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Fri, 8 Feb 2019 13:53:13 -0800 Subject: Add new actions to reorder tasks by column --- app/Model/TaskReorderModel.php | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 app/Model/TaskReorderModel.php (limited to 'app/Model/TaskReorderModel.php') 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 @@ +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++; + } + } +} -- cgit v1.2.3