diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-11-09 15:09:54 -0800 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-11-09 15:09:54 -0800 |
commit | 44aa24bab16bdc2545b08594386adb24ead3aa9e (patch) | |
tree | 4ca2c4632d9657f8babfb7781b5aadc0d3e30238 /app/Formatter | |
parent | 95b2a36886a763242e11b4b27998a0d5c51ca7f4 (diff) |
Add user backend provider system
Diffstat (limited to 'app/Formatter')
-rw-r--r-- | app/Formatter/GroupAutoCompleteFormatter.php | 3 | ||||
-rw-r--r-- | app/Formatter/UserAutoCompleteFormatter.php | 50 |
2 files changed, 37 insertions, 16 deletions
diff --git a/app/Formatter/GroupAutoCompleteFormatter.php b/app/Formatter/GroupAutoCompleteFormatter.php index d811de7f..9d740b7f 100644 --- a/app/Formatter/GroupAutoCompleteFormatter.php +++ b/app/Formatter/GroupAutoCompleteFormatter.php @@ -4,12 +4,11 @@ namespace Kanboard\Formatter; use Kanboard\Core\Filter\FormatterInterface; use Kanboard\Core\Group\GroupProviderInterface; -use PicoDb\Table; /** * Auto-complete formatter for groups * - * @package formatter + * @package Kanboard\Formatter * @author Frederic Guillot */ class GroupAutoCompleteFormatter extends BaseFormatter implements FormatterInterface diff --git a/app/Formatter/UserAutoCompleteFormatter.php b/app/Formatter/UserAutoCompleteFormatter.php index c81af00a..aa02cd22 100644 --- a/app/Formatter/UserAutoCompleteFormatter.php +++ b/app/Formatter/UserAutoCompleteFormatter.php @@ -2,37 +2,59 @@ namespace Kanboard\Formatter; -use Kanboard\Model\UserModel; +use Kanboard\Core\User\UserProviderInterface; use Kanboard\Core\Filter\FormatterInterface; /** - * Auto-complete formatter for user filter + * Auto-complete formatter for users * - * @package formatter + * @package Kanboard\Formatter * @author Frederic Guillot */ class UserAutoCompleteFormatter extends BaseFormatter implements FormatterInterface { /** - * Format the tasks for the ajax auto-completion + * 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() { - $users = $this->query->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name')->findAll(); + $result = array(); - 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'].')'; - } + 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 $users; + return $result; } } |