From b8fa0246803dab40cf57d40b45984c53046f2d55 Mon Sep 17 00:00:00 2001 From: "Dzial Techniczny WMW Projekt s.c" Date: Tue, 10 Dec 2019 11:34:53 +0100 Subject: Plugins directory and local modifications --- .../Filter/AdvancedSearchFilter.php | 198 +++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 plugins/KanboardSearchPlugin/Filter/AdvancedSearchFilter.php (limited to 'plugins/KanboardSearchPlugin/Filter') diff --git a/plugins/KanboardSearchPlugin/Filter/AdvancedSearchFilter.php b/plugins/KanboardSearchPlugin/Filter/AdvancedSearchFilter.php new file mode 100644 index 00000000..5809d37f --- /dev/null +++ b/plugins/KanboardSearchPlugin/Filter/AdvancedSearchFilter.php @@ -0,0 +1,198 @@ +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(); + } +} \ No newline at end of file -- cgit v1.2.3