From 784f3481e55b31ebaebdf79de8fe98ca87897e86 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 6 Aug 2021 13:14:06 +0200 Subject: [PATCH] Introduce class UsergroupDetail --- .../Widget/Detail/UsergroupDetail.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 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 00000000..8968c688 --- /dev/null +++ b/library/Icingadb/Widget/Detail/UsergroupDetail.php @@ -0,0 +1,74 @@ + 'usergroup-detail']; + + protected $tag = 'div'; + + public function __construct(Usergroup $usergroup) + { + $this->usergroup = $usergroup; + } + + protected function createCustomVars() + { + $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)) { + $customvarTable = new CustomVarTable($vars); + $customvarTable->setAttribute('id', 'usergroup-customvars'); + $content[] = $customvarTable; + } else { + $content[] = new EmptyState(t('No custom variables configured.')); + } + + return $content; + } + + protected function createUserList() + { + $users = $this->usergroup->user->limit(6)->peekAhead()->execute(); + + $showMoreLink = new ShowMore( + $users, + Links::users()->addParams(['usergroup.name' => $this->usergroup->name]) + ); + + return [ + new HtmlElement('h2', null, Text::create(t('Users'))), + new UserList($users), + $showMoreLink + ]; + } + + protected function assemble() + { + $this->add([ + $this->createUserList(), + $this->createCustomVars() + ]); + } +}