diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | app/Filter/TaskReferenceFilter.php | 5 | ||||
-rw-r--r-- | doc/en_US/search.markdown | 1 | ||||
-rw-r--r-- | doc/tr_TR/search.markdown | 1 | ||||
-rw-r--r-- | tests/units/Filter/TaskReferenceFilterTest.php | 65 |
5 files changed, 73 insertions, 0 deletions
@@ -3,6 +3,7 @@ Version 1.0.44 (unreleased) Improvements: +* Add wildcard search for task reference field * Improve automated action TaskAssignColorOnDueDate to update task only when necessary Version 1.0.43 (April 30, 2017) diff --git a/app/Filter/TaskReferenceFilter.php b/app/Filter/TaskReferenceFilter.php index 27c838f8..d843b777 100644 --- a/app/Filter/TaskReferenceFilter.php +++ b/app/Filter/TaskReferenceFilter.php @@ -32,6 +32,11 @@ class TaskReferenceFilter extends BaseFilter implements FilterInterface */ public function apply() { + if (strpos($this->value, '*') >= 0) { + $this->query->like(TaskModel::TABLE.'.reference', str_replace('*', '%', $this->value)); + return $this; + } + $this->query->eq(TaskModel::TABLE.'.reference', $this->value); return $this; } diff --git a/doc/en_US/search.markdown b/doc/en_US/search.markdown index fefbe095..befb0e5c 100644 --- a/doc/en_US/search.markdown +++ b/doc/en_US/search.markdown @@ -115,6 +115,7 @@ Attribute: **completed** 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` +- Wildcard search: `ref:TICKET-*` ### Search by category diff --git a/doc/tr_TR/search.markdown b/doc/tr_TR/search.markdown index c7bac5e6..1ddc26d1 100644 --- a/doc/tr_TR/search.markdown +++ b/doc/tr_TR/search.markdown @@ -111,6 +111,7 @@ Değiştirme tarihi sorguları aynı şekilde çalışır. Görev referansı, görevinizin harici bir kimliği, örneğin başka bir yazılımdan gelen bir bilet numarasıdır. - Görevleri referans ile bulun: `ref:1234` veya `reference:TICKET-1234` +- Wildcard search: `ref:TICKET-*` ### Kategoriye göre ara diff --git a/tests/units/Filter/TaskReferenceFilterTest.php b/tests/units/Filter/TaskReferenceFilterTest.php new file mode 100644 index 00000000..49a86454 --- /dev/null +++ b/tests/units/Filter/TaskReferenceFilterTest.php @@ -0,0 +1,65 @@ +<?php + +use Kanboard\Filter\TaskReferenceFilter; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; + +require_once __DIR__.'/../Base.php'; + +class TaskReferenceFilterTest extends Base +{ + public function testWithoutMatch() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + + $filter = new TaskReferenceFilter(); + $filter->withQuery($query); + $filter->withValue('aaa-bbb'); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithExactMatch() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'reference' => 'aaa-bbb'))); + + $filter = new TaskReferenceFilter(); + $filter->withQuery($query); + $filter->withValue('aaa-bbb'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + } + + public function testWithWildCard() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'reference' => 'aaa-bbb'))); + + $filter = new TaskReferenceFilter(); + $filter->withQuery($query); + $filter->withValue('aaa-*'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + } +} |