diff options
author | emkael <emkael@tlen.pl> | 2020-05-05 14:25:42 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2020-05-05 14:25:42 +0200 |
commit | 62827e6cf470449c117624058fb36ad94804bcc0 (patch) | |
tree | 10cd1e4d36c34b694acfadaa69fc7f6ae2b1eabd /plugins/Timetrackingeditor/Controller/SubtaskAjaxController.php | |
parent | 7b66ddf2e4fbdb837e78d8b7dbaa9fc38391bc32 (diff) |
Diffstat (limited to 'plugins/Timetrackingeditor/Controller/SubtaskAjaxController.php')
-rw-r--r-- | plugins/Timetrackingeditor/Controller/SubtaskAjaxController.php | 45 |
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))); + } +} |