summaryrefslogtreecommitdiff
path: root/app/Controller/TaskHelper.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller/TaskHelper.php')
-rw-r--r--app/Controller/TaskHelper.php38
1 files changed, 23 insertions, 15 deletions
diff --git a/app/Controller/TaskHelper.php b/app/Controller/TaskHelper.php
index 7e340a6a..6835ab2b 100644
--- a/app/Controller/TaskHelper.php
+++ b/app/Controller/TaskHelper.php
@@ -2,6 +2,12 @@
namespace Kanboard\Controller;
+use Kanboard\Filter\TaskIdExclusionFilter;
+use Kanboard\Filter\TaskIdFilter;
+use Kanboard\Filter\TaskProjectsFilter;
+use Kanboard\Filter\TaskTitleFilter;
+use Kanboard\Formatter\TaskAutoCompleteFormatter;
+
/**
* Task Ajax Helper
*
@@ -11,31 +17,33 @@ namespace Kanboard\Controller;
class TaskHelper extends Base
{
/**
- * Task autocompletion (Ajax)
+ * Task auto-completion (Ajax)
*
* @access public
*/
public function autocomplete()
{
$search = $this->request->getStringParam('term');
- $projects = $this->projectPermission->getActiveProjectIds($this->userSession->getId());
+ $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId());
+ $exclude_task_id = $this->request->getIntegerParam('exclude_task_id');
- if (empty($projects)) {
+ if (empty($project_ids)) {
$this->response->json(array());
- }
+ } else {
- $filter = $this->taskFilterAutoCompleteFormatter
- ->create()
- ->filterByProjects($projects)
- ->excludeTasks(array($this->request->getIntegerParam('exclude_task_id')));
+ $filter = $this->taskQuery->withFilter(new TaskProjectsFilter($project_ids));
- // Search by task id or by title
- if (ctype_digit($search)) {
- $filter->filterById($search);
- } else {
- $filter->filterByTitle($search);
- }
+ if (! empty($exclude_task_id)) {
+ $filter->withFilter(new TaskIdExclusionFilter(array($exclude_task_id)));
+ }
+
+ if (ctype_digit($search)) {
+ $filter->withFilter(new TaskIdFilter($search));
+ } else {
+ $filter->withFilter(new TaskTitleFilter($search));
+ }
- $this->response->json($filter->format());
+ $this->response->json($filter->format(new TaskAutoCompleteFormatter($this->container)));
+ }
}
}