summaryrefslogtreecommitdiff
path: root/app/Formatter/UserAutoCompleteFormatter.php
blob: c46a24d070970e510aa910dce058c4258ad1471f (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\User;
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 autocompletion
     *
     * @access public
     * @return array
     */
    public function format()
    {
        $users = $this->query->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name')->findAll();

        foreach ($users as &$user) {
            $user['value'] = $user['username'].' (#'.$user['id'].')';

            if (empty($user['name'])) {
                $user['label'] = $user['username'];
            } else {
                $user['label'] = $user['name'].' ('.$user['username'].')';
            }
        }

        return $users;
    }
}