summaryrefslogtreecommitdiff
path: root/app/Controller/TaskHelper.php
blob: 7e340a6afea348f944f1febbda396d23fc530fcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

namespace Kanboard\Controller;

/**
 * Task Ajax Helper
 *
 * @package  controller
 * @author   Frederic Guillot
 */
class TaskHelper extends Base
{
    /**
     * Task autocompletion (Ajax)
     *
     * @access public
     */
    public function autocomplete()
    {
        $search = $this->request->getStringParam('term');
        $projects = $this->projectPermission->getActiveProjectIds($this->userSession->getId());

        if (empty($projects)) {
            $this->response->json(array());
        }

        $filter = $this->taskFilterAutoCompleteFormatter
            ->create()
            ->filterByProjects($projects)
            ->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->format());
    }
}