summaryrefslogtreecommitdiff
path: root/app/Filter
diff options
context:
space:
mode:
authorRafael de Camargo <rafaelcamargo@trt15.jus.br>2019-05-14 02:34:53 -0300
committerfguillot <fred@kanboard.net>2019-05-13 22:34:52 -0700
commitd5f6317608376bf55351185a76bb3d8817af1e2d (patch)
tree477f5d51545a0e5b7644e1c3b894c41a5a30faf1 /app/Filter
parent702379a55093aa62bae7dcd49a657397a21fd6b5 (diff)
Do not show duplicated results when multiple comments match
Diffstat (limited to 'app/Filter')
-rw-r--r--app/Filter/TaskCommentFilter.php45
1 files changed, 43 insertions, 2 deletions
diff --git a/app/Filter/TaskCommentFilter.php b/app/Filter/TaskCommentFilter.php
index 52db5581..1bb230e9 100644
--- a/app/Filter/TaskCommentFilter.php
+++ b/app/Filter/TaskCommentFilter.php
@@ -5,6 +5,7 @@ namespace Kanboard\Filter;
use Kanboard\Core\Filter\FilterInterface;
use Kanboard\Model\CommentModel;
use Kanboard\Model\TaskModel;
+use PicoDb\Database;
/**
* Filter tasks by comment
@@ -15,6 +16,14 @@ use Kanboard\Model\TaskModel;
class TaskCommentFilter extends BaseFilter implements FilterInterface
{
/**
+ * Database object
+ *
+ * @access private
+ * @var Database
+ */
+ private $db;
+
+ /**
* Get search attribute
*
* @access public
@@ -26,6 +35,19 @@ class TaskCommentFilter extends BaseFilter implements FilterInterface
}
/**
+ * Set database object
+ *
+ * @access public
+ * @param Database $db
+ * @return $this
+ */
+ public function setDatabase(Database $db)
+ {
+ $this->db = $db;
+ return $this;
+ }
+
+ /**
* Apply filter
*
* @access public
@@ -33,9 +55,28 @@ class TaskCommentFilter extends BaseFilter implements FilterInterface
*/
public function apply()
{
- $this->query->ilike(CommentModel::TABLE.'.comment', '%'.$this->value.'%');
- $this->query->join(CommentModel::TABLE, 'task_id', 'id', TaskModel::TABLE);
+ $task_ids = $this->getTaskIdsWithGivenComment();
+
+ 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()
+ {
+ return $this->db
+ ->table(CommentModel::TABLE)
+ ->ilike(CommentModel::TABLE.'.comment', '%'.$this->value.'%')
+ ->findAllByColumn(CommentModel::TABLE.'.task_id');
+ }
}