ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCalendarUserSettings.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 {
29  public const CAL_SELECTION_MEMBERSHIP = 1;
30  public const CAL_SELECTION_ITEMS = 2;
31 
32  public const CAL_EXPORT_TZ_TZ = 1;
33  public const CAL_EXPORT_TZ_UTC = 2;
34 
35  public static array $instances = array();
36 
37  protected ilObjUser $user;
39 
40  private int $calendar_selection_type = 1;
41  private string $timezone = ilTimeZone::UTC;
42  private int $export_tz_type = self::CAL_EXPORT_TZ_TZ;
43  private int $weekstart = 0;
44  private int $time_format = 0;
45  private int $date_format = 0;
46 
47  private int $day_start = 0;
48  private int $day_end = 0;
49  private bool $show_weeks = true;
50 
51  private function __construct(int $a_user_id)
52  {
53  global $DIC;
54 
55  $this->user = $DIC->user();
56 
57  if ($this->user->getId() !== $a_user_id) {
58  $user = ilObjectFactory::getInstanceByObjId($a_user_id, false);
59  if ($user instanceof ilObjUser) {
60  $this->user = $user;
61  } else {
62  throw new DomainException('Invalid user id given: ' . $a_user_id);
63  }
64  }
66  $this->read();
67  }
68 
69  public static function _getInstanceByUserId(int $a_user_id): ilCalendarUserSettings
70  {
71  if (isset(self::$instances[$a_user_id])) {
72  return self::$instances[$a_user_id];
73  }
74  return self::$instances[$a_user_id] = new ilCalendarUserSettings($a_user_id);
75  }
76 
77  public static function _getInstance(): ilCalendarUserSettings
78  {
79  global $DIC;
80 
81  $ilUser = $DIC['ilUser'];
82  return self::_getInstanceByUserId($ilUser->getId());
83  }
84 
85  public function getTimeZone(): string
86  {
87  return $this->timezone;
88  }
89 
90  public function setTimeZone(string $a_tz): void
91  {
92  $this->timezone = $a_tz;
93  }
94 
95  public function getExportTimeZoneType(): int
96  {
97  return $this->export_tz_type;
98  }
99 
100  public function setExportTimeZoneType(int $a_type): void
101  {
102  $this->export_tz_type = $a_type;
103  }
104 
105  public function getExportTimeZone(): string
106  {
107  switch ($this->getExportTimeZoneType()) {
108  case self::CAL_EXPORT_TZ_TZ:
109  return $this->getTimeZone();
110 
111  case self::CAL_EXPORT_TZ_UTC:
112  return ilTimeZone::UTC;
113  }
114  return '';
115  }
116 
117  public function setWeekStart(int $a_weekstart): void
118  {
119  $this->weekstart = $a_weekstart;
120  }
121 
122  public function getWeekStart(): int
123  {
124  return $this->weekstart;
125  }
126 
127  public function setDayStart(int $a_start): void
128  {
129  $this->day_start = $a_start;
130  }
131 
132  public function getDayStart(): int
133  {
134  return $this->day_start;
135  }
136 
137  public function setDayEnd(int $a_end): void
138  {
139  $this->day_end = $a_end;
140  }
141 
142  public function getDayEnd(): int
143  {
144  return $this->day_end;
145  }
146 
147  public function setDateFormat(int $a_format): void
148  {
149  $this->date_format = $a_format;
150  }
151 
152  public function getDateFormat(): int
153  {
154  return $this->date_format;
155  }
156 
157  public function setTimeFormat(int $a_format): void
158  {
159  $this->time_format = $a_format;
160  }
161 
162  public function getTimeFormat(): int
163  {
164  return $this->time_format;
165  }
166 
171  public function getCalendarSelectionType(): int
172  {
174  }
175 
181  public function setCalendarSelectionType(int $a_type)
182  {
183  $this->calendar_selection_type = $a_type;
184  }
185 
186  public function setShowWeeks(bool $a_val): void
187  {
188  $this->show_weeks = $a_val;
189  }
190 
191  public function getShowWeeks(): bool
192  {
193  return $this->show_weeks;
194  }
195 
196  public function save()
197  {
198  $this->user->writePref('user_tz', $this->getTimeZone());
199  $this->user->writePref('export_tz_type', (string) $this->getExportTimeZoneType());
200  $this->user->writePref('weekstart', (string) $this->getWeekStart());
201  $this->user->writePref('date_format', (string) $this->getDateFormat());
202  $this->user->writePref('time_format', (string) $this->getTimeFormat());
203  $this->user->writePref('calendar_selection_type', (string) $this->getCalendarSelectionType());
204  $this->user->writePref('day_start', (string) $this->getDayStart());
205  $this->user->writePref('day_end', (string) $this->getDayEnd());
206  $this->user->writePref('show_weeks', (string) $this->getShowWeeks());
207  }
208 
209  protected function read(): void
210  {
211  $this->timezone = (string) $this->user->getTimeZone();
212  $this->export_tz_type = (int) (
213  ($this->user->getPref('export_tz_type') !== false) ?
214  $this->user->getPref('export_tz_type') :
216  );
217  $this->date_format = $this->translateDateFormatToId(
218  $this->user->getDateFormat()
219  );
220  $this->time_format = (int) $this->user->getTimeFormat();
221  if (($weekstart = $this->user->getPref('weekstart')) === false) {
222  $weekstart = $this->settings->getDefaultWeekStart();
223  }
224  $this->calendar_selection_type = (int) $this->user->getPref('calendar_selection_type') ?
225  (int) $this->user->getPref('calendar_selection_type') :
226  self::CAL_SELECTION_MEMBERSHIP;
227 
228  $this->weekstart = (int) $weekstart;
229 
230  $this->setDayStart(
231  $this->user->getPref('day_start') ?
232  (int) $this->user->getPref('day_start') :
233  $this->settings->getDefaultDayStart()
234  );
235  $this->setDayEnd(
236  $this->user->getPref('day_end') ?
237  (int) $this->user->getPref('day_end') :
238  $this->settings->getDefaultDayEnd()
239  );
240  $this->setShowWeeks(
241  $this->user->getPref('show_weeks') !== null ?
242  (bool) $this->user->getPref('show_weeks') :
243  $this->settings->getShowWeeks()
244  );
245  }
246 
250  protected function translateDateFormatToId(DateFormat $format): int
251  {
252  switch ((string) $format) {
253  case 'd.m.Y':
255 
256  case 'm/d/Y':
258 
259  case 'Y-m-d':
260  default:
262  }
263  }
264 }
setCalendarSelectionType(int $a_type)
set calendar selection type
static _getInstanceByUserId(int $a_user_id)
translateDateFormatToId(DateFormat $format)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getCalendarSelectionType()
get calendar selection type ("MyMembership" or "Selected Items")
A Date Format provides a format definition akin to PHP&#39;s date formatting options, but stores the sing...
Definition: DateFormat.php:26
global $DIC
Definition: shib_login.php:22
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id