From 39d0448ff511eac845a6a2f3f5f0ac5a3d452db0 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 6 Aug 2021 13:11:53 +0200 Subject: [PATCH] Introduce class UserDetail --- library/Icingadb/Widget/Detail/UserDetail.php | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 library/Icingadb/Widget/Detail/UserDetail.php diff --git a/library/Icingadb/Widget/Detail/UserDetail.php b/library/Icingadb/Widget/Detail/UserDetail.php new file mode 100644 index 00000000..c6b55d42 --- /dev/null +++ b/library/Icingadb/Widget/Detail/UserDetail.php @@ -0,0 +1,85 @@ + 'user-detail']; + + protected $tag = 'div'; + + public function __construct(User $user) + { + $this->user = $user; + } + + protected function createCustomVars() + { + $content = [new HtmlElement('h2', null, Text::create(t('Custom Variables')))]; + $flattenedVars = $this->user->customvar_flat; + $this->applyRestrictions($flattenedVars); + + $vars = $this->user->customvar_flat->getModel()->unflattenVars($flattenedVars); + if (! empty($vars)) { + $customvarTable = new CustomVarTable($vars); + $customvarTable->setAttribute('id', 'user-customvars'); + $content[] = $customvarTable; + } else { + $content[] = new EmptyState(t('No custom variables configured.')); + } + + return $content; + } + + protected function createUserDetail() + { + return [ + new HtmlElement('h2', null, Text::create(t('Details'))), + new HorizontalKeyValue(t('E-Mail'), $this->user->email), + new HorizontalKeyValue(t('Pager'), $this->user->pager) + ]; + } + + protected function createUsergroupList() + { + $userGroups = $this->user->usergroup->limit(6)->peekAhead()->execute(); + + $showMoreLink = new ShowMore( + $userGroups, + Links::usergroups()->addParams(['user.name' => $this->user->name]) + ); + + return [ + new HtmlElement('h2', null, Text::create(t('Groups'))), + new UsergroupList($userGroups), + $showMoreLink + ]; + } + + protected function assemble() + { + $this->add([ + $this->createUserDetail(), + $this->createUsergroupList(), + $this->createCustomVars() + ]); + } +}