ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Settings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\UI\Factory as UIFactory;
26use ILIAS\Refinery\Factory as Refinery;
27
33{
34 public const MODE_INCOMPLETE_ONLY = 0;
35 public const MODE_ONCE_AFTER_LOGIN = 1;
36 public const MODE_REPEAT = 2;
37
42 public function __construct(
43 private int $mode,
44 private ?int $days,
45 private array $info_texts,
46 private array $prompt_texts
47 ) {
48 }
49
50 public function getDays(): ?int
51 {
52 return $this->days;
53 }
54
55 public function getMode(): int
56 {
57 return $this->mode;
58 }
59
63 public function getInfoTexts(): array
64 {
65 return $this->info_texts;
66 }
67
71 public function getPromptTexts(): array
72 {
73 return $this->prompt_texts;
74 }
75
76 public function getInfoText(string $lang): string
77 {
78 return $this->info_texts[$lang] ?? '';
79 }
80
81 public function getPromptText(string $lang): string
82 {
83 return $this->prompt_texts[$lang] ?? '';
84 }
85
86 public function withFormData(array $data): self
87 {
88 $clone = clone $this;
89 $clone->mode = $data['prompting_settings']['prompt_mode']['mode'];
90 $clone->days = $data['prompting_settings']['prompt_mode']['days'];
91 $clone->info_texts = $data['profile_info'];
92 $clone->prompt_texts = $data['prompting_settings']['prompt_texts'];
93 return $clone;
94 }
95
99 public function toForm(
100 UIFactory $ui_factory,
103 ): array {
104 $lng->loadLanguageModule('meta');
105
106 return [
107 'profile_info' => $ui_factory->input()->field()->section(
109 $ui_factory->input()->field(),
110 $lng,
111 fn(string $lang): string => $this->info_texts[$lang] ?? ''
112 ),
113 $lng->txt('user_profile_info_std'),
114 $lng->txt('user_profile_info_text_info')
115 ),
116 'prompting_settings' => $ui_factory->input()->field()->section(
117 $this->buildPromptingSettingsInputs($ui_factory->input()->field(), $lng, $refinery),
118 $lng->txt('user_prompting_settings')
119 )
120 ];
121 }
122
126 private function buildLangTextAreaInputs(
127 FieldFactory $field_factory,
129 \Closure $value_closure
130 ): array {
131 return array_reduce(
132 $lng->getInstalledLanguages(),
133 function (array $c, string $v) use ($field_factory, $lng, $value_closure): array {
134 $c[$v] = $field_factory
135 ->textarea($lng->txt("meta_l_{$v}"))
136 ->withValue($value_closure($v));
137 return $c;
138 },
139 []
140 );
141 }
142
147 FieldFactory $field_factory,
150 ): array {
151 $trafo = $refinery->custom()->transformation(
152 function ($vs) {
153 return array_filter($vs);
154 }
155 );
156 return [
157 'prompt_mode' => $this->buildPromptModeInput($field_factory, $lng, $refinery),
158 'prompt_texts' => $field_factory->section(
159 $this->buildLangTextAreaInputs(
160 $field_factory,
161 $lng,
162 fn(string $lang): string => $this->prompt_texts[$lang] ?? ''
163 ),
164 $lng->txt('user_profile_prompt_text'),
165 $lng->txt('user_profile_prompt_text_info')
166 )->withAdditionalTransformation($trafo)
167 ];
168 }
169
170 private function buildPromptModeInput(
171 FieldFactory $field_factory,
174 ): SwitchableGroup {
175 $trafo = $refinery->custom()->transformation(
176 static fn(array $vs): array => [
177 'mode' => $refinery->kindlyTo()->int()->transform($vs[0]),
178 'days' => $vs[1]['days'] ?? null
179 ]
180 );
181 return $field_factory->switchableGroup(
182 [
183 Settings::MODE_INCOMPLETE_ONLY => $field_factory->group(
184 [],
185 $lng->txt('user_prompt_incomplete'),
186 $lng->txt('user_prompt_incomplete_info')
187 ),
188 Settings::MODE_ONCE_AFTER_LOGIN => $field_factory->group(
189 [
190 'days' => $field_factory
191 ->numeric($lng->txt('days'))
192 ->withRequired(true)
193 ->withAdditionalTransformation($refinery->int()->isGreaterThan(0))
194 ->withValue($this->getDays())
195 ],
196 $lng->txt('user_prompt_once_after_login'),
197 $lng->txt('user_prompt_once_after_login_info')
198 ),
199 Settings::MODE_REPEAT => $field_factory->group(
200 [
201 'days' => $field_factory
202 ->numeric($lng->txt('days'))
203 ->withRequired(true)
204 ->withAdditionalTransformation($refinery->int()->isGreaterThan(0))
205 ->withValue($this->getDays())
206 ],
207 $lng->txt('user_prompt_repeat'),
208 $lng->txt('user_prompt_repeat_info')
209 ),
210 ],
211 $lng->txt('user_prompting_recurrence')
212 )->withAdditionalTransformation($trafo)
213 ->withValue($this->getMode());
214 }
215}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Profile prompt settings.
Definition: Settings.php:33
toForm(UIFactory $ui_factory, \ilLanguage $lng, Refinery $refinery)
Definition: Settings.php:99
buildPromptingSettingsInputs(FieldFactory $field_factory, \ilLanguage $lng, Refinery $refinery)
Definition: Settings.php:146
__construct(private int $mode, private ?int $days, private array $info_texts, private array $prompt_texts)
Definition: Settings.php:42
buildLangTextAreaInputs(FieldFactory $field_factory, \ilLanguage $lng, \Closure $value_closure)
Definition: Settings.php:126
buildPromptModeInput(FieldFactory $field_factory, \ilLanguage $lng, Refinery $refinery)
Definition: Settings.php:170
language handling
$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 switchable group inputs.
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
$lang
Definition: xapiexit.php:25