diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-06-24 11:40:58 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-06-24 11:40:58 -0400 |
commit | b2e92480c29acb15586bc8ea305c8416927a667c (patch) | |
tree | 3a81aaac07b88a4af08795203e997b04d50a96c6 /app/Filter | |
parent | 700b4e8f0265e4eabd7a7c0eb6a06088d50554fe (diff) |
Added filter class for tags
Diffstat (limited to 'app/Filter')
-rw-r--r-- | app/Filter/TaskTagFilter.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/app/Filter/TaskTagFilter.php b/app/Filter/TaskTagFilter.php new file mode 100644 index 00000000..01b6f625 --- /dev/null +++ b/app/Filter/TaskTagFilter.php @@ -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; + } +} |