From b18bc644404e02b57635bfcc8258e85abb141146 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:44:46 +0200 Subject: Adding upstream version 1.1.1. Signed-off-by: Daniel Baumann --- library/Icingadb/Widget/Detail/UsergroupDetail.php | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 library/Icingadb/Widget/Detail/UsergroupDetail.php (limited to 'library/Icingadb/Widget/Detail/UsergroupDetail.php') diff --git a/library/Icingadb/Widget/Detail/UsergroupDetail.php b/library/Icingadb/Widget/Detail/UsergroupDetail.php new file mode 100644 index 0000000..249c795 --- /dev/null +++ b/library/Icingadb/Widget/Detail/UsergroupDetail.php @@ -0,0 +1,98 @@ + 'object-detail']; + + protected $tag = 'div'; + + public function __construct(Usergroup $usergroup) + { + $this->usergroup = $usergroup; + } + + protected function createPrintHeader() + { + return [ + new HtmlElement('h2', null, Text::create(t('Details'))), + new HorizontalKeyValue(t('Name'), $this->usergroup->name) + ]; + } + + protected function createCustomVars(): array + { + $content = [new HtmlElement('h2', null, Text::create(t('Custom Variables')))]; + $flattenedVars = $this->usergroup->customvar_flat; + $this->applyRestrictions($flattenedVars); + + $vars = $this->usergroup->customvar_flat->getModel()->unflattenVars($flattenedVars); + if (! empty($vars)) { + $content[] = new HtmlElement('div', Attributes::create([ + 'id' => 'usergroup-customvars', + 'class' => 'collapsible', + 'data-visible-height' => 200 + ]), new CustomVarTable($vars, $this->usergroup)); + } else { + $content[] = new EmptyState(t('No custom variables configured.')); + } + + return $content; + } + + protected function createUserList(): array + { + $users = $this->usergroup->user->limit(6)->peekAhead()->execute(); + + $showMoreLink = (new ShowMore( + $users, + Links::users()->addParams(['usergroup.name' => $this->usergroup->name]) + ))->setBaseTarget('_next'); + + return [ + new HtmlElement('h2', null, Text::create(t('Users'))), + new UserTable($users), + $showMoreLink + ]; + } + + protected function createExtensions(): array + { + return ObjectDetailExtensionHook::loadExtensions($this->usergroup); + } + + protected function assemble() + { + if (getenv('ICINGAWEB_EXPORT_FORMAT') === 'pdf') { + $this->add($this->createPrintHeader()); + } + + $this->add(ObjectDetailExtensionHook::injectExtensions([ + 500 => $this->createUserList(), + 700 => $this->createCustomVars() + ], $this->createExtensions())); + } +} -- cgit v1.2.3