db = $db; return $this; } /** * Set configModel object * * @access public * @param ConfigModel $config * @return AdvancedSearchFilter */ public function setConfigModel(ConfigModel $config) { $this->config = $config; return $this; } /** * Set TaskFileModel object * * @access public * @param TaskFileModel $file * @return AdvancedSearchFilter */ public function setFileModel(TaskFileModel $file) { $this->file = $file; return $this; } /** * Get search attribute * * @access public * @return string[] */ public function getAttributes() { return array('title', 'comment', 'description', 'desc'); } /** * Apply filter * * @access public * @return string */ public function apply() { $commentTaskIds = $this->getTaskIdsWithGivenComment(); $titlesTaskIds = $this->getTaskIdsWithGivenTitles(); $descriptionTaskIds = $this->getTaskIdsWithGivenDescription(); $subtaskTitlesIds = $this->getTaskIdsWithGivenSubtaskTitles(); $attachmentIds = $this->getTaskIdsWithGivenAttachmentName(); $task_ids = array_merge($commentTaskIds, $titlesTaskIds, $descriptionTaskIds, $subtaskTitlesIds, $attachmentIds); if (empty($task_ids)) { $task_ids = array(-1); } $this->query->in(TaskModel::TABLE . '.id', $task_ids); return $this; } /** * Get task ids having this comment * * @access public * @return array */ protected function getTaskIdsWithGivenComment() { if($this->config->get('comment_search') == 1) { return $this->db ->table(CommentModel::TABLE) ->ilike(CommentModel::TABLE . '.comment', '%' . $this->value . '%') ->findAllByColumn(CommentModel::TABLE . '.task_id'); } return array(); } /** * Get task ids having this description * * @access public * @return array */ protected function getTaskIdsWithGivenDescription() { if($this->config->get('description_search') == 1) { return $this->db ->table(TaskModel::TABLE) ->ilike(TaskModel::TABLE . '.description', '%' . $this->value . '%') ->findAllByColumn(TaskModel::TABLE . '.id'); } return array(); } /** * Get task ids having this title * * @access public * @return array */ private function getTaskIdsWithGivenTitles() { if($this->config->get('title_search') == 1) { return $this->db ->table(TaskModel::TABLE) ->ilike(TaskModel::TABLE . '.title', '%' . $this->value . '%') ->findAllByColumn(TaskModel::TABLE . '.id'); } return array(); } /** * Get task ids having this Subtask title * * @access public * @return array */ private function getTaskIdsWithGivenSubtaskTitles() { if($this->config->get('subtask_search') == 1) { return $this->db ->table(SubtaskModel::TABLE) ->ilike(SubtaskModel::TABLE . '.title', '%' . $this->value . '%') ->findAllByColumn(SubtaskModel::TABLE . '.task_id'); } return array(); } /** * Get task ids having this Attachment Name * * @access public * @return array */ private function getTaskIdsWithGivenAttachmentName() { if($this->config->get('attachment_search') == 1) { return $this->db ->table(TaskFileModel::TABLE) ->ilike(TaskFileModel::TABLE . '.name', '%' . $this->value . '%') ->findAllByColumn(TaskFileModel::TABLE . '.task_id'); } return array(); } }