ILIAS  release_8 Revision v8.24
class.ilCalendarSettings.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
32{
33 public const WEEK_START_MONDAY = 1;
34 public const WEEK_START_SUNDAY = 0;
35
36 public const DEFAULT_DAY_START = 8;
37 public const DEFAULT_DAY_END = 19;
38
39 public const DATE_FORMAT_UNDEFINED = 0;
40 public const DATE_FORMAT_DMY = 1;
41 public const DATE_FORMAT_YMD = 2;
42 public const DATE_FORMAT_MDY = 3;
43
44 public const DEFAULT_CAL_DAY = 1;
45 public const DEFAULT_CAL_WEEK = 2;
46 public const DEFAULT_CAL_MONTH = 3;
47 public const DEFAULT_CAL_LIST = 4;
48
49 public const TIME_FORMAT_24 = 1;
50 public const TIME_FORMAT_12 = 2;
51
52 public const DEFAULT_CACHE_MINUTES = 0;
53 public const DEFAULT_SYNC_CACHE_MINUTES = 10;
54
55 public const DEFAULT_SHOW_WEEKS = true;
56
57 private static ?ilCalendarSettings $instance = null;
58
59 protected ilDBInterface $db;
61
62 private string $timezone = ilTimeZone::UTC;
67 private bool $enabled = false;
68 private int $cal_settings_id = 0;
69 private bool $consultation_hours = false;
70 private int $date_format = 0;
72 private int $default_period = 2;
73 private bool $cache_enabled = true;
74 private int $cache_minutes = 1;
75 private bool $sync_cache_enabled = true;
76 private int $sync_cache_minutes = 10;
77 private bool $notification = false;
78 private bool $notification_user = false;
79 private bool $cg_registration = false;
80 private bool $course_cal_enabled = true;
81 private bool $group_cal_enabled = true;
82 private bool $course_cal_visible = true;
83 private bool $group_cal_visible = true;
84 private bool $webcal_sync = false;
85 private int $webcal_sync_hours = 2;
86 private bool $show_weeks = false;
87 private bool $batch_file_downloads = false;
88 private bool $enablegroupmilestones = false;
89
90 private function __construct()
91 {
92 global $DIC;
93
94 $this->db = $DIC->database();
95 $this->initStorage();
96 $this->read();
98 }
99
100 public static function _getInstance(): ilCalendarSettings
101 {
102 if (self::$instance) {
103 return self::$instance;
104 }
105 return self::$instance = new ilCalendarSettings();
106 }
107
108 public static function lookupCalendarContentPresentationEnabled(int $obj_id): bool
109 {
110 if (!self::lookupCalendarActivated($obj_id)) {
111 return false;
112 }
114 $type = ilObject::_lookupType($obj_id);
115 $default = $settings->isObjectCalendarVisible($type);
117 $obj_id,
118 'cont_show_calendar',
119 (string) $default
120 );
121 }
122
123 public static function lookupCalendarActivated(int $a_obj_id): bool
124 {
126 return false;
127 }
128 $type = ilObject::_lookupType($a_obj_id);
129 // lookup global setting
130 $gl_activated = false;
131 switch ($type) {
132 case 'crs':
133 $gl_activated = ilCalendarSettings::_getInstance()->isCourseCalendarEnabled();
134 break;
135
136 case 'grp':
137 $gl_activated = ilCalendarSettings::_getInstance()->isGroupCalendarEnabled();
138 break;
139
140 default:
141 return false;
142 }
143 // look individual object setting
145 $a_obj_id,
146 'cont_activation_calendar',
147 (string) $gl_activated
148 );
149 }
150
151 public function useCache(bool $a_status): void
152 {
153 $this->cache_enabled = $a_status;
154 }
155
156 public function isCacheUsed(): bool
157 {
159 }
160
161 public function setCacheMinutes(int $a_min): void
162 {
163 $this->cache_minutes = $a_min;
164 }
165
166 public function getCacheMinutes(): int
167 {
169 }
170
171 public function setEnabled(bool $a_enabled): void
172 {
173 $this->enabled = $a_enabled;
174 }
175
176 public function isEnabled(): bool
177 {
178 return $this->enabled;
179 }
180
181 public function setDefaultWeekStart(int $a_start): void
182 {
183 $this->week_start = $a_start;
184 }
185
186 public function getDefaultWeekStart(): int
187 {
188 return $this->week_start;
189 }
190
191 public function getDefaultCal(): int
192 {
193 return $this->default_cal;
194 }
195
196 public function setDefaultCal(int $default_cal): void
197 {
198 $this->default_cal = $default_cal;
199 }
200
201 public function getDefaultPeriod(): int
202 {
204 }
205
206 public function setDefaultPeriod(int $default_period): void
207 {
208 $this->default_period = $default_period;
209 }
210
211 public function setDefaultTimeZone(string $a_zone): void
212 {
213 $this->timezone = $a_zone;
214 }
215
216 public function getDefaultTimeZone(): string
217 {
218 return $this->timezone;
219 }
220
221 public function setDefaultDateFormat(int $a_format): void
222 {
223 $this->date_format = $a_format;
224 }
225
226 public function getDefaultDateFormat(): int
227 {
228 return $this->date_format;
229 }
230
231 public function setDefaultTimeFormat(int $a_format): void
232 {
233 $this->time_format = $a_format;
234 }
235
236 public function getDefaultTimeFormat(): int
237 {
238 return $this->time_format;
239 }
240
241 public function getDefaultDayStart(): int
242 {
243 return $this->day_start;
244 }
245
246 public function setDefaultDayStart(int $a_start): void
247 {
248 $this->day_start = $a_start;
249 }
250
251 public function getDefaultDayEnd(): int
252 {
253 return $this->day_end;
254 }
255
256 public function setDefaultDayEnd(int $a_end): void
257 {
258 $this->day_end = $a_end;
259 }
260
261 public function areConsultationHoursEnabled(): bool
262 {
264 }
265
266 public function enableConsultationHours(bool $a_status): void
267 {
268 $this->consultation_hours = $a_status;
269 }
270
271 public function getCalendarSettingsId(): int
272 {
274 }
275
276 public function setEnableGroupMilestones(bool $a_enablegroupmilestones): void
277 {
278 $this->enablegroupmilestones = $a_enablegroupmilestones;
279 }
280
281 public function getEnableGroupMilestones(): bool
282 {
284 }
285
286 public function isSynchronisationCacheEnabled(): bool
287 {
289 }
290
291 public function enableSynchronisationCache(bool $a_status): void
292 {
293 $this->sync_cache_enabled = $a_status;
294 }
295
296 public function setSynchronisationCacheMinutes(int $a_min): void
297 {
298 $this->sync_cache_minutes = $a_min;
299 }
300
302 {
304 }
305
306 public function isNotificationEnabled(): bool
307 {
308 return $this->notification;
309 }
310
311 public function enableNotification(bool $a_status): void
312 {
313 $this->notification = $a_status;
314 }
315
316 public function isUserNotificationEnabled(): bool
317 {
319 }
320
321 public function enableUserNotification(bool $a_not): void
322 {
323 $this->notification_user = $a_not;
324 }
325
326 public function enableCGRegistration(bool $a_status): void
327 {
328 $this->cg_registration = $a_status;
329 }
330
331 public function isCGRegistrationEnabled(): bool
332 {
334 }
335
336 public function enableCourseCalendar(bool $a_stat): void
337 {
338 $this->course_cal_enabled = $a_stat;
339 }
340
341 public function isCourseCalendarEnabled(): bool
342 {
344 }
345
346 public function isCourseCalendarVisible(): bool
347 {
349 }
350
351 public function setCourseCalendarVisible(bool $status): void
352 {
353 $this->course_cal_visible = $status;
354 }
355
356 public function isObjectCalendarVisible(string $type): bool
357 {
358 switch ($type) {
359 case 'crs':
360 return $this->isCourseCalendarVisible();
361 case 'grp':
362 return $this->isGroupCalendarVisible();
363 }
364 return false;
365 }
366
367 public function enableGroupCalendar(bool $a_stat): void
368 {
369 $this->group_cal_enabled = $a_stat;
370 }
371
372 public function isGroupCalendarEnabled(): bool
373 {
375 }
376
377 public function isGroupCalendarVisible(): bool
378 {
380 }
381
382 public function setGroupCalendarVisible(bool $status): void
383 {
384 $this->group_cal_visible = $status;
385 }
386
387 public function enableWebCalSync(bool $a_stat): void
388 {
389 $this->webcal_sync = $a_stat;
390 }
391
392 public function isWebCalSyncEnabled(): bool
393 {
394 return $this->webcal_sync;
395 }
396
397 public function setWebCalSyncHours(int $a_hours): void
398 {
399 $this->webcal_sync_hours = $a_hours;
400 }
401
402 public function getWebCalSyncHours(): int
403 {
405 }
406
407 public function setShowWeeks(bool $a_val): void
408 {
409 $this->show_weeks = $a_val;
410 }
411
412 public function getShowWeeks(): bool
413 {
414 return $this->show_weeks;
415 }
416
417 public function enableBatchFileDownloads(bool $a_stat): void
418 {
419 $this->batch_file_downloads = $a_stat;
420 }
421
422 public function isBatchFileDownloadsEnabled(): bool
423 {
425 }
426
427 public function save()
428 {
429 $this->storage->set('enabled', (string) (int) $this->isEnabled());
430 $this->storage->set('default_timezone', $this->getDefaultTimeZone());
431 $this->storage->set('default_week_start', (string) $this->getDefaultWeekStart());
432 $this->storage->set('default_date_format', (string) $this->getDefaultDateFormat());
433 $this->storage->set('default_time_format', (string) $this->getDefaultTimeFormat());
434 $this->storage->set('enable_grp_milestones', (string) (int) $this->getEnableGroupMilestones());
435 $this->storage->set('default_day_start', (string) $this->getDefaultDayStart());
436 $this->storage->set('default_day_end', (string) $this->getDefaultDayEnd());
437 $this->storage->set('cache_minutes', (string) $this->getCacheMinutes());
438 $this->storage->set('sync_cache_enabled', (string) (int) $this->isSynchronisationCacheEnabled());
439 $this->storage->set('sync_cache_minutes', (string) $this->getSynchronisationCacheMinutes());
440 $this->storage->set('cache_enabled', (string) (int) $this->isCacheUsed());
441 $this->storage->set('notification', (string) (int) $this->isNotificationEnabled());
442 $this->storage->set('consultation_hours', (string) (int) $this->areConsultationHoursEnabled());
443 $this->storage->set('cg_registration', (string) (int) $this->isCGRegistrationEnabled());
444 $this->storage->set('course_cal', (string) (int) $this->isCourseCalendarEnabled());
445 $this->storage->set('course_cal_visible', (string) (int) $this->isCourseCalendarVisible());
446 $this->storage->set('group_cal', (string) (int) $this->isGroupCalendarEnabled());
447 $this->storage->set('group_cal_visible', (string) (int) $this->isGroupCalendarVisible());
448 $this->storage->set('notification_user', (string) (int) $this->isUserNotificationEnabled());
449 $this->storage->set('webcal_sync', (string) (int) $this->isWebCalSyncEnabled());
450 $this->storage->set('webcal_sync_hours', (string) $this->getWebCalSyncHours());
451 $this->storage->set('show_weeks', (string) (int) $this->getShowWeeks());
452 $this->storage->set('batch_files', (string) (int) $this->isBatchFileDownloadsEnabled());
453 $this->storage->set('default_calendar_view', (string) $this->getDefaultCal());
454 $this->storage->set('default_period', (string) $this->getDefaultPeriod());
455 }
456
457 private function read()
458 {
459 $this->setEnabled((bool) $this->storage->get('enabled'));
460 $this->setDefaultTimeZone($this->storage->get('default_timezone', ilTimeZone::_getDefaultTimeZone()));
461 $this->setDefaultWeekStart((int) $this->storage->get('default_week_start', (string) self::WEEK_START_MONDAY));
462 $this->setDefaultDateFormat((int) $this->storage->get('default_date_format', (string) self::DATE_FORMAT_DMY));
463 $this->setDefaultTimeFormat((int) $this->storage->get('default_time_format', (string) self::TIME_FORMAT_24));
464 $this->setEnableGroupMilestones((bool) $this->storage->get('enable_grp_milestones'));
465 $this->setDefaultDayStart((int) $this->storage->get('default_day_start', (string) self::DEFAULT_DAY_START));
466 $this->setDefaultDayEnd((int) $this->storage->get('default_day_end', (string) self::DEFAULT_DAY_END));
467 $this->useCache((bool) $this->storage->get('cache_enabled', (string) $this->cache_enabled));
468 $this->setCacheMinutes((int) $this->storage->get('cache_minutes', (string) self::DEFAULT_CACHE_MINUTES));
469 $this->enableSynchronisationCache((bool) $this->storage->get(
470 'sync_cache_enabled',
471 (string) $this->isSynchronisationCacheEnabled()
472 ));
473 $this->setSynchronisationCacheMinutes((int) $this->storage->get(
474 'sync_cache_minutes',
475 (string) self::DEFAULT_SYNC_CACHE_MINUTES
476 ));
477 $this->enableNotification((bool) $this->storage->get('notification', (string) $this->isNotificationEnabled()));
478 $this->enableConsultationHours((bool) $this->storage->get(
479 'consultation_hours',
480 (string) $this->areConsultationHoursEnabled()
481 ));
482 $this->enableCGRegistration((bool) $this->storage->get(
483 'cg_registration',
484 (string) $this->isCGRegistrationEnabled()
485 ));
486 $this->enableCourseCalendar((bool) $this->storage->get(
487 'course_cal',
488 (string) $this->isCourseCalendarEnabled()
489 ));
490 $this->setCourseCalendarVisible((bool) $this->storage->get(
491 'course_cal_visible',
492 (string) $this->isCourseCalendarVisible()
493 ));
494 $this->enableGroupCalendar((bool) $this->storage->get('group_cal', (string) $this->isGroupCalendarEnabled()));
495 $this->setGroupCalendarVisible((bool) $this->storage->get(
496 'group_cal_visible',
497 (string) $this->isGroupCalendarVisible()
498 ));
499 $this->enableUserNotification((bool) $this->storage->get(
500 'notification_user',
501 (string) $this->isUserNotificationEnabled()
502 ));
503 $this->enableWebCalSync((bool) $this->storage->get('webcal_sync', (string) $this->isWebCalSyncEnabled()));
504 $this->setWebCalSyncHours((int) $this->storage->get('webcal_sync_hours', (string) $this->getWebCalSyncHours()));
505 $this->setShowWeeks((bool) $this->storage->get('show_weeks', (string) $this->getShowWeeks()));
506 $this->enableBatchFileDownloads((bool) $this->storage->get(
507 'batch_files',
508 (string) $this->isBatchFileDownloadsEnabled()
509 ));
510 $this->setDefaultCal((int) $this->storage->get('default_calendar_view', (string) $this->getDefaultCal()));
511 $this->setDefaultPeriod((int) $this->storage->get('default_period', (string) $this->getDefaultPeriod()));
512 }
513
514 private function readCalendarSettingsId(): void
515 {
516 $query = "SELECT ref_id FROM object_reference obr " .
517 "JOIN object_data obd ON obd.obj_id = obr.obj_id " .
518 "WHERE type = 'cals'";
519
520 $set = $this->db->query($query);
521 $row = $this->db->fetchAssoc($set);
522
523 $this->cal_settings_id = (int) $row["ref_id"];
524 }
525
526 private function initStorage()
527 {
528 $this->storage = new ilSetting('calendar');
529 }
530}
Stores all calendar relevant settings.
static lookupCalendarContentPresentationEnabled(int $obj_id)
setEnableGroupMilestones(bool $a_enablegroupmilestones)
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getDefaultTimeZone()
Calculate and set default time zone.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$query
$type