ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DateFormat.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30
32{
33 public function getIdentifier(): string
34 {
35 return 'date_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_date_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_date_format'),
68 $this->buildOptions(),
69 $lng->txt('cal_date_format_info')
70 )->withRequired(true)
71 ->withValue(
72 $user !== null
73 ? $this->retrieveValueFromUser($user)
74 : \ilCalendarSettings::_getInstance()->getDefaultDateFormat()
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_date_format'));
85 $input->setOptions($this->buildOptions());
86 $input->setInfo($lng->txt('cal_date_format_info'));
87 $input->setValue(
88 $user !== null
89 ? $this->retrieveValueFromUser($user)
90 : \ilCalendarSettings::_getInstance()->getDefaultDateFormat()
91 );
92 return $input;
93 }
94
97 \ilSetting $settings
98 ): string {
99 return $this->buildOptions()[\ilCalendarSettings::_getInstance()->getDefaultDateFormat()];
100 }
101
102 private function buildOptions(): array
103 {
104 $year = date('Y');
105 return [
106 \ilCalendarSettings::DATE_FORMAT_DMY => '31.10.' . $year,
107 \ilCalendarSettings::DATE_FORMAT_YMD => $year . '-10-31',
108 \ilCalendarSettings::DATE_FORMAT_MDY => '10/31/' . $year
109 ];
110 }
111
113 \ilSetting $settings,
114 \ilObjUser $user
115 ): bool {
116 return $this->retrieveValueFromUser($user)
117 !== \ilCalendarSettings::_getInstance()->getDefaultDateFormat();
118 }
119
120 public function persistUserInput(
121 \ilObjUser $user,
122 mixed $input
123 ): \ilObjUser {
124 $calendar_settings = \ilCalendarUserSettings::_getInstance($user->getId());
125 $calendar_settings->setDateFormat(
126 $input !== null ? (int) $input : \ilCalendarSettings::_getInstance()->getDefaultDateFormat()
127 );
128 $calendar_settings->save();
129 return $user;
130 }
131
132 public function retrieveValueFromUser(\ilObjUser $user): int
133 {
134 return \ilCalendarUserSettings::_getInstance($user->getId())->getDateFormat();
135 }
136}
persistUserInput(\ilObjUser $user, mixed $input)
Definition: DateFormat.php:120
hasUserPersonalizedSetting(\ilSetting $settings, \ilObjUser $user)
Definition: DateFormat.php:112
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: DateFormat.php:78
getInput(FieldFactory $field_factory, Language $lng, Refinery $refinery, \ilSetting $settings, ?\ilObjUser $user=null)
Definition: DateFormat.php:58
isAvailable()
If this function returns false the setting will not be shown, even if it's PropertyAttributes would a...
Definition: DateFormat.php:38
getDefaultValueForDisplay(Language $lng, \ilSetting $settings)
Definition: DateFormat.php:95
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