19declare(strict_types=1);
33 private readonly UIFactory $ui_factory,
50 function (array
$c, array $v) use ($pages, $context, $user): array {
52 if ($settings === []) {
56 $page = $settings[0]->getSettingsPage();
57 $section = $settings[0]->getSection();
65 if (!in_array(AvailablePages::MainSettings, $pages)
66 || $page === AvailablePages::MainSettings && $section === AvailableSections::Main) {
70 $c[$section_key] = $this->ui_factory->input()->field()->optionalGroup(
72 $this->
lng->txt(
"personalise_{$section_key}"),
77 $c[$section_key] =
$c[$section_key]->withValue(
null);
96 $this->getSettingsForPagesBySections($pages),
100 $this->filterSettingsInSectionForAvailability($context, $v)
110 return $this->checkStartingPointValue(
128 foreach ($this->getSettingsForPagesBySections($pages) as $section => $settings) {
129 $available_settings = $this->filterSettingsInSectionForAvailability($context, $settings);
130 $set_settings_to_default =
false;
133 is_array($form) && $form[$section] ===
null
135 && (($input = $form->getInput($section)) ===
'' || $input ===
'0')
138 $set_settings_to_default =
true;
140 foreach ($available_settings as $setting) {
141 $setting->persistUserInput(
144 $set_settings_to_default ?
null : $this->retrieveValueFromInputs($form, $setting),
155 string $definition_class
157 $setting = $this->user_settings_configuration_repository->getByDefinitionClass($definition_class);
158 if ($setting ===
null) {
159 throw new \UnexpectedValueException(
'No class by that name');
165 string $definition_class,
169 $this->getSettingByDefinitionClass($definition_class)->getIdentifier()
174 string $definition_class
177 $this->getSettingByDefinitionClass($definition_class)
183 return $this->user_settings_data_repository->getFor(
$user_id)[$key] ??
null;
188 $context = Context::Export;
190 $this->user_settings_configuration_repository->get(),
191 fn(
Setting $v):
bool => $context->isSettingAvailable($v)
201 return $this->reorderSections(
203 $this->user_settings_configuration_repository->
get(),
204 function (array
$c,
Setting $v) use ($pages): array {
205 if (!in_array($v->getSettingsPage(), $pages)) {
209 $section_key = $this->buildSectionKey($v);
210 if (!array_key_exists($section_key,
$c)) {
211 $c[$section_key] = [];
214 $c[$section_key][] = $v;
226 $default_section = $sections[AvailableSections::Main->value];
227 unset($sections[AvailableSections::Main->value]);
228 array_unshift($sections, $default_section);
245 function (array
$c,
Setting $v) use ($user): array {
246 $c[
'inputs'][$v->getIdentifier()] = $v->getInput(
247 $this->ui_factory->input()->field(),
253 $c[
'byline'] .=
"{$v->getLabel($this->lng)}: "
254 .
"{$v->getDefaultValueForDisplay($this->lng, $this->settings)}; ";
255 if ($v->hasUserPersonalizedSetting($this->settings, $user)) {
256 $c[
'personalized'] =
true;
262 'byline' =>
"{$this->lng->txt('default')}<br>",
263 'personalized' => false
273 if ($section === []) {
277 if ($section[0]->getSettingsPage() === AvailablePages::MainSettings
278 && $section[0]->getSection() === AvailableSections::Main) {
279 return $this->addDefaultInputsToLegacyForm($form, $user, $section);
282 return $this->addAdditionalInputsToLegacyForm($form, $user, $section);
293 $input = $v->getLegacyInput($this->
lng, $this->
settings, $user);
306 $section_key = $this->buildSectionKey($section[0]);
307 $values = array_reduce(
309 function (array
$c,
Setting $v) use ($user): array {
312 $c[
'checkbox']->addSubItem($input);
313 $c[
'defaults'] .=
"{$v->getLabel($this->lng)}: "
314 .
"{$v->getDefaultValueForDisplay($this->lng, $this->settings)}; ";
316 $c[
'has_personalization'] = true;
321 'checkbox' => new \ilCheckboxInputGUI(
322 $this->
lng->txt(
"personalise_{$section_key}"),
325 'defaults' =>
"{$this->lng->txt('default')}<br>",
326 'has_personalization' => false
329 $values[
'checkbox']->setInfo(trim($values[
'defaults']));
330 $values[
'checkbox']->setChecked($values[
'has_personalization']);
332 $form->
addItem($values[
'checkbox']);
351 static fn(
Setting $v): bool => $context->isSettingAvailable($v)
364 $section_key = $this->buildSectionKey($setting);
366 if ($section_key === AvailableSections::Main->value) {
367 return $form[$setting->getIdentifier()];
369 return $form[$section_key][$setting->getIdentifier()];
376 return $form->getInput(
'additional') ===
''
377 || $this->user_settings_configuration_repository
378 ->getByIdentifier(
'starting_point')
379 ->validateUserChoice(
Builds a Color from either hex- or rgb values.
hasUserPersonalizedSetting(\ilSetting $settings, ?\ilObjUser $user)
getLegacyInput(Language $lng, \ilSetting $settings, ?\ilObjUser $user=null)
__construct(private readonly Language $lng, private readonly \ilSetting $settings, private readonly UIFactory $ui_factory, private readonly Refinery $refinery, private readonly ConfigurationRepository $user_settings_configuration_repository, private readonly DataRepository $user_settings_data_repository)
addSectionsToLegacyForm(\ilPropertyFormGUI $form, array $pages, Context $context, ?\ilObjUser $user)
buildInputsForSection(array $settings, ?\ilObjUser $user)
checkStartingPointValue(\ilGlobalTemplateInterface $tpl, \ilPropertyFormGUI $form)
getSettingByDefinitionClass(string $definition_class)
settingAvailableToUser(string $definition_class)
getSettingsForPagesBySections(array $pages)
getSettingValueFor(int $user_id, string $key)
buildFormInputs(array $pages, Context $context, ?\ilObjUser $user)
retrieveValuefromInputs(\ilPropertyFormGUI|array $form, Setting $setting)
addSectionToLegacyForm(\ilPropertyFormGUI $form, ?\ilObjUser $user, array $section)
addAdditionalInputsToLegacyForm(\ilPropertyFormGUI $form, ?\ilObjUser $user, array $section)
saveForm(\ilPropertyFormGUI|array $form, array $pages, Context $context, \ilObjUser $user)
If it is possible to set the preference on the user, this is what will be done, the user needs to be ...
performAdditionalChecks(\ilGlobalTemplateInterface $tpl, \ilPropertyFormGUI $form)
addDefaultInputsToLegacyForm(\ilPropertyFormGUI $form, ?\ilObjUser $user, array $section)
filterSettingsInSectionForAvailability(Context $context, array $settings)
getValueFromLegacyFormByDefinitionClass(string $definition_class, \ilPropertyFormGUI $form)
reorderSections(array $sections)
buildSectionKey(Setting $setting)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))