ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TimeFormat.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\Refinery\Factory as Refinery;
30
32{
33 public function getIdentifier(): string
34 {
35 return 'time_format';
36 }
37
38 public function isAvailable(): bool
39 {
40 return true;
41 }
42
43 public function getLabel(Language $lng): string
44 {
45 return $lng->txt('cal_user_time_format');
46 }
47
49 {
50 return AvailablePages::MainSettings;
51 }
52
53 public function getSection(): AvailableSections
54 {
55 return AvailableSections::DateTime;
56 }
57
58 public function getInput(
59 FieldFactory $field_factory,
62 \ilSetting $settings,
63 ?\ilObjUser $user = null
64 ): Input {
65 $lng->loadLanguageModule('dateplaner');
66 return $field_factory->select(
67 $lng->txt('cal_user_time_format'),
68 $this->buildOptions(),
69 $lng->txt('cal_time_format_info')
70 )->withRequired(true)
71 ->withValue(
72 $user !== null
73 ? $this->retrieveValueFromUser($user)
74 : \ilCalendarSettings::_getInstance()->getDefaultTimeZone()
75 );
76 }
77
78 public function getLegacyInput(
80 \ilSetting $settings,
81 ?\ilObjUser $user = null
83 $lng->loadLanguageModule('dateplaner');
84 $input = new \ilSelectInputGUI($lng->txt('cal_user_time_format'));
85 $input->setOptions($this->buildOptions());
86 $input->setInfo($lng->txt('cal_time_format_info'));
87 $input->setValue(
88 $user !== null
89 ? $this->retrieveValueFromUser($user)
90 : \ilCalendarSettings::_getInstance()->getDefaultTimeFormat()
91 );
92 return $input;
93 }
94
97 \ilSetting $settings
98 ): string {
99 return $this->buildOptions()[\ilCalendarSettings::_getInstance()->getDefaultTimeFormat()];
100 }
101
103 \ilSetting $settings,
104 \ilObjUser $user
105 ): bool {
106 return $this->retrieveValueFromUser($user) !== \ilCalendarSettings::_getInstance()->getDefaultTimeFormat();
107 }
108
109 public function persistUserInput(
110 \ilObjUser $user,
111 mixed $input
112 ): \ilObjUser {
113 $calendar_settings = \ilCalendarUserSettings::_getInstance($user->getId());
114 $calendar_settings->setTimeFormat(
115 $input !== null ? (int) $input : \ilCalendarSettings::_getInstance()->getDefaultTimeFormat()
116 );
117 $calendar_settings->save();
118 return $user;
119 }
120
121 public function retrieveValueFromUser(\ilObjUser $user): int
122 {
123 return (int) $user->getTimeFormat();
124 }
125
126 private function buildOptions(): array
127 {
128 return [
131 ];
132 }
133}
getDefaultValueForDisplay(Language $lng, \ilSetting $settings)
Definition: TimeFormat.php:95
persistUserInput(\ilObjUser $user, mixed $input)
Definition: TimeFormat.php:109
getInput(FieldFactory $field_factory, Language $lng, Refinery $refinery, \ilSetting $settings, ?\ilObjUser $user=null)
Definition: TimeFormat.php:58
hasUserPersonalizedSetting(\ilSetting $settings, \ilObjUser $user)
Definition: TimeFormat.php:102
getLegacyInput(Language $lng, \ilSetting $settings, ?\ilObjUser $user=null)
You don't need to add a post_var to the input as the User will handle this for you,...
Definition: TimeFormat.php:78
isAvailable()
If this function returns false the setting will not be shown, even if it's PropertyAttributes would a...
Definition: TimeFormat.php:38
Builds data types.
Definition: Factory.php:36
Stores all calendar relevant settings.
This class represents a property in a property form.
User class.
ILIAS Setting Class.
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