summaryrefslogtreecommitdiff
path: root/app/Controller/TaskHelper.php
blob: 236af33ef6448ca5d563e5ff8c13fd5c707c1da5 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace Kanboard\Controller;

/**
 * Task Ajax Helper
 *
 * @package  controller
 * @author   Frederic Guillot
 */
class TaskHelper extends Base
{
    /**
     * Render Markdown text and reply with the HTML Code
     *
     * @access public
     */
    public function preview()
    {
        $payload = $this->request->getJson();

        if (empty($payload['text'])) {
            $this->response->html('<p>'.t('Nothing to preview...').'</p>');
        }

        $this->response->html($this->helper->text->markdown($payload['text']));
    }

    /**
     * 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());
    }
}