Add filter tag:none
This commit is contained in:
parent
d7e92cf290
commit
71ad04cd66
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,4 +119,31 @@ class TaskTagFilterTest extends Base
|
|||
$this->assertEquals('test1', $tasks[0]['title']);
|
||||
$this->assertEquals('test2', $tasks[1]['title']);
|
||||
}
|
||||
|
||||
public function testWithNone()
|
||||
{
|
||||
$taskFinderModel = new TaskFinderModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$taskTagModel = new TaskTagModel($this->container);
|
||||
$query = $taskFinderModel->getExtendedQuery();
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
|
||||
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
|
||||
$this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
|
||||
|
||||
$this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
|
||||
$this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
|
||||
|
||||
$filter = new TaskTagFilter();
|
||||
$filter->setDatabase($this->container['db']);
|
||||
$filter->withQuery($query);
|
||||
$filter->withValue('none');
|
||||
$filter->apply();
|
||||
|
||||
$tasks = $query->findAll();
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('test3', $tasks[0]['title']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue