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