summaryrefslogtreecommitdiff
path: root/app/Controller/UserAjaxController.php
blob: 37c09b8a7c19066a857b3e12ecd23ad1b314100d (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
<?php

namespace Kanboard\Controller;

use Kanboard\Filter\UserNameFilter;
use Kanboard\Model\UserModel;

/**
 * User Ajax Controller
 *
 * @package  Kanboard\Controller
 * @author   Frederic Guillot
 */
class UserAjaxController extends BaseController
{
    /**
     * User auto-completion (Ajax)
     *
     * @access public
     */
    public function autocomplete()
    {
        $search = $this->request->getStringParam('term');
        $filter = $this->userQuery->withFilter(new UserNameFilter($search));
        $filter->getQuery()
            ->eq(UserModel::TABLE.'.is_active', 1)
            ->asc(UserModel::TABLE.'.name')
            ->asc(UserModel::TABLE.'.username');

        $this->response->json($filter->format($this->userAutoCompleteFormatter));
    }

    /**
     * User mention auto-completion (Ajax)
     *
     * @access public
     */
    public function mention()
    {
        $project_id = $this->request->getStringParam('project_id');
        $query = $this->request->getStringParam('search');
        $users = $this->projectPermissionModel->findUsernames($project_id, $query);

        $this->response->json($this->userMentionFormatter->withUsers($users)->format());
    }

    /**
     * Check if the user is connected
     *
     * @access public
     */
    public function status()
    {
        $this->response->text('OK');
    }
}