summaryrefslogtreecommitdiff
path: root/app/Controller/TaskAjaxController.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller/TaskAjaxController.php')
-rw-r--r--app/Controller/TaskAjaxController.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/app/Controller/TaskAjaxController.php b/app/Controller/TaskAjaxController.php
new file mode 100644
index 00000000..d630b962
--- /dev/null
+++ b/app/Controller/TaskAjaxController.php
@@ -0,0 +1,49 @@
+<?php
+
+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 Controller
+ *
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
+ */
+class TaskAjaxController extends BaseController
+{
+ /**
+ * Task auto-completion (Ajax)
+ *
+ * @access public
+ */
+ public function autocomplete()
+ {
+ $search = $this->request->getStringParam('term');
+ $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId());
+ $exclude_task_id = $this->request->getIntegerParam('exclude_task_id');
+
+ if (empty($project_ids)) {
+ $this->response->json(array());
+ } else {
+
+ $filter = $this->taskQuery->withFilter(new TaskProjectsFilter($project_ids));
+
+ 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(new TaskAutoCompleteFormatter($this->container)));
+ }
+ }
+}