summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Model/TaskFilter.php81
-rw-r--r--docs/search.markdown15
-rw-r--r--tests/units/TaskFilterTest.php35
3 files changed, 88 insertions, 43 deletions
diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php
index d7d5148b..0dbadbf8 100644
--- a/app/Model/TaskFilter.php
+++ b/app/Model/TaskFilter.php
@@ -104,6 +104,25 @@ class TaskFilter extends Base
}
/**
+ * Create a new subtask query
+ *
+ * @access public
+ * @return \PicoDb\Table
+ */
+ public function createSubtaskQuery()
+ {
+ 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)
+ ->neq(Subtask::TABLE.'.status', Subtask::STATUS_DONE);
+ }
+
+ /**
* Clone the filter
*
* @access public
@@ -340,11 +359,9 @@ 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);
@@ -352,18 +369,43 @@ 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();
- $this->addTasksWithFoundSubtask($subtasks);
}
}
+ $this->filterBySubtaskAssignee($values);
+
$this->query->closeOr();
+
+ return $this;
+ }
+
+ /**
+ * Filter by subtask assignee names
+ *
+ * @access public
+ * @param array $values List of assignees
+ * @return TaskFilter
+ */
+ public function filterBySubtaskAssignee(array $values)
+ {
+ $subtaskQuery = $this->createSubtaskQuery();
+ $subtaskQuery->beginOr();
+
+ foreach ($values as $assignee) {
+ if ($assignee === 'me') {
+ $subtaskQuery->eq(Subtask::TABLE.'.user_id', $this->userSession->getId());
+ }
+ else {
+ $subtaskQuery->ilike(User::TABLE.'.username', '%'.$assignee.'%');
+ $subtaskQuery->ilike(User::TABLE.'.name', '%'.$assignee.'%');
+ }
+ }
+
+ $subtaskQuery->closeOr();
+
+ $this->query->in(Task::TABLE.'.id', $subtaskQuery->findAllByColumn('task_id'));
+
+ return $this;
}
/**
@@ -796,23 +838,4 @@ 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)
- ->neq(Subtask::TABLE.'.status', Subtask::STATUS_DONE);
-
- }
-
- private function addTasksWithFoundSubtask($subtasks) {
- foreach ($subtasks as $subtask) {
- $this->query->eq(Task::TABLE.'.id',$subtask['task_id']);
- }
- }
-
}
diff --git a/docs/search.markdown b/docs/search.markdown
index d0e71203..4674a07e 100644
--- a/docs/search.markdown
+++ b/docs/search.markdown
@@ -63,6 +63,8 @@ Query for my assigned tasks
assignee:me
```
+Note: Results will also include subtasks assignee with the status todo or in progress.
+
Search by color
---------------
@@ -125,6 +127,13 @@ Attribute: **description**
Example: `description:"text search"`
+Search by external reference
+----------------------------
+
+The task reference is an external id of your task, by example a ticket number from another software.
+
+- Find tasks with a reference: `ref:1234` or `reference:TICKET-1234`
+
Search by category
------------------
@@ -160,9 +169,3 @@ Attribute: **swimlane**
- Find tasks in the default swimlane: `swimlane:default`
- Find tasks into several swimlanes: `swimlane:"Version 1.2" swimlane:"Version 1.3"`
-Search by external reference
-----------------------------
-
-The task reference is an external id of your task, by example a ticket number from another software.
-
-- Find tasks with a reference: `ref:1234` or `reference:TICKET-1234`
diff --git a/tests/units/TaskFilterTest.php b/tests/units/TaskFilterTest.php
index cf65198c..47fe4e35 100644
--- a/tests/units/TaskFilterTest.php
+++ b/tests/units/TaskFilterTest.php
@@ -539,23 +539,42 @@ class TaskFilterTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test')));
$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)));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #1', 'task_id' => 2, 'status' => 1, 'another_subtask' => 'on', 'user_id' => 2)));
+
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'task1', 'owner_id' => 2)));
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'status' => 1, 'user_id' => 0)));
+
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'task2', 'owner_id' => 0)));
+ $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 2, 'status' => 1, 'user_id' => 2)));
+
+ $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'task3', 'owner_id' => 0)));
+ $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 3, 'user_id' => 1)));
$tf->search('assignee:bob');
$tasks = $tf->findAll();
$this->assertNotEmpty($tasks);
$this->assertCount(2, $tasks);
- $this->assertEquals('my task title is awesome', $tasks[0]['title']);
- $this->assertEquals('my task title is amazing', $tasks[1]['title']);
-
+ $this->assertEquals('task1', $tasks[0]['title']);
+ $this->assertEquals('task2', $tasks[1]['title']);
+
+ $tf->search('assignee:"Paul Ryan"');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('task1', $tasks[0]['title']);
+ $this->assertEquals('task2', $tasks[1]['title']);
+
$tf->search('assignee:nobody');
$tasks = $tf->findAll();
$this->assertNotEmpty($tasks);
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('task2', $tasks[0]['title']);
+ $this->assertEquals('task3', $tasks[1]['title']);
+
+ $tf->search('assignee:admin');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
$this->assertCount(1, $tasks);
- $this->assertEquals('my task title is amazing', $tasks[0]['title']);
+ $this->assertEquals('task3', $tasks[0]['title']);
}
public function testCopy()