From ae708a712a5dd932c01e734f8450b899b1407a70 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 20 Dec 2016 20:06:39 -0500 Subject: Offer the possibility to override internal formatter objects from plugins --- app/Formatter/BoardColumnFormatter.php | 2 +- app/Formatter/BoardFormatter.php | 2 +- app/Formatter/BoardSwimlaneFormatter.php | 2 +- app/Formatter/GroupAutoCompleteFormatter.php | 22 ++++++---------------- app/Formatter/UserAutoCompleteFormatter.php | 2 +- 5 files changed, 10 insertions(+), 20 deletions(-) (limited to 'app/Formatter') diff --git a/app/Formatter/BoardColumnFormatter.php b/app/Formatter/BoardColumnFormatter.php index 85d31b5c..0d59f54e 100644 --- a/app/Formatter/BoardColumnFormatter.php +++ b/app/Formatter/BoardColumnFormatter.php @@ -79,7 +79,7 @@ class BoardColumnFormatter extends BaseFormatter implements FormatterInterface { foreach ($this->columns as &$column) { $column['id'] = (int) $column['id']; - $column['tasks'] = BoardTaskFormatter::getInstance($this->container) + $column['tasks'] = $this->boardTaskFormatter ->withTasks($this->tasks) ->withTags($this->tags) ->withSwimlaneId($this->swimlaneId) diff --git a/app/Formatter/BoardFormatter.php b/app/Formatter/BoardFormatter.php index df443a52..3f47bfa9 100644 --- a/app/Formatter/BoardFormatter.php +++ b/app/Formatter/BoardFormatter.php @@ -59,7 +59,7 @@ class BoardFormatter extends BaseFormatter implements FormatterInterface $task_ids = array_column($tasks, 'id'); $tags = $this->taskTagModel->getTagsByTasks($task_ids); - return BoardSwimlaneFormatter::getInstance($this->container) + return $this->boardSwimlaneFormatter ->withSwimlanes($swimlanes) ->withColumns($columns) ->withTasks($tasks) diff --git a/app/Formatter/BoardSwimlaneFormatter.php b/app/Formatter/BoardSwimlaneFormatter.php index ce67c8a8..18db259d 100644 --- a/app/Formatter/BoardSwimlaneFormatter.php +++ b/app/Formatter/BoardSwimlaneFormatter.php @@ -82,7 +82,7 @@ class BoardSwimlaneFormatter extends BaseFormatter implements FormatterInterface foreach ($this->swimlanes as &$swimlane) { $swimlane['id'] = (int) $swimlane['id']; - $swimlane['columns'] = BoardColumnFormatter::getInstance($this->container) + $swimlane['columns'] = $this->boardColumnFormatter ->withSwimlaneId($swimlane['id']) ->withColumns($this->columns) ->withTasks($this->tasks) diff --git a/app/Formatter/GroupAutoCompleteFormatter.php b/app/Formatter/GroupAutoCompleteFormatter.php index 4d552886..d811de7f 100644 --- a/app/Formatter/GroupAutoCompleteFormatter.php +++ b/app/Formatter/GroupAutoCompleteFormatter.php @@ -12,36 +12,26 @@ use PicoDb\Table; * @package formatter * @author Frederic Guillot */ -class GroupAutoCompleteFormatter implements FormatterInterface +class GroupAutoCompleteFormatter extends BaseFormatter implements FormatterInterface { /** * Groups found * - * @access private + * @access protected * @var GroupProviderInterface[] */ - private $groups; + protected $groups; /** - * Format groups for the ajax auto-completion + * Set groups * * @access public * @param GroupProviderInterface[] $groups + * @return $this */ - public function __construct(array $groups) + public function withGroups(array $groups) { $this->groups = $groups; - } - - /** - * Set query - * - * @access public - * @param Table $query - * @return FormatterInterface - */ - public function withQuery(Table $query) - { return $this; } diff --git a/app/Formatter/UserAutoCompleteFormatter.php b/app/Formatter/UserAutoCompleteFormatter.php index cd23a2a4..32a83608 100644 --- a/app/Formatter/UserAutoCompleteFormatter.php +++ b/app/Formatter/UserAutoCompleteFormatter.php @@ -14,7 +14,7 @@ use Kanboard\Core\Filter\FormatterInterface; class UserAutoCompleteFormatter extends BaseFormatter implements FormatterInterface { /** - * Format the tasks for the ajax autocompletion + * Format the tasks for the ajax auto-completion * * @access public * @return array -- cgit v1.2.3 From 9d5d389de841705450190fb1ebbaa11393870dfe Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 20 Dec 2016 20:27:23 -0500 Subject: Display user full name in auto-complete field value --- app/Formatter/UserAutoCompleteFormatter.php | 4 ++-- doc/plugin-overrides.markdown | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'app/Formatter') diff --git a/app/Formatter/UserAutoCompleteFormatter.php b/app/Formatter/UserAutoCompleteFormatter.php index 32a83608..c81af00a 100644 --- a/app/Formatter/UserAutoCompleteFormatter.php +++ b/app/Formatter/UserAutoCompleteFormatter.php @@ -24,11 +24,11 @@ class UserAutoCompleteFormatter extends BaseFormatter implements FormatterInterf $users = $this->query->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name')->findAll(); foreach ($users as &$user) { - $user['value'] = $user['username'].' (#'.$user['id'].')'; - 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'].')'; } } diff --git a/doc/plugin-overrides.markdown b/doc/plugin-overrides.markdown index b9372bdf..3b94bd60 100644 --- a/doc/plugin-overrides.markdown +++ b/doc/plugin-overrides.markdown @@ -47,8 +47,8 @@ Formatter Overrides Here an example to override formatter objects in Kanboard: ```php -class MyFormatter extends UserAutoCompleteFormatter { - +class MyFormatter extends UserAutoCompleteFormatter +{ public function format() { $users = parent::format(); -- cgit v1.2.3