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() + ]); + } +}