ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
RoleDefinition.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
31use ilRbacReview;
32use Closure;
34
36{
40 public function __construct(
41 private readonly UI $ui,
42 private readonly ilObjectDataCache $cache,
43 private readonly ilRbacReview $review,
44 private readonly Closure $required
45 ) {
46 }
47
48 public function formGroup(array $arguments = []): Group
49 {
50 $roles = $this->review->getGlobalRoles();
51 $roles = array_combine($roles, array_map($this->translatedRole(...), $roles));
52 $default_role = isset($roles[SYSTEM_ROLE_ID]) ? SYSTEM_ROLE_ID : key($roles);
53
54 return $this->ui->create()->input()->field()->group([
55 'role_id' => $this->radio(
56 $this->ui->txt('perm_global_role'),
57 $roles,
58 $arguments['role_id'] ?? $default_role
59 )->withRequired(true, ($this->required)($roles)),
60 ], $this->ui->txt('crit_type_usr_global_role'), $this->ui->txt('crit_type_usr_global_role_info'));
61 }
62
63 public function translatedRole(int $role): string
64 {
65 return $this->cache->lookupTitle($role);
66 }
67
68 public function translatedType(): string
69 {
70 return $this->ui->txt('crit_type_usr_global_role');
71 }
72
73 public function withCriterion(CriterionContent $criterion): Condition
74 {
75 return new Role($criterion, $this, $this->ui->create(), $this->review);
76 }
77
81 private function radio(string $lang_key, array $options, $value): Radio
82 {
83 $field = $this->ui->create()->input()->field()->radio($lang_key);
84 foreach ($options as $key => $label) {
85 $field = $field->withOption((string) $key, $label);
86 }
87 return $value === null ? $field : $field->withValue($value);
88 }
89}
radio(string $lang_key, array $options, $value)
__construct(private readonly UI $ui, private readonly ilObjectDataCache $cache, private readonly ilRbacReview $review, private readonly Closure $required)
class ilObjectDataCache
class ilRbacReview Contains Review functions of core Rbac.
const SYSTEM_ROLE_ID
Definition: constants.php:29
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
Describes the monoid operation of grouping form inputs.
Definition: Group.php:32
This is what a radio-input looks like.
Definition: Radio.php:29