Added filter class for tags
This commit is contained in:
74
app/Filter/TaskTagFilter.php
Normal file
74
app/Filter/TaskTagFilter.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Filter;
|
||||
|
||||
use Kanboard\Core\Filter\FilterInterface;
|
||||
use Kanboard\Model\TagModel;
|
||||
use Kanboard\Model\TaskModel;
|
||||
use Kanboard\Model\TaskTagModel;
|
||||
use PicoDb\Database;
|
||||
|
||||
/**
|
||||
* Class TaskTagFilter
|
||||
*
|
||||
* @package Kanboard\Filter
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskTagFilter extends BaseFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* Database object
|
||||
*
|
||||
* @access private
|
||||
* @var Database
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* Get search attribute
|
||||
*
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return array('tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set database object
|
||||
*
|
||||
* @access public
|
||||
* @param Database $db
|
||||
* @return $this
|
||||
*/
|
||||
public function setDatabase(Database $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply filter
|
||||
*
|
||||
* @access public
|
||||
* @return 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 (empty($task_ids)) {
|
||||
$task_ids = array(-1);
|
||||
}
|
||||
|
||||
$this->query->in(TaskModel::TABLE.'.id', $task_ids);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -74,9 +74,9 @@ class TaskTagModel extends Base
|
||||
* Add or update a list of tags to a task
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @param integer $task_id
|
||||
* @param string[] $tags
|
||||
* @param integer $project_id
|
||||
* @param integer $task_id
|
||||
* @param string[] $tags
|
||||
* @return boolean
|
||||
*/
|
||||
public function save($project_id, $task_id, array $tags)
|
||||
@@ -123,10 +123,10 @@ class TaskTagModel extends Base
|
||||
* Associate missing tags
|
||||
*
|
||||
* @access protected
|
||||
* @param integer $project_id
|
||||
* @param integer $task_id
|
||||
* @param array $task_tags
|
||||
* @param array $tags
|
||||
* @param integer $project_id
|
||||
* @param integer $task_id
|
||||
* @param array $task_tags
|
||||
* @param string[] $tags
|
||||
* @return bool
|
||||
*/
|
||||
protected function associateTags($project_id, $task_id, $task_tags, $tags)
|
||||
@@ -146,9 +146,9 @@ class TaskTagModel extends Base
|
||||
* Dissociate removed tags
|
||||
*
|
||||
* @access protected
|
||||
* @param integer $task_id
|
||||
* @param array $task_tags
|
||||
* @param array $tags
|
||||
* @param integer $task_id
|
||||
* @param array $task_tags
|
||||
* @param string[] $tags
|
||||
* @return bool
|
||||
*/
|
||||
protected function dissociateTags($task_id, $task_tags, $tags)
|
||||
|
||||
@@ -26,6 +26,7 @@ use Kanboard\Filter\TaskReferenceFilter;
|
||||
use Kanboard\Filter\TaskStatusFilter;
|
||||
use Kanboard\Filter\TaskSubtaskAssigneeFilter;
|
||||
use Kanboard\Filter\TaskSwimlaneFilter;
|
||||
use Kanboard\Filter\TaskTagFilter;
|
||||
use Kanboard\Filter\TaskTitleFilter;
|
||||
use Kanboard\Model\ProjectModel;
|
||||
use Kanboard\Model\ProjectGroupRoleModel;
|
||||
@@ -163,6 +164,9 @@ class FilterProvider implements ServiceProviderInterface
|
||||
->setDatabase($c['db'])
|
||||
)
|
||||
->withFilter(new TaskSwimlaneFilter())
|
||||
->withFilter(TaskTagFilter::getInstance()
|
||||
->setDatabase($c['db'])
|
||||
)
|
||||
->withFilter(new TaskTitleFilter(), true)
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user