ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups 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  const TIME_FORMAT_24 = 1;
48  const TIME_FORMAT_12 = 2;
49 
52 
53 
54  private static $instance = null;
55 
56  private $db = null;
57  private $storage = null;
58  private $timezone = null;
59  private $time_format = null;
60  private $week_start = 0;
61  private $day_start = null;
62  private $day_end = null;
63  private $enabled = false;
64  private $cal_settings_id = 0;
65 
66  private $consultation_hours = false;
67 
68  private $cache_enabled = true;
69  private $cache_minutes = 1;
70 
71  private $sync_cache_enabled = true;
72  private $sync_cache_minutes = 10;
73 
74  private $notification = false;
75  private $notification_user = false;
76 
77  private $cg_registration = false;
78 
79  private $course_cal_enabled = true;
80  private $group_cal_enabled = true;
81 
82  private $webcal_sync = false;
83  private $webcal_sync_hours = 2;
84 
91  private function __construct()
92  {
93  global $ilDB;
94 
95  $this->db = $ilDB;
96 
97  $this->initStorage();
98  $this->read();
99  $this->readCalendarSettingsId();
100  }
101 
110  public static function _getInstance()
111  {
112  if(self::$instance)
113  {
114  return self::$instance;
115  }
116  return self::$instance = new ilCalendarSettings();
117  }
118 
123  public static function lookupCalendarActivated($a_obj_id)
124  {
126  {
127  return false;
128  }
129  $type = ilObject::_lookupType($a_obj_id);
130  // lookup global setting
131  $gl_activated = false;
132  switch($type)
133  {
134  case 'crs':
135  $gl_activated = ilCalendarSettings::_getInstance()->isCourseCalendarEnabled();
136  break;
137 
138  case 'grp':
139  $gl_activated = ilCalendarSettings::_getInstance()->isGroupCalendarEnabled();
140  break;
141 
142  default:
143  return false;
144  }
145  // look individual object setting
146  include_once './Services/Container/classes/class.ilContainer.php';
148  $a_obj_id,
149  'cont_show_calendar',
150  $gl_activated
151  );
152  }
153 
159  public function useCache($a_status)
160  {
161  $this->cache_enabled = $a_status;
162  }
163 
168  public function isCacheUsed()
169  {
170  return $this->cache_enabled;
171  }
172 
178  public function setCacheMinutes($a_min)
179  {
180  $this->cache_minutes = $a_min;
181  }
182 
187  public function getCacheMinutes()
188  {
189  return (int) $this->cache_minutes;
190  }
191 
198  public function setEnabled($a_enabled)
199  {
200  $this->enabled = $a_enabled;
201  }
202 
209  public function isEnabled()
210  {
211  return (bool) $this->enabled;
212  }
213 
220  public function setDefaultWeekStart($a_start)
221  {
222  $this->week_start = $a_start;
223  }
224 
231  public function getDefaultWeekStart()
232  {
233  return $this->week_start;
234  }
235 
241  public function setDefaultTimeZone($a_zone)
242  {
243  $this->timezone = $a_zone;
244  }
245 
251  public function getDefaultTimeZone()
252  {
253  return $this->timezone;
254  }
255 
263  public function setDefaultDateFormat($a_format)
264  {
265  $this->date_format = $a_format;
266  }
267 
274  public function getDefaultDateFormat()
275  {
276  return $this->date_format;
277  }
278 
286  public function setDefaultTimeFormat($a_format)
287  {
288  $this->time_format = $a_format;
289  }
290 
297  public function getDefaultTimeFormat()
298  {
299  return $this->time_format;
300  }
301 
306  public function getDefaultDayStart()
307  {
308  return $this->day_start;
309  }
310 
316  public function setDefaultDayStart($a_start)
317  {
318  $this->day_start = $a_start;
319  }
320 
325  public function getDefaultDayEnd()
326  {
327  return $this->day_end;
328  }
329 
335  public function setDefaultDayEnd($a_end)
336  {
337  $this->day_end = $a_end;
338  }
339 
344  public function areConsultationHoursEnabled()
345  {
347  }
348 
353  public function enableConsultationHours($a_status)
354  {
355  $this->consultation_hours = $a_status;
356  }
357 
358 
366  public function getCalendarSettingsId()
367  {
368  return $this->cal_settings_id;
369  }
370 
376  function setEnableGroupMilestones($a_enablegroupmilestones)
377  {
378  $this->enablegroupmilestones = $a_enablegroupmilestones;
379  }
380 
387  {
388  return $this->enablegroupmilestones;
389  }
390 
396  {
397  return (bool) $this->sync_cache_enabled;
398  }
399 
404  public function enableSynchronisationCache($a_status)
405  {
406  $this->sync_cache_enabled = $a_status;
407  }
408 
414  public function setSynchronisationCacheMinutes($a_min)
415  {
416  $this->sync_cache_minutes = $a_min;
417  }
418 
424  {
426  }
427 
432  public function isNotificationEnabled()
433  {
434  return (bool) $this->notification;
435  }
436 
442  public function enableNotification($a_status)
443  {
444  $this->notification = $a_status;
445  }
446 
447  public function isUserNotificationEnabled()
448  {
450  }
451 
452  public function enableUserNotification($a_not)
453  {
454  $this->notification_user = $a_not;
455  }
456 
462  public function enableCGRegistration($a_status)
463  {
464  $this->cg_registration = $a_status;
465  }
466 
467  public function isCGRegistrationEnabled()
468  {
469  return $this->cg_registration;
470  }
471 
472  public function enableCourseCalendar($a_stat)
473  {
474  $this->course_cal_enabled = $a_stat;
475  }
476 
477  public function isCourseCalendarEnabled()
478  {
480  }
481 
482  public function enableGroupCalendar($a_stat)
483  {
484  $this->group_cal_enabled = $a_stat;
485  }
486 
487  public function isGroupCalendarEnabled()
488  {
490  }
491 
492  public function enableWebCalSync($a_stat)
493  {
494  $this->webcal_sync = $a_stat;
495  }
496 
497  public function isWebCalSyncEnabled()
498  {
499  return $this->webcal_sync;
500  }
501 
502  public function setWebCalSyncHours($a_hours)
503  {
504  $this->webcal_sync_hours = $a_hours;
505  }
506 
507  public function getWebCalSyncHours()
508  {
510  }
511 
517  public function save()
518  {
519  $this->storage->set('enabled',(int) $this->isEnabled());
520  $this->storage->set('default_timezone',$this->getDefaultTimeZone());
521  $this->storage->set('default_week_start',$this->getDefaultWeekStart());
522  $this->storage->set('default_date_format',$this->getDefaultDateFormat());
523  $this->storage->set('default_time_format',$this->getDefaultTimeFormat());
524  $this->storage->set('enable_grp_milestones',(int) $this->getEnableGroupMilestones());
525  $this->storage->set('default_day_start',(int) $this->getDefaultDayStart());
526  $this->storage->set('default_day_end',(int) $this->getDefaultDayEnd());
527  $this->storage->set('cache_minutes',(int) $this->getCacheMinutes());
528  $this->storage->set('sync_cache_enabled',(int) $this->isSynchronisationCacheEnabled());
529  $this->storage->set('sync_cache_minutes',(int) $this->getSynchronisationCacheMinutes());
530  $this->storage->set('cache_enabled',(int) $this->isCacheUsed());
531  $this->storage->set('notification',(int) $this->isNotificationEnabled());
532  $this->storage->set('consultation_hours',(int) $this->areConsultationHoursEnabled());
533  $this->storage->set('cg_registration',(int) $this->isCGRegistrationEnabled());
534  $this->storage->set('course_cal',(int) $this->isCourseCalendarEnabled());
535  $this->storage->set('group_cal',(int) $this->isGroupCalendarEnabled());
536  $this->storage->set('notification_user',(int) $this->isUserNotificationEnabled());
537  $this->storage->set('webcal_sync',(int) $this->isWebCalSyncEnabled());
538  $this->storage->set('webcal_sync_hours',(int) $this->getWebCalSyncHours());
539  }
540 
548  private function read()
549  {
550  $this->setEnabled($this->storage->get('enabled'));
551  $this->setDefaultTimeZone($this->storage->get('default_timezone',ilTimeZone::_getDefaultTimeZone()));
552  $this->setDefaultWeekStart($this->storage->get('default_week_start',self::WEEK_START_MONDAY));
553  $this->setDefaultDateFormat($this->storage->get('default_date_format',self::DATE_FORMAT_DMY));
554  $this->setDefaultTimeFormat($this->storage->get('default_time_format',self::TIME_FORMAT_24));
555  $this->setEnableGroupMilestones($this->storage->get('enable_grp_milestones'));
556  $this->setDefaultDayStart($this->storage->get('default_day_start',self::DEFAULT_DAY_START));
557  $this->setDefaultDayEnd($this->storage->get('default_day_end',self::DEFAULT_DAY_END));
558  $this->useCache($this->storage->get('cache_enabled'),$this->cache_enabled);
559  $this->setCacheMinutes($this->storage->get('cache_minutes',self::DEFAULT_CACHE_MINUTES));
560  $this->enableSynchronisationCache($this->storage->get('sync_cache_enabled'),$this->isSynchronisationCacheEnabled());
561  $this->setSynchronisationCacheMinutes($this->storage->get('sync_cache_minutes',self::DEFAULT_SYNC_CACHE_MINUTES));
562  $this->enableNotification($this->storage->get('notification',$this->isNotificationEnabled()));
563  $this->enableConsultationHours($this->storage->get('consultation_hours',$this->areConsultationHoursEnabled()));
564  $this->enableCGRegistration($this->storage->get('cg_registration',$this->isCGRegistrationEnabled()));
565  $this->enableCourseCalendar($this->storage->get('course_cal',$this->isCourseCalendarEnabled()));
566  $this->enableGroupCalendar($this->storage->get('group_cal',$this->isGroupCalendarEnabled()));
567  $this->enableUserNotification($this->storage->get('notification_user',$this->isUserNotificationEnabled()));
568  $this->enableWebCalSync($this->storage->get('webcal_sync',$this->isWebCalSyncEnabled()));
569  $this->setWebCalSyncHours($this->storage->get('webcal_sync_hours',$this->getWebCalSyncHours()));
570  }
571 
579  private function readCalendarSettingsId()
580  {
581  global $ilDB;
582 
583  $query = "SELECT ref_id FROM object_reference obr ".
584  "JOIN object_data obd ON obd.obj_id = obr.obj_id ".
585  "WHERE type = 'cals'";
586 
587  $res = $this->db->query($query);
588  $row = $res->fetchRow();
589 
590  $this->cal_settings_id = $row[0];
591  return true;
592  }
593 
599  private function initStorage()
600  {
601  include_once('./Services/Administration/classes/class.ilSetting.php');
602  $this->storage = new ilSetting('calendar');
603  }
604 }
605 ?>