19declare(strict_types=1);
34 private readonly UIFactory $ui_factory,
36 private readonly
Repository $user_settings_repository
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)
109 return $this->checkStartingPointValue($form);
124 foreach ($this->getSettingsForPagesBySections($pages) as $section => $settings) {
125 $available_settings = $this->filterSettingsInSectionForAvailability(
$context, $settings);
126 $set_settings_to_default =
false;
129 is_array($form) && $form[$section] ===
null
131 && (($input = $form->getInput($section)) ===
'' || $input ===
'0')
134 $set_settings_to_default =
true;
136 foreach ($available_settings as $setting) {
137 $setting->persistUserInput(
140 $set_settings_to_default ?
null : $this->retrieveValueFromInputs($form, $setting),
151 string $definition_class
153 $setting = $this->user_settings_repository->getByDefinitionClass($definition_class);
154 if ($setting ===
null) {
155 throw new \UnexpectedValueException(
'No class by that name');
161 string $definition_class,
165 $this->getSettingByDefinitionClass($definition_class)->getIdentifier()
170 string $definition_class
172 return Context::
User->isSettingAvailableInType(
173 $this->getSettingByDefinitionClass($definition_class)
183 return $this->reorderSections(
185 $this->user_settings_repository->
get(),
186 function (array
$c,
Setting $v) use ($pages): array {
187 if (!in_array($v->getSettingsPage(), $pages)) {
191 $section_key = $this->buildSectionKey($v);
192 if (!array_key_exists($section_key,
$c)) {
193 $c[$section_key] = [];
196 $c[$section_key][] = $v;
208 $default_section = $sections[AvailableSections::Main->value];
209 unset($sections[AvailableSections::Main->value]);
210 array_unshift($sections, $default_section);
227 function (array
$c,
Setting $v) use ($user): array {
228 $c[
'inputs'][$v->getIdentifier()] = $v->getInput(
229 $this->ui_factory->input()->field(),
235 $c[
'byline'] .=
"{$v->getLabel($this->lng)}: "
236 .
"{$v->getDefaultValueForDisplay($this->lng, $this->settings)}; ";
237 if ($v->hasUserPersonalizedSetting($this->settings, $user)) {
238 $c[
'personalized'] =
true;
244 'byline' =>
"{$this->lng->txt('default')}<br>",
245 'personalized' => false
255 if ($section === []) {
259 if ($section[0]->getSettingsPage() === AvailablePages::MainSettings
260 && $section[0]->getSection() === AvailableSections::Main) {
261 return $this->addDefaultInputsToLegacyForm($form, $user, $section);
264 return $this->addAdditionalInputsToLegacyForm($form, $user, $section);
275 $input = $v->getLegacyInput($this->
lng, $this->
settings, $user);
288 $section_key = $this->buildSectionKey($section[0]);
289 $values = array_reduce(
291 function (array
$c,
Setting $v) use ($user): array {
294 $c[
'checkbox']->addSubItem($input);
295 $c[
'defaults'] .=
"{$v->getLabel($this->lng)}: "
296 .
"{$v->getDefaultValueForDisplay($this->lng, $this->settings)}; ";
298 $c[
'has_personalization'] = true;
303 'checkbox' => new \ilCheckboxInputGUI(
304 $this->
lng->txt(
"personalise_{$section_key}"),
307 'defaults' =>
"{$this->lng->txt('default')}<br>",
308 'has_personalization' => false
311 $values[
'checkbox']->setInfo(trim($values[
'defaults']));
312 $values[
'checkbox']->setChecked($values[
'has_personalization']);
314 $form->
addItem($values[
'checkbox']);
346 $section_key = $this->buildSectionKey($setting);
348 if ($section_key === AvailableSections::Main->value) {
349 return $form[$setting->getIdentifier()];
351 return $form[$section_key][$setting->getIdentifier()];
356 return $form->
getInput(
'additional') ===
''
357 || $this->user_settings_repository->getByIdentifier(
'starting_point')->validateUserChoice($this->tpl, $this->
lng, $form);
Builds a Color from either hex- or rgb values.
hasUserPersonalizedSetting(\ilSetting $settings, ?\ilObjUser $user)
getLegacyInput(Language $lng, \ilSetting $settings, ?\ilObjUser $user=null)
addSectionsToLegacyForm(\ilPropertyFormGUI $form, array $pages, Context $context, ?\ilObjUser $user)
buildInputsForSection(array $settings, ?\ilObjUser $user)
getSettingByDefinitionClass(string $definition_class)
settingAvailableToUser(string $definition_class)
__construct(private readonly Language $lng, private readonly \ilSetting $settings, private readonly \ilGlobalTemplateInterface $tpl, private readonly UIFactory $ui_factory, private readonly Refinery $refinery, private readonly Repository $user_settings_repository)
getSettingsForPagesBySections(array $pages)
buildFormInputs(array $pages, Context $context, ?\ilObjUser $user)
retrieveValuefromInputs(\ilPropertyFormGUI|array $form, Setting $setting)
addSectionToLegacyForm(\ilPropertyFormGUI $form, ?\ilObjUser $user, array $section)
performAdditionalChecks(\ilPropertyFormGUI $form)
checkStartingPointValue(\ilPropertyFormGUI $form)
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 ...
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'))