Add category attribute for advanced search

This commit is contained in:
Frederic Guillot
2015-06-28 21:53:50 -04:00
parent 7c1222fc59
commit 3f084916e3
7 changed files with 110 additions and 21 deletions

View File

@@ -45,12 +45,8 @@ class Projectinfo extends Base
->setDirection('DESC');
if ($search !== '') {
// $paginator
// ->setQuery($this->taskFinder->getSearchQuery($project['id'], $search))
// ->calculate();
$paginator->setQuery($this->taskFilter->search($search)->filterByProject($project['id'])->getQuery())->calculate();
$paginator->setQuery($this->taskFilter->search($search)->filterByProject($project['id'])->getQuery())
->calculate();
$nb_tasks = $paginator->getTotal();
}

View File

@@ -30,6 +30,7 @@ class Lexer
"/^(due:)/" => 'T_DUE',
"/^(status:)/" => 'T_STATUS',
"/^(description:)/" => 'T_DESCRIPTION',
"/^(category:)/" => 'T_CATEGORY',
"/^(\s+)/" => 'T_WHITESPACE',
'/^([<=>]{0,2}[0-9]{4}-[0-9]{2}-[0-9]{2})/' => 'T_DATE',
'/^(yesterday|tomorrow|today)/' => 'T_DATE',
@@ -107,6 +108,7 @@ class Lexer
switch ($token['token']) {
case 'T_ASSIGNEE':
case 'T_COLOR':
case 'T_CATEGORY':
$next = next($tokens);
if ($next !== false && $next['token'] === 'T_STRING') {

View File

@@ -59,6 +59,9 @@ class TaskFilter extends Base
case 'T_DESCRIPTION':
$this->filterByDescription($value);
break;
case 'T_CATEGORY':
$this->filterByCategoryName($value);
break;
}
}
@@ -202,6 +205,30 @@ class TaskFilter extends Base
return $this;
}
/**
* Filter by category
*
* @access public
* @param array $values List of assignees
* @return TaskFilter
*/
public function filterByCategoryName(array $values)
{
$this->query->join(Category::TABLE, 'id', 'category_id');
$this->query->beginOr();
foreach ($values as $category) {
if ($category === 'none') {
$this->query->eq(Task::TABLE.'.category_id', 0);
}
else {
$this->query->eq(Category::TABLE.'.name', $category);
}
}
$this->query->closeOr();
}
/**
* Filter by assignee
*

View File

@@ -26,21 +26,6 @@ class TaskFinder extends Base
->eq('is_active', Task::STATUS_CLOSED);
}
/**
* Get query for task search
*
* @access public
* @param integer $project_id Project id
* @param string $search Search terms
* @return \PicoDb\Table
*/
public function getSearchQuery($project_id, $search)
{
return $this->getExtendedQuery()
->eq('project_id', $project_id)
->ilike('title', '%'.$search.'%');
}
/**
* Get query for assigned user tasks
*