diff options
author | Lesstat <florianbarth@gmx.de> | 2015-07-11 11:38:04 +0200 |
---|---|---|
committer | Lesstat <florianbarth@gmx.de> | 2015-07-11 11:38:04 +0200 |
commit | 5101eaa8060ce3c75a81a26f6e47aae40e3d4ac3 (patch) | |
tree | cdd9fb31e9dbcf030ce2439de7078ddc9f555f66 /app/Model | |
parent | e7b967d7432267d48e54d7775d0baf1e411178e7 (diff) |
Included Subtask when filtering Tasks by Assignee
I wrote some unit test specifing the behaviour.
I think only Substask with a Status != Done and an assigned user should be taken into account. The search for "nobody" should not reveal tasks with assigned users when these tasks have a subtask without an user.
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/TaskFilter.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php index c88be830..6cf10a17 100644 --- a/app/Model/TaskFilter.php +++ b/app/Model/TaskFilter.php @@ -313,10 +313,11 @@ class TaskFilter extends Base $this->query->beginOr(); foreach ($values as $assignee) { - + $subtaskQuery = $this->buildSubtaskQuery(); switch ($assignee) { case 'me': $this->query->eq(Task::TABLE.'.owner_id', $this->userSession->getId()); + $subtaskQuery->eq(Subtask::TABLE.'user_id',$this->userSession->getId() ); break; case 'nobody': $this->query->eq(Task::TABLE.'.owner_id', 0); @@ -324,6 +325,12 @@ class TaskFilter extends Base default: $this->query->ilike(User::TABLE.'.username', '%'.$assignee.'%'); $this->query->ilike(User::TABLE.'.name', '%'.$assignee.'%'); + $subtaskQuery->ilike(User::TABLE.'.username', '%'.$assignee.'%'); + $subtaskQuery->ilike(User::TABLE.'.name', '%'.$assignee.'%'); + } + if ($assignee != 'nobody'){ + $subtasks = $subtaskQuery->findAll(); + $this->addTasksWithFoundSubtask($subtasks); } } @@ -760,4 +767,25 @@ class TaskFilter extends Base return $this; } + + private function buildSubtaskQuery(){ + return $this->db->table(Subtask::TABLE) + ->columns( + Subtask::TABLE.'.user_id', + Subtask::TABLE.'.task_id', + User::TABLE.'.name', + User::TABLE.'.username') + ->join(User::TABLE, 'id', 'user_id', Subtask::TABLE) + ->beginOr() + ->eq(Subtask::TABLE.'.status', Subtask::STATUS_TODO) + ->eq(Subtask::TABLE.'.status', Subtask::STATUS_INPROGRESS) + ->closeOr(); + } + + private function addTasksWithFoundSubtask($subtasks) { + foreach ($subtasks as $subtask) { + $this->query->eq(Task::TABLE.'.id',$subtask['task_id']); + } + } + } |