ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarSettings.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('Services/Calendar/classes/class.ilTimeZone.php');
25 
36 {
37  const WEEK_START_MONDAY = 1;
38  const WEEK_START_SUNDAY = 0;
39 
40  const DEFAULT_DAY_START = 8;
41  const DEFAULT_DAY_END = 19;
42 
43  const DATE_FORMAT_DMY = 1;
44  const DATE_FORMAT_YMD = 2;
45  const DATE_FORMAT_MDY = 3;
46 
47  public const DEFAULT_CAL_DAY = 1;
48  public const DEFAULT_CAL_WEEK = 2;
49  public const DEFAULT_CAL_MONTH = 3;
50  public const DEFAULT_CAL_LIST = 4;
51 
52  const TIME_FORMAT_24 = 1;
53  const TIME_FORMAT_12 = 2;
54 
57 
58  const DEFAULT_SHOW_WEEKS = true;
59 
60  private static $instance = null;
61 
62  private $db = null;
63  private $storage = null;
64  private $timezone = null;
65  private $time_format = null;
66  private $week_start = 0;
67  private $day_start = null;
68  private $day_end = null;
69  private $enabled = false;
70  private $cal_settings_id = 0;
71 
72  private $consultation_hours = false;
73  private $default_cal = self::DEFAULT_CAL_LIST;
74  private $default_period = 2;
75 
76  private $cache_enabled = true;
77  private $cache_minutes = 1;
78 
79  private $sync_cache_enabled = true;
80  private $sync_cache_minutes = 10;
81 
82  private $notification = false;
83  private $notification_user = false;
84 
85  private $cg_registration = false;
86 
87  private $course_cal_enabled = true;
88  private $group_cal_enabled = true;
89  private $course_cal_visible = true;
90  private $group_cal_visible = true;
91 
92  private $webcal_sync = false;
93  private $webcal_sync_hours = 2;
94  private $show_weeks = false;
95 
96  private $batch_file_downloads = false;
97 
104  private function __construct()
105  {
106  global $DIC;
107 
108  $ilDB = $DIC['ilDB'];
109 
110  $this->db = $ilDB;
111 
112  $this->initStorage();
113  $this->read();
114  $this->readCalendarSettingsId();
115  }
116 
124  public static function _getInstance()
125  {
126  if (self::$instance) {
127  return self::$instance;
128  }
129  return self::$instance = new ilCalendarSettings();
130  }
131 
136  public static function lookupCalendarContentPresentationEnabled(int $obj_id) : bool
137  {
138  if (!self::lookupCalendarActivated($obj_id)) {
139  return false;
140  }
141  $settings = self::_getInstance();
142  $type = ilObject::_lookupType($obj_id);
143  $default = $settings->isObjectCalendarVisible($type);
145  $obj_id,
146  'cont_show_calendar', // @todo create ilContainer constant
147  $default
148  );
149  }
150 
154  public static function lookupCalendarActivated($a_obj_id)
155  {
157  return false;
158  }
159  $type = ilObject::_lookupType($a_obj_id);
160  // lookup global setting
161  $gl_activated = false;
162  switch ($type) {
163  case 'crs':
164  $gl_activated = ilCalendarSettings::_getInstance()->isCourseCalendarEnabled();
165  break;
166 
167  case 'grp':
168  $gl_activated = ilCalendarSettings::_getInstance()->isGroupCalendarEnabled();
169  break;
170 
171  default:
172  return false;
173  }
174  // look individual object setting
175  include_once './Services/Container/classes/class.ilContainer.php';
177  $a_obj_id,
178  'cont_activation_calendar',
179  $gl_activated
180  );
181  }
182 
188  public function useCache($a_status)
189  {
190  $this->cache_enabled = $a_status;
191  }
192 
197  public function isCacheUsed()
198  {
199  return $this->cache_enabled;
200  }
201 
207  public function setCacheMinutes($a_min)
208  {
209  $this->cache_minutes = $a_min;
210  }
211 
216  public function getCacheMinutes()
217  {
218  return (int) $this->cache_minutes;
219  }
220 
227  public function setEnabled($a_enabled)
228  {
229  $this->enabled = $a_enabled;
230  }
231 
238  public function isEnabled()
239  {
240  return (bool) $this->enabled;
241  }
242 
249  public function setDefaultWeekStart($a_start)
250  {
251  $this->week_start = $a_start;
252  }
253 
260  public function getDefaultWeekStart()
261  {
262  return $this->week_start;
263  }
264 
265 
269  public function getDefaultCal() : int
270  {
271  return $this->default_cal;
272  }
273 
277  public function setDefaultCal(int $default_cal) : void
278  {
279  $this->default_cal = $default_cal;
280  }
281 
285  public function getDefaultPeriod() : int
286  {
287  return $this->default_period;
288  }
289 
293  public function setDefaultPeriod(int $default_period) : void
294  {
295  $this->default_period = $default_period;
296  }
297 
303  public function setDefaultTimeZone($a_zone)
304  {
305  $this->timezone = $a_zone;
306  }
307 
313  public function getDefaultTimeZone()
314  {
315  return $this->timezone;
316  }
317 
325  public function setDefaultDateFormat($a_format)
326  {
327  $this->date_format = $a_format;
328  }
329 
336  public function getDefaultDateFormat()
337  {
338  return $this->date_format;
339  }
340 
348  public function setDefaultTimeFormat($a_format)
349  {
350  $this->time_format = $a_format;
351  }
352 
359  public function getDefaultTimeFormat()
360  {
361  return $this->time_format;
362  }
363 
368  public function getDefaultDayStart()
369  {
370  return $this->day_start;
371  }
372 
378  public function setDefaultDayStart($a_start)
379  {
380  $this->day_start = $a_start;
381  }
382 
387  public function getDefaultDayEnd()
388  {
389  return $this->day_end;
390  }
391 
397  public function setDefaultDayEnd($a_end)
398  {
399  $this->day_end = $a_end;
400  }
401 
406  public function areConsultationHoursEnabled()
407  {
409  }
410 
415  public function enableConsultationHours($a_status)
416  {
417  $this->consultation_hours = $a_status;
418  }
419 
420 
428  public function getCalendarSettingsId()
429  {
430  return $this->cal_settings_id;
431  }
432 
438  public function setEnableGroupMilestones($a_enablegroupmilestones)
439  {
440  $this->enablegroupmilestones = $a_enablegroupmilestones;
441  }
442 
448  public function getEnableGroupMilestones()
449  {
450  return $this->enablegroupmilestones;
451  }
452 
458  {
459  return (bool) $this->sync_cache_enabled;
460  }
461 
466  public function enableSynchronisationCache($a_status)
467  {
468  $this->sync_cache_enabled = $a_status;
469  }
470 
476  public function setSynchronisationCacheMinutes($a_min)
477  {
478  $this->sync_cache_minutes = $a_min;
479  }
480 
486  {
488  }
489 
494  public function isNotificationEnabled()
495  {
496  return (bool) $this->notification;
497  }
498 
504  public function enableNotification($a_status)
505  {
506  $this->notification = $a_status;
507  }
508 
509  public function isUserNotificationEnabled()
510  {
512  }
513 
514  public function enableUserNotification($a_not)
515  {
516  $this->notification_user = $a_not;
517  }
518 
524  public function enableCGRegistration($a_status)
525  {
526  $this->cg_registration = $a_status;
527  }
528 
529  public function isCGRegistrationEnabled()
530  {
531  return $this->cg_registration;
532  }
533 
534  public function enableCourseCalendar($a_stat)
535  {
536  $this->course_cal_enabled = $a_stat;
537  }
538 
539  public function isCourseCalendarEnabled()
540  {
542  }
543 
544  public function isCourseCalendarVisible() : bool
545  {
547  }
548 
549  public function setCourseCalendarVisible(bool $status)
550  {
551  $this->course_cal_visible = $status;
552  }
553 
554  public function isObjectCalendarVisible(string $type) : bool
555  {
556  switch ($type) {
557  case 'crs':
558  return $this->isCourseCalendarVisible();
559  case 'grp':
560  return $this->isGroupCalendarVisible();
561  }
562  return false;
563  }
564 
565  public function enableGroupCalendar($a_stat)
566  {
567  $this->group_cal_enabled = $a_stat;
568  }
569 
570  public function isGroupCalendarEnabled()
571  {
573  }
574 
575  public function isGroupCalendarVisible() : bool
576  {
578  }
579 
580  public function setGroupCalendarVisible(bool $status)
581  {
582  $this->group_cal_visible = $status;
583  }
584 
585  public function enableWebCalSync($a_stat)
586  {
587  $this->webcal_sync = $a_stat;
588  }
589 
590  public function isWebCalSyncEnabled()
591  {
592  return $this->webcal_sync;
593  }
594 
595  public function setWebCalSyncHours($a_hours)
596  {
597  $this->webcal_sync_hours = $a_hours;
598  }
599 
600  public function getWebCalSyncHours()
601  {
603  }
604 
610  public function setShowWeeks($a_val)
611  {
612  $this->show_weeks = $a_val;
613  }
614 
620  public function getShowWeeks()
621  {
622  return $this->show_weeks;
623  }
624 
625  public function enableBatchFileDownloads($a_stat)
626  {
627  $this->batch_file_downloads = $a_stat;
628  }
629 
630  public function isBatchFileDownloadsEnabled()
631  {
633  }
634 
640  public function save()
641  {
642  $this->storage->set('enabled', (int) $this->isEnabled());
643  $this->storage->set('default_timezone', $this->getDefaultTimeZone());
644  $this->storage->set('default_week_start', $this->getDefaultWeekStart());
645  $this->storage->set('default_date_format', $this->getDefaultDateFormat());
646  $this->storage->set('default_time_format', $this->getDefaultTimeFormat());
647  $this->storage->set('enable_grp_milestones', (int) $this->getEnableGroupMilestones());
648  $this->storage->set('default_day_start', (int) $this->getDefaultDayStart());
649  $this->storage->set('default_day_end', (int) $this->getDefaultDayEnd());
650  $this->storage->set('cache_minutes', (int) $this->getCacheMinutes());
651  $this->storage->set('sync_cache_enabled', (int) $this->isSynchronisationCacheEnabled());
652  $this->storage->set('sync_cache_minutes', (int) $this->getSynchronisationCacheMinutes());
653  $this->storage->set('cache_enabled', (int) $this->isCacheUsed());
654  $this->storage->set('notification', (int) $this->isNotificationEnabled());
655  $this->storage->set('consultation_hours', (int) $this->areConsultationHoursEnabled());
656  $this->storage->set('cg_registration', (int) $this->isCGRegistrationEnabled());
657  $this->storage->set('course_cal', (int) $this->isCourseCalendarEnabled());
658  $this->storage->set('course_cal_visible', (int) $this->isCourseCalendarVisible());
659  $this->storage->set('group_cal', (int) $this->isGroupCalendarEnabled());
660  $this->storage->set('group_cal_visible', (int) $this->isGroupCalendarVisible());
661  $this->storage->set('notification_user', (int) $this->isUserNotificationEnabled());
662  $this->storage->set('webcal_sync', (int) $this->isWebCalSyncEnabled());
663  $this->storage->set('webcal_sync_hours', (int) $this->getWebCalSyncHours());
664  $this->storage->set('show_weeks', (int) $this->getShowWeeks());
665  $this->storage->set('batch_files', (int) $this->isBatchFileDownloadsEnabled());
666  $this->storage->set('default_calendar_view', (int) $this->getDefaultCal());
667  $this->storage->set('default_period', (int) $this->getDefaultPeriod());
668  }
669 
677  private function read()
678  {
679  $this->setEnabled($this->storage->get('enabled'));
680  $this->setDefaultTimeZone($this->storage->get('default_timezone', ilTimeZone::_getDefaultTimeZone()));
681  $this->setDefaultWeekStart($this->storage->get('default_week_start', self::WEEK_START_MONDAY));
682  $this->setDefaultDateFormat($this->storage->get('default_date_format', self::DATE_FORMAT_DMY));
683  $this->setDefaultTimeFormat($this->storage->get('default_time_format', self::TIME_FORMAT_24));
684  $this->setEnableGroupMilestones($this->storage->get('enable_grp_milestones'));
685  $this->setDefaultDayStart($this->storage->get('default_day_start', self::DEFAULT_DAY_START));
686  $this->setDefaultDayEnd($this->storage->get('default_day_end', self::DEFAULT_DAY_END));
687  $this->useCache($this->storage->get('cache_enabled'), $this->cache_enabled);
688  $this->setCacheMinutes($this->storage->get('cache_minutes', self::DEFAULT_CACHE_MINUTES));
689  $this->enableSynchronisationCache($this->storage->get('sync_cache_enabled'), $this->isSynchronisationCacheEnabled());
690  $this->setSynchronisationCacheMinutes($this->storage->get('sync_cache_minutes', self::DEFAULT_SYNC_CACHE_MINUTES));
691  $this->enableNotification($this->storage->get('notification', $this->isNotificationEnabled()));
692  $this->enableConsultationHours($this->storage->get('consultation_hours', $this->areConsultationHoursEnabled()));
693  $this->enableCGRegistration($this->storage->get('cg_registration', $this->isCGRegistrationEnabled()));
694  $this->enableCourseCalendar($this->storage->get('course_cal', $this->isCourseCalendarEnabled()));
695  $this->setCourseCalendarVisible($this->storage->get('course_cal_visible', $this->isCourseCalendarVisible()));
696  $this->enableGroupCalendar($this->storage->get('group_cal', $this->isGroupCalendarEnabled()));
697  $this->setGroupCalendarVisible($this->storage->get('group_cal_visible', $this->isGroupCalendarVisible()));
698  $this->enableUserNotification($this->storage->get('notification_user', $this->isUserNotificationEnabled()));
699  $this->enableWebCalSync($this->storage->get('webcal_sync', $this->isWebCalSyncEnabled()));
700  $this->setWebCalSyncHours($this->storage->get('webcal_sync_hours', $this->getWebCalSyncHours()));
701  $this->setShowWeeks($this->storage->get('show_weeks', $this->getShowWeeks()));
702  $this->enableBatchFileDownloads($this->storage->get('batch_files', $this->isBatchFileDownloadsEnabled()));
703  $this->setDefaultCal($this->storage->get('default_calendar_view', $this->getDefaultCal()));
704  $this->setDefaultPeriod($this->storage->get('default_period', $this->getDefaultPeriod()));
705  }
706 
714  private function readCalendarSettingsId()
715  {
716  $query = "SELECT ref_id FROM object_reference obr " .
717  "JOIN object_data obd ON obd.obj_id = obr.obj_id " .
718  "WHERE type = 'cals'";
719 
720  $set = $this->db->query($query);
721  $row = $this->db->fetchAssoc($set);
722 
723  $this->cal_settings_id = $row["ref_id"];
724  return true;
725  }
726 
732  private function initStorage()
733  {
734  include_once('./Services/Administration/classes/class.ilSetting.php');
735  $this->storage = new ilSetting('calendar');
736  }
737 }
getDefaultTimeFormat()
get default time format
static _getDefaultTimeZone()
Calculate and set default time zone.
getCacheMinutes()
Get cache minutes.
getDefaultTimeZone()
get derfault time zone
setSynchronisationCacheMinutes($a_min)
Set synchronisation cache minutes.
static _getInstance()
get singleton instance
getDefaultWeekStart()
get default week start
enableConsultationHours($a_status)
En/Disable consultation hours.
isNotificationEnabled()
Course group notification enabled.
isCacheUsed()
Check if cache is used.
$type
setShowWeeks($a_val)
Set show weeks.
setDefaultDayStart($a_start)
Set default start of day.
getShowWeeks()
Get show weeks.
setDefaultDateFormat($a_format)
set default date format
setEnableGroupMilestones($a_enablegroupmilestones)
Set Enable milestone planning feature for groups.
static lookupCalendarActivated($a_obj_id)
getDefaultDateFormat()
get default date format
setDefaultDayEnd($a_end)
set default end of day
setDefaultTimeFormat($a_format)
set default time format
getCalendarSettingsId()
Get calendar settings id (Used for permission checks)
getDefaultDayStart()
Get default end of day.
getSynchronisationCacheMinutes()
get synchronisation cache minutes
getDefaultDayEnd()
Get default end of day.
setCacheMinutes($a_min)
Set time of cache storage.
areConsultationHoursEnabled()
Check if consultation hours are enabled.
global $DIC
Definition: goto.php:24
setDefaultTimeZone($a_zone)
set default timezone
notification()
Definition: notification.php:2
$query
setEnabled($a_enabled)
set enabled
setCourseCalendarVisible(bool $status)
setDefaultPeriod(int $default_period)
static lookupCalendarContentPresentationEnabled(int $obj_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
enableSynchronisationCache($a_status)
En/Disable synchronisation cache.
isEnabled()
is calendar enabled
global $ilDB
getEnableGroupMilestones()
Get Enable milestone planning feature for groups.
setDefaultCal(int $default_cal)
enableNotification($a_status)
Enable course group notification.
readCalendarSettingsId()
Read ref_id of calendar settings.
__construct()
singleton contructor
useCache($a_status)
Enable cache.
enableCGRegistration($a_status)
Enable optional registration for courses and groups.
isSynchronisationCacheEnabled()
Check if cache is active for calendar synchronisation.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
initStorage()
Init storage class (ilSetting) private.
setDefaultWeekStart($a_start)
set week start