summaryrefslogtreecommitdiff
path: root/app/Formatter/UserAutoCompleteFormatter.php
blob: c81af00a2b841ff2f5f0e41310c9db0eea4f11d5 (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
<?php

namespace Kanboard\Formatter;

use Kanboard\Model\UserModel;
use Kanboard\Core\Filter\FormatterInterface;

/**
 * Auto-complete formatter for user filter
 *
 * @package  formatter
 * @author   Frederic Guillot
 */
class UserAutoCompleteFormatter extends BaseFormatter implements FormatterInterface
{
    /**
     * Format the tasks for the ajax auto-completion
     *
     * @access public
     * @return array
     */
    public function format()
    {
        $users = $this->query->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name')->findAll();

        foreach ($users as &$user) {
            if (empty($user['name'])) {
                $user['value'] = $user['username'].' (#'.$user['id'].')';
                $user['label'] = $user['username'];
            } else {
                $user['value'] = $user['name'].' (#'.$user['id'].')';
                $user['label'] = $user['name'].' ('.$user['username'].')';
            }
        }

        return $users;
    }
}