ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
26{
27 public const WEEK_START_MONDAY = 1;
28 public const WEEK_START_SUNDAY = 0;
29
30 public const DEFAULT_DAY_START = 8;
31 public const DEFAULT_DAY_END = 19;
32
33 public const DATE_FORMAT_UNDEFINED = 0;
34 public const DATE_FORMAT_DMY = 1;
35 public const DATE_FORMAT_YMD = 2;
36 public const DATE_FORMAT_MDY = 3;
37
38 public const DEFAULT_CAL_DAY = 1;
39 public const DEFAULT_CAL_WEEK = 2;
40 public const DEFAULT_CAL_MONTH = 3;
41 public const DEFAULT_CAL_LIST = 4;
42
43 public const TIME_FORMAT_24 = 1;
44 public const TIME_FORMAT_12 = 2;
45
46 public const DEFAULT_CACHE_MINUTES = 0;
47 public const DEFAULT_SYNC_CACHE_MINUTES = 10;
48
49 public const DEFAULT_SHOW_WEEKS = true;
50
51 private static ?ilCalendarSettings $instance = null;
52
53 protected ilDBInterface $db;
55
56 private string $timezone = ilTimeZone::UTC;
61 private bool $enabled = false;
62 private int $cal_settings_id = 0;
63 private bool $consultation_hours = false;
64 private int $date_format = 0;
66 private int $default_period = 2;
67 private bool $cache_enabled = true;
68 private int $cache_minutes = 1;
69 private bool $sync_cache_enabled = true;
70 private int $sync_cache_minutes = 10;
71 private bool $notification = false;
72 private bool $notification_user = false;
73 private bool $cg_registration = false;
74 private bool $course_cal_enabled = true;
75 private bool $group_cal_enabled = true;
76 private bool $course_cal_visible = true;
77 private bool $group_cal_visible = true;
78 private bool $webcal_sync = false;
79 private int $webcal_sync_hours = 2;
80 private bool $show_weeks = false;
81 private bool $batch_file_downloads = false;
82
83 private function __construct()
84 {
85 global $DIC;
86
87 $this->db = $DIC->database();
88 $this->initStorage();
89 $this->read();
91 }
92
93 public static function _getInstance(): ilCalendarSettings
94 {
95 if (self::$instance) {
96 return self::$instance;
97 }
98 return self::$instance = new ilCalendarSettings();
99 }
100
101 public static function lookupCalendarContentPresentationEnabled(int $obj_id): bool
102 {
103 if (!self::lookupCalendarActivated($obj_id)) {
104 return false;
105 }
106 $settings = self::_getInstance();
107 $type = ilObject::_lookupType($obj_id);
108 $default = $settings->isObjectCalendarVisible($type);
110 $obj_id,
111 'cont_show_calendar',
112 (string) $default
113 );
114 }
115
116 public static function lookupCalendarActivated(int $a_obj_id): bool
117 {
119 return false;
120 }
121 $type = ilObject::_lookupType($a_obj_id);
122 // lookup global setting
123 $gl_activated = false;
124 switch ($type) {
125 case 'crs':
126 $gl_activated = ilCalendarSettings::_getInstance()->isCourseCalendarEnabled();
127 break;
128
129 case 'grp':
130 $gl_activated = ilCalendarSettings::_getInstance()->isGroupCalendarEnabled();
131 break;
132
133 default:
134 return false;
135 }
136 // look individual object setting
138 $a_obj_id,
139 'cont_activation_calendar',
140 (string) $gl_activated
141 );
142 }
143
144 public function useCache(bool $a_status): void
145 {
146 $this->cache_enabled = $a_status;
147 }
148
149 public function isCacheUsed(): bool
150 {
152 }
153
154 public function setCacheMinutes(int $a_min): void
155 {
156 $this->cache_minutes = $a_min;
157 }
158
159 public function getCacheMinutes(): int
160 {
162 }
163
164 public function setEnabled(bool $a_enabled): void
165 {
166 $this->enabled = $a_enabled;
167 }
168
169 public function isEnabled(): bool
170 {
171 return $this->enabled;
172 }
173
174 public function setDefaultWeekStart(int $a_start): void
175 {
176 $this->week_start = $a_start;
177 }
178
179 public function getDefaultWeekStart(): int
180 {
181 return $this->week_start;
182 }
183
184 public function getDefaultCal(): int
185 {
186 return $this->default_cal;
187 }
188
189 public function setDefaultCal(int $default_cal): void
190 {
191 $this->default_cal = $default_cal;
192 }
193
194 public function getDefaultPeriod(): int
195 {
197 }
198
199 public function setDefaultPeriod(int $default_period): void
200 {
201 $this->default_period = $default_period;
202 }
203
204 public function setDefaultTimeZone(string $a_zone): void
205 {
206 $this->timezone = $a_zone;
207 }
208
209 public function getDefaultTimeZone(): string
210 {
211 return $this->timezone;
212 }
213
214 public function setDefaultDateFormat(int $a_format): void
215 {
216 $this->date_format = $a_format;
217 }
218
219 public function getDefaultDateFormat(): int
220 {
221 return $this->date_format;
222 }
223
224 public function setDefaultTimeFormat(int $a_format): void
225 {
226 $this->time_format = $a_format;
227 }
228
229 public function getDefaultTimeFormat(): int
230 {
231 return $this->time_format;
232 }
233
234 public function getDefaultDayStart(): int
235 {
236 return $this->day_start;
237 }
238
239 public function setDefaultDayStart(int $a_start): void
240 {
241 $this->day_start = $a_start;
242 }
243
244 public function getDefaultDayEnd(): int
245 {
246 return $this->day_end;
247 }
248
249 public function setDefaultDayEnd(int $a_end): void
250 {
251 $this->day_end = $a_end;
252 }
253
254 public function areConsultationHoursEnabled(): bool
255 {
257 }
258
259 public function enableConsultationHours(bool $a_status): void
260 {
261 $this->consultation_hours = $a_status;
262 }
263
264 public function getCalendarSettingsId(): int
265 {
267 }
268
269 public function isSynchronisationCacheEnabled(): bool
270 {
272 }
273
274 public function enableSynchronisationCache(bool $a_status): void
275 {
276 $this->sync_cache_enabled = $a_status;
277 }
278
279 public function setSynchronisationCacheMinutes(int $a_min): void
280 {
281 $this->sync_cache_minutes = $a_min;
282 }
283
285 {
287 }
288
289 public function isNotificationEnabled(): bool
290 {
291 return $this->notification;
292 }
293
294 public function enableNotification(bool $a_status): void
295 {
296 $this->notification = $a_status;
297 }
298
299 public function isUserNotificationEnabled(): bool
300 {
302 }
303
304 public function enableUserNotification(bool $a_not): void
305 {
306 $this->notification_user = $a_not;
307 }
308
309 public function enableCGRegistration(bool $a_status): void
310 {
311 $this->cg_registration = $a_status;
312 }
313
314 public function isCGRegistrationEnabled(): bool
315 {
317 }
318
319 public function enableCourseCalendar(bool $a_stat): void
320 {
321 $this->course_cal_enabled = $a_stat;
322 }
323
324 public function isCourseCalendarEnabled(): bool
325 {
327 }
328
329 public function isCourseCalendarVisible(): bool
330 {
332 }
333
334 public function setCourseCalendarVisible(bool $status): void
335 {
336 $this->course_cal_visible = $status;
337 }
338
339 public function isObjectCalendarVisible(string $type): bool
340 {
341 switch ($type) {
342 case 'crs':
343 return $this->isCourseCalendarVisible();
344 case 'grp':
345 return $this->isGroupCalendarVisible();
346 }
347 return false;
348 }
349
350 public function enableGroupCalendar(bool $a_stat): void
351 {
352 $this->group_cal_enabled = $a_stat;
353 }
354
355 public function isGroupCalendarEnabled(): bool
356 {
358 }
359
360 public function isGroupCalendarVisible(): bool
361 {
363 }
364
365 public function setGroupCalendarVisible(bool $status): void
366 {
367 $this->group_cal_visible = $status;
368 }
369
370 public function enableWebCalSync(bool $a_stat): void
371 {
372 $this->webcal_sync = $a_stat;
373 }
374
375 public function isWebCalSyncEnabled(): bool
376 {
377 return $this->webcal_sync;
378 }
379
380 public function setWebCalSyncHours(int $a_hours): void
381 {
382 $this->webcal_sync_hours = $a_hours;
383 }
384
385 public function getWebCalSyncHours(): int
386 {
388 }
389
390 public function setShowWeeks(bool $a_val): void
391 {
392 $this->show_weeks = $a_val;
393 }
394
395 public function getShowWeeks(): bool
396 {
397 return $this->show_weeks;
398 }
399
400 public function enableBatchFileDownloads(bool $a_stat): void
401 {
402 $this->batch_file_downloads = $a_stat;
403 }
404
405 public function isBatchFileDownloadsEnabled(): bool
406 {
408 }
409
410 public function save()
411 {
412 $this->storage->set('enabled', (string) (int) $this->isEnabled());
413 $this->storage->set('default_timezone', $this->getDefaultTimeZone());
414 $this->storage->set('default_week_start', (string) $this->getDefaultWeekStart());
415 $this->storage->set('default_date_format', (string) $this->getDefaultDateFormat());
416 $this->storage->set('default_time_format', (string) $this->getDefaultTimeFormat());
417 $this->storage->set('default_day_start', (string) $this->getDefaultDayStart());
418 $this->storage->set('default_day_end', (string) $this->getDefaultDayEnd());
419 $this->storage->set('cache_minutes', (string) $this->getCacheMinutes());
420 $this->storage->set('sync_cache_enabled', (string) (int) $this->isSynchronisationCacheEnabled());
421 $this->storage->set('sync_cache_minutes', (string) $this->getSynchronisationCacheMinutes());
422 $this->storage->set('cache_enabled', (string) (int) $this->isCacheUsed());
423 $this->storage->set('notification', (string) (int) $this->isNotificationEnabled());
424 $this->storage->set('consultation_hours', (string) (int) $this->areConsultationHoursEnabled());
425 $this->storage->set('cg_registration', (string) (int) $this->isCGRegistrationEnabled());
426 $this->storage->set('course_cal', (string) (int) $this->isCourseCalendarEnabled());
427 $this->storage->set('course_cal_visible', (string) (int) $this->isCourseCalendarVisible());
428 $this->storage->set('group_cal', (string) (int) $this->isGroupCalendarEnabled());
429 $this->storage->set('group_cal_visible', (string) (int) $this->isGroupCalendarVisible());
430 $this->storage->set('notification_user', (string) (int) $this->isUserNotificationEnabled());
431 $this->storage->set('webcal_sync', (string) (int) $this->isWebCalSyncEnabled());
432 $this->storage->set('webcal_sync_hours', (string) $this->getWebCalSyncHours());
433 $this->storage->set('show_weeks', (string) (int) $this->getShowWeeks());
434 $this->storage->set('batch_files', (string) (int) $this->isBatchFileDownloadsEnabled());
435 $this->storage->set('default_calendar_view', (string) $this->getDefaultCal());
436 $this->storage->set('default_period', (string) $this->getDefaultPeriod());
437 }
438
439 private function read()
440 {
441 $this->setEnabled((bool) $this->storage->get('enabled'));
442 $this->setDefaultTimeZone($this->storage->get('default_timezone', ilTimeZone::_getDefaultTimeZone()));
443 $this->setDefaultWeekStart((int) $this->storage->get('default_week_start', (string) self::WEEK_START_MONDAY));
444 $this->setDefaultDateFormat((int) $this->storage->get('default_date_format', (string) self::DATE_FORMAT_DMY));
445 $this->setDefaultTimeFormat((int) $this->storage->get('default_time_format', (string) self::TIME_FORMAT_24));
446 $this->setDefaultDayStart((int) $this->storage->get('default_day_start', (string) self::DEFAULT_DAY_START));
447 $this->setDefaultDayEnd((int) $this->storage->get('default_day_end', (string) self::DEFAULT_DAY_END));
448 $this->useCache((bool) $this->storage->get('cache_enabled', (string) $this->cache_enabled));
449 $this->setCacheMinutes((int) $this->storage->get('cache_minutes', (string) self::DEFAULT_CACHE_MINUTES));
450 $this->enableSynchronisationCache((bool) $this->storage->get(
451 'sync_cache_enabled',
452 (string) $this->isSynchronisationCacheEnabled()
453 ));
454 $this->setSynchronisationCacheMinutes((int) $this->storage->get(
455 'sync_cache_minutes',
456 (string) self::DEFAULT_SYNC_CACHE_MINUTES
457 ));
458 $this->enableNotification((bool) $this->storage->get('notification', (string) $this->isNotificationEnabled()));
459 $this->enableConsultationHours((bool) $this->storage->get(
460 'consultation_hours',
461 (string) $this->areConsultationHoursEnabled()
462 ));
463 $this->enableCGRegistration((bool) $this->storage->get(
464 'cg_registration',
465 (string) $this->isCGRegistrationEnabled()
466 ));
467 $this->enableCourseCalendar((bool) $this->storage->get(
468 'course_cal',
469 (string) $this->isCourseCalendarEnabled()
470 ));
471 $this->setCourseCalendarVisible((bool) $this->storage->get(
472 'course_cal_visible',
473 (string) $this->isCourseCalendarVisible()
474 ));
475 $this->enableGroupCalendar((bool) $this->storage->get('group_cal', (string) $this->isGroupCalendarEnabled()));
476 $this->setGroupCalendarVisible((bool) $this->storage->get(
477 'group_cal_visible',
478 (string) $this->isGroupCalendarVisible()
479 ));
480 $this->enableUserNotification((bool) $this->storage->get(
481 'notification_user',
482 (string) $this->isUserNotificationEnabled()
483 ));
484 $this->enableWebCalSync((bool) $this->storage->get('webcal_sync', (string) $this->isWebCalSyncEnabled()));
485 $this->setWebCalSyncHours((int) $this->storage->get('webcal_sync_hours', (string) $this->getWebCalSyncHours()));
486 $this->setShowWeeks((bool) $this->storage->get('show_weeks', (string) $this->getShowWeeks()));
487 $this->enableBatchFileDownloads((bool) $this->storage->get(
488 'batch_files',
489 (string) $this->isBatchFileDownloadsEnabled()
490 ));
491 $this->setDefaultCal((int) $this->storage->get('default_calendar_view', (string) $this->getDefaultCal()));
492 $this->setDefaultPeriod((int) $this->storage->get('default_period', (string) $this->getDefaultPeriod()));
493 }
494
495 private function readCalendarSettingsId(): void
496 {
497 $query = "SELECT ref_id FROM object_reference obr " .
498 "JOIN object_data obd ON obd.obj_id = obr.obj_id " .
499 "WHERE type = 'cals'";
500
501 $set = $this->db->query($query);
502 $row = $this->db->fetchAssoc($set);
503
504 $this->cal_settings_id = (int) $row["ref_id"];
505 }
506
507 private function initStorage()
508 {
509 $this->storage = new ilSetting('calendar');
510 }
511}
Stores all calendar relevant settings.
static lookupCalendarContentPresentationEnabled(int $obj_id)
setCourseCalendarVisible(bool $status)
setSynchronisationCacheMinutes(int $a_min)
enableSynchronisationCache(bool $a_status)
setDefaultTimeZone(string $a_zone)
enableNotification(bool $a_status)
enableBatchFileDownloads(bool $a_stat)
enableConsultationHours(bool $a_status)
setDefaultPeriod(int $default_period)
static lookupCalendarActivated(int $a_obj_id)
enableCGRegistration(bool $a_status)
setDefaultCal(int $default_cal)
static ilCalendarSettings $instance
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
static _lookupType(int $id, bool $reference=false)
ILIAS Setting Class.
static _getDefaultTimeZone()
Calculate and set default time zone.
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26