ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
UserLanguageDefinition.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 use Closure;
32 
34 {
39  public function __construct(
40  private readonly UI $ui,
41  private readonly array $installed_languages,
42  private readonly Closure $required
43  ) {
44  }
45 
46  public function formGroup(array $arguments = []): Group
47  {
48  $languages = array_combine($this->installed_languages, array_map($this->translatedLanguage(...), $this->installed_languages));
49 
50  return $this->ui->create()->input()->field()->group([
51  'lng' => $this->radio(
52  $this->ui->txt('language'),
53  $languages,
54  $arguments['lng'] ?? null
55  )->withRequired(true, ($this->required)($languages))
56  ], $this->ui->txt('crit_type_usr_language'), $this->ui->txt('crit_type_usr_language_info'));
57  }
58 
59  public function withCriterion(CriterionContent $criterion): Condition
60  {
61  return new UserLanguage($criterion, $this, $this->ui->create());
62  }
63 
64  public function translatedType(): string
65  {
66  return $this->ui->txt('crit_type_usr_language');
67  }
68 
69  public function translatedLanguage(string $language): string
70  {
71  return $this->ui->txt('meta_l_' . $language);
72  }
73 
78  private function radio(string $lang_key, array $options, $value): Radio
79  {
80  $field = $this->ui->create()->input()->field()->radio($lang_key);
81  foreach ($options as $key => $label) {
82  $field = $field->withOption((string) $key, $label);
83  }
84 
85  return $value !== null && isset($options[(string) $value]) ? $field->withValue((string) $value) : $field;
86  }
87 }
This is what a radio-input looks like.
Definition: Radio.php:28
__construct(private readonly UI $ui, private readonly array $installed_languages, private readonly Closure $required)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...