summaryrefslogtreecommitdiff
path: root/plugins/KanboardSearchPlugin/Filter
diff options
context:
space:
mode:
authorDzial Techniczny WMW Projekt s.c <techniczna@wmwprojekt.pl>2019-12-10 11:34:53 +0100
committerDzial Techniczny WMW Projekt s.c <techniczna@wmwprojekt.pl>2019-12-10 11:34:53 +0100
commitb8fa0246803dab40cf57d40b45984c53046f2d55 (patch)
treedc92b167c7542137c385614a1d558e57669a4339 /plugins/KanboardSearchPlugin/Filter
parent2a43146236fd8fb16f84398d85720ad84aa0a0b1 (diff)
Plugins directory and local modifications
Diffstat (limited to 'plugins/KanboardSearchPlugin/Filter')
-rw-r--r--plugins/KanboardSearchPlugin/Filter/AdvancedSearchFilter.php198
1 files changed, 198 insertions, 0 deletions
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 @@
+<?php
+
+namespace Kanboard\Plugin\KanboardSearchPlugin\Filter;
+
+use Kanboard\Core\Filter\FilterInterface;
+use Kanboard\Filter\BaseFilter;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\TaskFileModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\ConfigModel;
+use PicoDb\Database;
+
+
+class AdvancedSearchFilter extends BaseFilter implements FilterInterface
+{
+
+ /**
+ * Database object
+ *
+ * @access private
+ * @var Database
+ */
+ private $db;
+
+ /**
+ * @var ConfigModel
+ */
+ private $config;
+
+ /**
+ * @var TaskFileModel
+ */
+ private $file;
+
+ /**
+ * Set database object
+ *
+ * @access public
+ * @param Database $db
+ * @return AdvancedSearchFilter
+ */
+ public function setDatabase(Database $db)
+ {
+ $this->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