Add search attribute to search by reference

This commit is contained in:
Frederic Guillot 2015-07-04 17:35:52 -04:00
parent 0e5756ecc1
commit 198f3eda90
5 changed files with 90 additions and 0 deletions

View File

@ -33,6 +33,8 @@ class Lexer
"/^(category:)/" => 'T_CATEGORY',
"/^(column:)/" => 'T_COLUMN',
"/^(project:)/" => 'T_PROJECT',
"/^(ref:)/" => 'T_REFERENCE',
"/^(reference:)/" => 'T_REFERENCE',
"/^(\s+)/" => 'T_WHITESPACE',
'/^([<=>]{0,2}[0-9]{4}-[0-9]{2}-[0-9]{2})/' => 'T_DATE',
'/^(yesterday|tomorrow|today)/' => 'T_DATE',
@ -124,6 +126,7 @@ class Lexer
case 'T_STATUS':
case 'T_DUE':
case 'T_DESCRIPTION':
case 'T_REFERENCE':
$next = next($tokens);
if ($next !== false && ($next['token'] === 'T_DATE' || $next['token'] === 'T_STRING')) {

View File

@ -68,6 +68,9 @@ class TaskFilter extends Base
case 'T_COLUMN':
$this->filterByColumnName($value);
break;
case 'T_REFERENCE':
$this->filterByReference($value);
break;
}
}
@ -140,6 +143,22 @@ class TaskFilter extends Base
return $this;
}
/**
* Filter by reference
*
* @access public
* @param string $reference
* @return TaskFilter
*/
public function filterByReference($reference)
{
if (! empty($reference)) {
$this->query->eq(Task::TABLE.'.reference', $reference);
}
return $this;
}
/**
* Filter by title
*

View File

@ -144,3 +144,10 @@ Attribute: **column**
- Find tasks by column name: `column:"Work in progress"`
- Find tasks for several columns: `column:"Backlog" column:ready`
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`

View File

@ -171,6 +171,36 @@ class LexerTest extends Base
);
}
public function testReferenceQuery()
{
$lexer = new Lexer;
$this->assertEquals(
array(array('match' => 'ref:', 'token' => 'T_REFERENCE'), array('match' => '123', 'token' => 'T_STRING')),
$lexer->tokenize('ref:123')
);
$this->assertEquals(
array(array('match' => 'reference:', 'token' => 'T_REFERENCE'), array('match' => '456', 'token' => 'T_STRING')),
$lexer->tokenize('reference:456')
);
$this->assertEquals(
array('T_REFERENCE' => '123'),
$lexer->map($lexer->tokenize('reference:123'))
);
$this->assertEquals(
array('T_REFERENCE' => '456'),
$lexer->map($lexer->tokenize('ref:456'))
);
$this->assertEquals(
array(),
$lexer->map($lexer->tokenize('ref: '))
);
}
public function testDescriptionQuery()
{
$lexer = new Lexer;

View File

@ -27,6 +27,37 @@ class TaskFilterTest extends Base
$this->assertEmpty($tf->search('search something')->findAll());
}
public function testSearchWithReference()
{
$p = new Project($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFilter($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
$this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'reference' => 123)));
$tf->search('ref:123');
$tasks = $tf->findAll();
$this->assertNotEmpty($tasks);
$this->assertCount(1, $tasks);
$this->assertEquals('task2', $tasks[0]['title']);
$tf->search('reference:123');
$tasks = $tf->findAll();
$this->assertNotEmpty($tasks);
$this->assertCount(1, $tasks);
$this->assertEquals('task2', $tasks[0]['title']);
$tf->search('ref:plop');
$tasks = $tf->findAll();
$this->assertEmpty($tasks);
$tf->search('ref:');
$tasks = $tf->findAll();
$this->assertEmpty($tasks);
}
public function testSearchWithStatus()
{
$p = new Project($this->container);