ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
Language.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
29 class Language
30 {
31  public function __construct(
32  private readonly string $language_code,
33  private string $title,
34  private string $description,
35  private bool $default = false,
36  private bool $base = false
37  ) {
38  }
39 
40  public function getLanguageCode(): string
41  {
42  return $this->language_code;
43  }
44 
45  public function getTitle(): string
46  {
47  return $this->title;
48  }
49 
50  public function withTitle(string $title): self
51  {
52  $clone = clone $this;
53  $clone->title = $title;
54  return $clone;
55  }
56 
57  public function getDescription(): string
58  {
59  return $this->description;
60  }
61 
62  public function withDescription(string $description): self
63  {
64  $clone = clone $this;
65  $clone->description = $description;
66  return $clone;
67  }
68 
69  public function isDefault(): bool
70  {
71  return $this->default;
72  }
73 
74  public function withDefault(bool $default): self
75  {
76  $clone = clone $this;
77  $clone->default = $default;
78  return $clone;
79  }
80 
81  public function isBase(): bool
82  {
83  return $this->base;
84  }
85 
86  public function withBase(bool $base): self
87  {
88  $clone = clone $this;
89  $clone->base = $base;
90  return $clone;
91  }
92 
93  public function toForm(
94  \ilLanguage $language,
95  FieldFactory $field_factory,
97  ): array {
98  return [
99  $field_factory->group([
100  'language' => $field_factory->hidden()->withValue($this->language_code),
101  'title' => $field_factory->text($language->txt('title'))
102  ->withRequired(true)
103  ->withValue($this->title),
104  'description' => $field_factory->textarea($language->txt('description'))
105  ->withValue($this->description),
106  'default' => $field_factory->hidden()->withValue($this->isDefault()),
107  'base' => $field_factory->hidden()->withValue($this->isBase()),
109  $refinery->custom()->transformation(
110  static fn(array $vs): self => new self(
111  $vs['language'],
112  $vs['title'],
113  $vs['description'],
114  $vs['default'] === '1',
115  $vs['base'] === '1'
116  )
117  )
118  )
119  ];
120  }
121 
122  public function toRow(
123  DataRowBuilder $row_builder,
125  ): DataRow {
126  return $row_builder->buildDataRow(
127  $this->language_code,
128  [
129  'language' => $this->getTranslatedLanguageName($lng, $this->language_code),
130  'base' => $this->isBase(),
131  'default' => $this->isDefault(),
132  'title' => $this->getTitle(),
133  'description' => $this->getDescription()
134  ]
135  )->withDisabledAction(TranslationsTable::ACTION_DELETE, $this->isBase() || $this->isDefault())
136  ->withDisabledAction(TranslationsTable::ACTION_MAKE_DEFAULT, $this->isDefault());
137  }
138 
139  private function getTranslatedLanguageName(
141  string $language_code
142  ): string {
143  return $lng->txt("meta_l_{$language_code}");
144  }
145 }
__construct(private readonly string $language_code, private string $title, private string $description, private bool $default=false, private bool $base=false)
Definition: Language.php:31
toForm(\ilLanguage $language, FieldFactory $field_factory, Refinery $refinery)
Definition: Language.php:93
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
buildDataRow(string $id, array $record)
getTranslatedLanguageName(SystemLanguage $lng, string $language_code)
Definition: Language.php:139
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
global $lng
Definition: privfeed.php:31
toRow(DataRowBuilder $row_builder, SystemLanguage $lng)
Definition: Language.php:122