Introduce class UsergroupDetail

This commit is contained in:
Sukhwinder Dhillon 2021-08-06 13:14:06 +02:00
parent 39d0448ff5
commit 784f3481e5

View file

@ -0,0 +1,74 @@
<?php
/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Widget\Detail;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Model\Usergroup;
use Icinga\Module\Icingadb\Widget\EmptyState;
use Icinga\Module\Icingadb\Widget\ItemList\UserList;
use Icinga\Module\Icingadb\Widget\ShowMore;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
class UsergroupDetail extends BaseHtmlElement
{
use Auth;
/** @var Usergroup The given user group */
protected $usergroup;
protected $defaultAttributes = ['class' => '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()
]);
}
}