db = $db; return $this; } /** * Apply filter * * @access public * @return FilterInterface */ public function apply() { if ($this->value === 'none') { $sub_query = $this->getQueryOfTaskIdsWithoutTags(); } else { $sub_query = $this->getQueryOfTaskIdsWithGivenTag(); } $this->query->inSubquery(TaskModel::TABLE.'.id', $sub_query); return $this; } protected function getQueryOfTaskIdsWithoutTags() { return $this->db ->table(TaskModel::TABLE) ->columns(TaskModel::TABLE . '.id') ->left(TaskTagModel::TABLE, 'tg', 'task_id', TaskModel::TABLE, 'id') ->isNull('tg.tag_id'); } protected function getQueryOfTaskIdsWithGivenTag() { return $this->db ->table(TagModel::TABLE) ->columns(TaskTagModel::TABLE.'.task_id') ->ilike(TagModel::TABLE.'.name', '%'.$this->value.'%') ->join(TaskTagModel::TABLE, 'tag_id', 'id'); } }