ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
UserCountryDefinition.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 use ilCountry;
32 use Closure;
33 
35 {
39  public function __construct(private readonly UI $ui, private readonly Closure $required)
40  {
41  }
42 
43  public function formGroup(array $arguments = []): Group
44  {
45  $countries = ilCountry::getCountryCodes();
46  $countries = array_combine($countries, array_map($this->translatedCountry(...), $countries));
47 
48  return $this->ui->create()->input()->field()->group([
49  'country' => $this->ui->create()->input()->field()->select(
50  $this->ui->txt('country'),
51  $countries
52  )->withRequired(true, ($this->required)($countries))->withValue(strtoupper($arguments['country'] ?? '') ?: null)
53  ], $this->ui->txt('crit_type_usr_country'), $this->ui->txt('crit_type_usr_country_info'));
54  }
55 
56  public function withCriterion(CriterionContent $criterion): Condition
57  {
58  return new UserCountry($criterion, $this, $this->ui->create());
59  }
60 
61  public function translatedType(): string
62  {
63  return $this->ui->txt('crit_type_usr_country');
64  }
65 
66  public function translatedCountry(string $country): string
67  {
68  return $this->ui->txt('meta_c_' . strtoupper($country));
69  }
70 }
__construct(private readonly UI $ui, private readonly Closure $required)
static getCountryCodes()
Get country codes (DIN EN 3166-1)