File size: 1,449 Bytes
e4f4821 |
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 58 59 60 61 |
<?php
namespace Kanboard\Formatter;
use Kanboard\Core\User\UserProviderInterface;
use Kanboard\Core\Filter\FormatterInterface;
/**
* Auto-complete formatter for users
*
* @package Kanboard\Formatter
* @author Frederic Guillot
*/
class UserAutoCompleteFormatter extends BaseFormatter implements FormatterInterface
{
/**
* Users found
*
* @access protected
* @var UserProviderInterface[]
*/
protected $users;
/**
* Set users
*
* @access public
* @param UserProviderInterface[] $users
* @return $this
*/
public function withUsers(array $users)
{
$this->users = $users;
return $this;
}
/**
* Format the users for the ajax auto-completion
*
* @access public
* @return array
*/
public function format()
{
$result = array();
foreach ($this->users as $user) {
$result[] = array(
'id' => $user->getInternalId(),
'username' => $user->getUsername(),
'external_id' => $user->getExternalId(),
'external_id_column' => $user->getExternalIdColumn(),
'value' => $user->getName() === '' ? $user->getUsername() : $user->getName(),
'label' => $user->getName() === '' ? $user->getUsername() : $user->getName().' ('.$user->getUsername().')',
);
}
return $result;
}
}
|