ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UserCountryDefinition.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30use ilCountry;
31use Closure;
32
34{
38 public function __construct(private readonly UI $ui, private readonly Closure $required)
39 {
40 }
41
42 public function formGroup(array $arguments = []): Group
43 {
44 $countries = ilCountry::getCountryCodes();
45 $countries = array_combine($countries, array_map($this->translatedCountry(...), $countries));
46
47 return $this->ui->create()->input()->field()->group([
48 'country' => $this->ui->create()->input()->field()->select(
49 $this->ui->txt('country'),
50 $countries
51 )->withRequired(true, ($this->required)($countries))->withValue(strtoupper($arguments['country'] ?? '') ?: null)
52 ], $this->ui->txt('crit_type_usr_country'), $this->ui->txt('crit_type_usr_country_info'));
53 }
54
55 public function withCriterion(CriterionContent $criterion): Condition
56 {
57 return new UserCountry($criterion, $this, $this->ui->create());
58 }
59
60 public function translatedType(): string
61 {
62 return $this->ui->txt('crit_type_usr_country');
63 }
64
65 public function translatedCountry(string $country): string
66 {
67 return $this->ui->txt('meta_c_' . strtoupper($country));
68 }
69}
__construct(private readonly UI $ui, private readonly Closure $required)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getCountryCodes()
Get country codes (DIN EN 3166-1)
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
Describes the monoid operation of grouping form inputs.
Definition: Group.php:32