ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Language.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Language\Language as SystemLanguage;
30
32{
33 private \ilLanguage $lng;
34
35 public function __construct()
36 {
37 global $DIC;
38 $this->lng = $DIC['lng'];
39 }
40
41 public function isAvailable(): bool
42 {
43 return true;
44 }
45
46 public function getIdentifier(): string
47 {
48 return 'language';
49 }
50
51 public function getLabel(SystemLanguage $lng): string
52 {
53 return $lng->txt($this->getIdentifier());
54 }
55
57 {
58 return AvailablePages::MainSettings;
59 }
60
61 public function getSection(): AvailableSections
62 {
63 return AvailableSections::Main;
64 }
65
66 public function getInput(
67 FieldFactory $field_factory,
68 SystemLanguage $lng,
70 \ilSetting $settings,
71 ?\ilObjUser $user = null
72 ): Input {
73 $options = $this->buildSelectOptions($lng);
74 return $field_factory->select(
75 $this->getLabel($lng),
76 $options
77 )->withDisabled(
78 count($options) <= 1
79 )->withRequired(true)
80 ->withValue(
81 $user !== null
82 ? $this->retrieveValueFromUser($user)
83 : $this->lng->getDefaultLanguage()
84 );
85 }
86
87 public function getLegacyInput(
88 SystemLanguage $lng,
89 \ilSetting $settings,
90 ?\ilObjUser $user = null
92 $options = $this->buildSelectOptions($lng);
93 $input = new \ilSelectInputGUI($this->getLabel($lng));
94 $input->setOptionsLangAttribute(fn($options, $key) => $key);
95 $input->setOptions($options);
96 $input->setDisabled(count($options) <= 1);
97 $input->setValue(
98 $user !== null
99 ? $this->retrieveValueFromUser($user)
100 : $this->lng->getDefaultLanguage()
101 );
102 return $input;
103 }
104
106 SystemLanguage $lng,
107 \ilSetting $settings
108 ): null {
109 return null;
110 }
111
113 \ilSetting $settings,
114 \ilObjUser $user
115 ): bool {
116 return true;
117 }
118
119 public function persistUserInput(
120 \ilObjUser $user,
121 mixed $input
122 ): \ilObjUser {
123 $user->setLanguage($input);
124 return $user;
125 }
126
127 public function retrieveValueFromUser(\ilObjUser $user): string
128 {
129 return $user->getLanguage();
130 }
131
132 private function buildSelectOptions(SystemLanguage $lng): array
133 {
134 return array_reduce(
135 $lng->getInstalledLanguages(),
136 function (array $c, string $lang_key) use ($lng): array {
137 $c[$lang_key] = $lng->txtlng('meta', 'meta_l_' . $lang_key, $lang_key);
138 return $c;
139 },
140 []
141 );
142 }
143}
Builds data types.
Definition: Factory.php:36
getInput(FieldFactory $field_factory, SystemLanguage $lng, Refinery $refinery, \ilSetting $settings, ?\ilObjUser $user=null)
Definition: Language.php:66
getDefaultValueForDisplay(SystemLanguage $lng, \ilSetting $settings)
Definition: Language.php:105
retrieveValueFromUser(\ilObjUser $user)
Definition: Language.php:127
getLegacyInput(SystemLanguage $lng, \ilSetting $settings, ?\ilObjUser $user=null)
Definition: Language.php:87
getLabel(SystemLanguage $lng)
Definition: Language.php:51
hasUserPersonalizedSetting(\ilSetting $settings, \ilObjUser $user)
Definition: Language.php:112
persistUserInput(\ilObjUser $user, mixed $input)
Definition: Language.php:119
isAvailable()
If this function returns false the setting will not be shown, even if it's PropertyAttributes would a...
Definition: Language.php:41
buildSelectOptions(SystemLanguage $lng)
Definition: Language.php:132
return true
This class represents a property in a property form.
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...
User class.
ILIAS Setting Class.
$c
Definition: deliver.php:25
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes commonalities between all inputs.
Definition: Input.php:47
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26