summaryrefslogtreecommitdiff
path: root/plugins/Timetrackingeditor/Controller/SubtaskAjaxController.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Timetrackingeditor/Controller/SubtaskAjaxController.php')
-rw-r--r--plugins/Timetrackingeditor/Controller/SubtaskAjaxController.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/Timetrackingeditor/Controller/SubtaskAjaxController.php b/plugins/Timetrackingeditor/Controller/SubtaskAjaxController.php
new file mode 100644
index 00000000..4871bfe0
--- /dev/null
+++ b/plugins/Timetrackingeditor/Controller/SubtaskAjaxController.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Kanboard\Plugin\Timetrackingeditor\Controller;
+
+use Kanboard\Controller\BaseController;
+use Kanboard\Core\Filter\QueryBuilder;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Plugin\Timetrackingeditor\Filter\SubtaskTasksFilter;
+use Kanboard\Plugin\Timetrackingeditor\Filter\SubtaskIdFilter;
+use Kanboard\Plugin\Timetrackingeditor\Filter\SubtaskTitleFilter;
+use Kanboard\Plugin\Timetrackingeditor\Formatter\SubtaskAutoCompleteFormatter;
+
+/**
+ * Task Ajax Controller
+ *
+ * @package Kanboard\Plugin\Timetrackingeditor\Controller
+ * @author Thomas Stinner
+ */
+class SubtaskAjaxController extends BaseController
+{
+ /**
+ * Task auto-completion (Ajax)
+ *
+ * @access public
+ */
+ public function autocomplete()
+ {
+ $search = $this->request->getStringParam('term');
+ $task_id = $this->request->getIntegerParam('task_id');
+
+ $subtaskQuery = new QueryBuilder();
+ $subtaskQuery->withQuery($this->db
+ ->table(SubtaskModel::TABLE)
+ ->eq('task_id', $task_id)
+ ->columns(SubtaskModel::TABLE.'*'));
+
+ if (ctype_digit($search)) {
+ $subtaskQuery->withFilter(new SubtaskIdFilter($search));
+ } else {
+ $subtaskQuery->withFilter(new SubtaskTitleFilter($search));
+ }
+
+ $this->response->json($subtaskQuery->format(new SubtaskAutoCompleteFormatter($this->container)));
+ }
+}