ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
RoleDefinition.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 use ilRbacReview;
32 use Closure;
33 
35 {
39  public function __construct(
40  private readonly UI $ui,
41  private readonly ilObjectDataCache $cache,
42  private readonly ilRbacReview $review,
43  private readonly Closure $required
44  ) {
45  }
46 
47  public function formGroup(array $arguments = []): Group
48  {
49  $roles = $this->review->getGlobalRoles();
50  $roles = array_combine($roles, array_map($this->translatedRole(...), $roles));
51  $default_role = isset($roles[SYSTEM_ROLE_ID]) ? SYSTEM_ROLE_ID : key($roles);
52 
53  return $this->ui->create()->input()->field()->group([
54  'role_id' => $this->radio(
55  $this->ui->txt('perm_global_role'),
56  $roles,
57  $arguments['role_id'] ?? $default_role
58  )->withRequired(true, ($this->required)($roles)),
59  ], $this->ui->txt('crit_type_usr_global_role'), $this->ui->txt('crit_type_usr_global_role_info'));
60  }
61 
62  public function translatedRole(int $role): string
63  {
64  return $this->cache->lookupTitle($role);
65  }
66 
67  public function translatedType(): string
68  {
69  return $this->ui->txt('crit_type_usr_global_role');
70  }
71 
72  public function withCriterion(CriterionContent $criterion): Condition
73  {
74  return new Role($criterion, $this, $this->ui->create(), $this->review);
75  }
76 
80  private function radio($lang_key, array $options, $value)
81  {
82  $field = $this->ui->create()->input()->field()->radio($lang_key);
83  foreach ($options as $key => $label) {
84  $field = $field->withOption((string) $key, $label);
85  }
86  return $value === null ? $field : $field->withValue($value);
87  }
88 }
const SYSTEM_ROLE_ID
Definition: constants.php:29
__construct(private readonly UI $ui, private readonly ilObjectDataCache $cache, private readonly ilRbacReview $review, private readonly Closure $required)
string $key
Consumer key/client ID value.
Definition: System.php:193