summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Controller/App.php24
-rw-r--r--app/Model/TaskFilter.php9
2 files changed, 25 insertions, 8 deletions
diff --git a/app/Controller/App.php b/app/Controller/App.php
index ebe39670..e4a97f8e 100644
--- a/app/Controller/App.php
+++ b/app/Controller/App.php
@@ -110,13 +110,21 @@ class App extends Base
*/
public function autocomplete()
{
- $this->response->json(
- $this->taskFilter
- ->create()
- ->filterByProjects($this->projectPermission->getActiveMemberProjectIds($this->userSession->getId()))
- ->excludeTasks(array($this->request->getIntegerParam('exclude_task_id')))
- ->filterByTitle($this->request->getStringParam('term'))
- ->toAutoCompletion()
- );
+ $search = $this->request->getStringParam('term');
+
+ $filter = $this->taskFilter
+ ->create()
+ ->filterByProjects($this->projectPermission->getActiveMemberProjectIds($this->userSession->getId()))
+ ->excludeTasks(array($this->request->getIntegerParam('exclude_task_id')));
+
+ // Search by task id or by title
+ if (ctype_digit($search)) {
+ $filter->filterById($search);
+ }
+ else {
+ $filter->filterByTitle($search);
+ }
+
+ $this->response->json($filter->toAutoCompletion());
}
}
diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php
index 31de2795..94f6bab0 100644
--- a/app/Model/TaskFilter.php
+++ b/app/Model/TaskFilter.php
@@ -24,6 +24,15 @@ class TaskFilter extends Base
return $this;
}
+ public function filterById($task_id)
+ {
+ if ($task_id > 0) {
+ $this->query->eq('id', $task_id);
+ }
+
+ return $this;
+ }
+
public function filterByTitle($title)
{
$this->query->ilike('title', '%'.$title.'%');