From 5101eaa8060ce3c75a81a26f6e47aae40e3d4ac3 Mon Sep 17 00:00:00 2001 From: Lesstat Date: Sat, 11 Jul 2015 11:38:04 +0200 Subject: 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. --- app/Model/TaskFilter.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'app/Model/TaskFilter.php') 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']); + } + } + } -- cgit v1.2.3 From 0f2d57ca5b00fb58e5b3baadb64fcd011c666ff6 Mon Sep 17 00:00:00 2001 From: Lesstat Date: Sun, 12 Jul 2015 09:52:44 +0200 Subject: Corrected some SQL Spelling Erorrs --- app/Model/TaskFilter.php | 10 +++++----- tests/units/TaskFilterTest.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'app/Model/TaskFilter.php') diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php index dfd97d9d..8d7bdb44 100644 --- a/app/Model/TaskFilter.php +++ b/app/Model/TaskFilter.php @@ -317,7 +317,7 @@ class TaskFilter extends Base switch ($assignee) { case 'me': $this->query->eq(Task::TABLE.'.owner_id', $this->userSession->getId()); - $subtaskQuery->eq(Subtask::TABLE.'user_id',$this->userSession->getId() ); + $subtaskQuery->eq(Subtask::TABLE.'.user_id',$this->userSession->getId() ); break; case 'nobody': $this->query->eq(Task::TABLE.'.owner_id', 0); @@ -325,8 +325,10 @@ class TaskFilter extends Base default: $this->query->ilike(User::TABLE.'.username', '%'.$assignee.'%'); $this->query->ilike(User::TABLE.'.name', '%'.$assignee.'%'); + $subtaskQuery->beginOr(); $subtaskQuery->ilike(User::TABLE.'.username', '%'.$assignee.'%'); $subtaskQuery->ilike(User::TABLE.'.name', '%'.$assignee.'%'); + $subtaskQuery->closeOr(); } if ($assignee != 'nobody'){ $subtasks = $subtaskQuery->findAll(); @@ -776,10 +778,8 @@ class TaskFilter extends Base 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(); + ->neq(Subtask::TABLE.'.status', Subtask::STATUS_DONE); + } private function addTasksWithFoundSubtask($subtasks) { diff --git a/tests/units/TaskFilterTest.php b/tests/units/TaskFilterTest.php index 98142ec7..fede157e 100644 --- a/tests/units/TaskFilterTest.php +++ b/tests/units/TaskFilterTest.php @@ -479,7 +479,7 @@ class TaskFilterTest extends Base $tf = new TaskFilter($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan'))); + $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Paul Ryan'))); $this->assertEquals(1,$tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'owner_id' => 2))); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'status' => 1, 'another_subtask' => 'on', 'user_id' => 0))); $this->assertEquals(2,$tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'owner_id' => 0))); -- cgit v1.2.3