Add filter tag:none

This commit is contained in:
Frederic Guillot
2016-10-09 20:35:30 -04:00
parent d7e92cf290
commit 71ad04cd66
2 changed files with 52 additions and 6 deletions

View File

@@ -56,12 +56,11 @@ class TaskTagFilter extends BaseFilter implements FilterInterface
*/
public function apply()
{
$task_ids = $this->db
->table(TagModel::TABLE)
->ilike(TagModel::TABLE.'.name', $this->value)
->asc(TagModel::TABLE.'.project_id')
->join(TaskTagModel::TABLE, 'tag_id', 'id')
->findAllByColumn(TaskTagModel::TABLE.'.task_id');
if ($this->value === 'none') {
$task_ids = $this->getTaskIdsWithoutTags();
} else {
$task_ids = $this->getTaskIdsWithGivenTag();
}
if (empty($task_ids)) {
$task_ids = array(-1);
@@ -71,4 +70,24 @@ class TaskTagFilter extends BaseFilter implements FilterInterface
return $this;
}
protected function getTaskIdsWithoutTags()
{
return $this->db
->table(TaskModel::TABLE)
->asc(TaskModel::TABLE . '.project_id')
->left(TaskTagModel::TABLE, 'tg', 'task_id', TaskModel::TABLE, 'id')
->isNull('tg.tag_id')
->findAllByColumn(TaskModel::TABLE . '.id');
}
protected function getTaskIdsWithGivenTag()
{
return $this->db
->table(TagModel::TABLE)
->ilike(TagModel::TABLE.'.name', $this->value)
->asc(TagModel::TABLE.'.project_id')
->join(TaskTagModel::TABLE, 'tag_id', 'id')
->findAllByColumn(TaskTagModel::TABLE.'.task_id');
}
}