ILIAS  eassessment Revision 61809
 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 
76  private $cg_registration = false;
77 
84  private function __construct()
85  {
86  global $ilDB;
87 
88  $this->db = $ilDB;
89 
90  $this->initStorage();
91  $this->read();
92  $this->readCalendarSettingsId();
93  }
94 
102  public static function _getInstance()
103  {
104  if(self::$instance)
105  {
106  return self::$instance;
107  }
108  return self::$instance = new ilCalendarSettings();
109  }
110 
116  public function useCache($a_status)
117  {
118  $this->cache_enabled = $a_status;
119  }
120 
125  public function isCacheUsed()
126  {
127  return $this->cache_enabled;
128  }
129 
135  public function setCacheMinutes($a_min)
136  {
137  $this->cache_minutes = $a_min;
138  }
139 
144  public function getCacheMinutes()
145  {
146  return (int) $this->cache_minutes;
147  }
148 
155  public function setEnabled($a_enabled)
156  {
157  $this->enabled = $a_enabled;
158  }
159 
166  public function isEnabled()
167  {
168  return (bool) $this->enabled;
169  }
170 
177  public function setDefaultWeekStart($a_start)
178  {
179  $this->week_start = $a_start;
180  }
181 
188  public function getDefaultWeekStart()
189  {
190  return $this->week_start;
191  }
192 
198  public function setDefaultTimeZone($a_zone)
199  {
200  $this->timezone = $a_zone;
201  }
202 
208  public function getDefaultTimeZone()
209  {
210  return $this->timezone;
211  }
212 
220  public function setDefaultDateFormat($a_format)
221  {
222  $this->date_format = $a_format;
223  }
224 
231  public function getDefaultDateFormat()
232  {
233  return $this->date_format;
234  }
235 
243  public function setDefaultTimeFormat($a_format)
244  {
245  $this->time_format = $a_format;
246  }
247 
254  public function getDefaultTimeFormat()
255  {
256  return $this->time_format;
257  }
258 
263  public function getDefaultDayStart()
264  {
265  return $this->day_start;
266  }
267 
273  public function setDefaultDayStart($a_start)
274  {
275  $this->day_start = $a_start;
276  }
277 
282  public function getDefaultDayEnd()
283  {
284  return $this->day_end;
285  }
286 
292  public function setDefaultDayEnd($a_end)
293  {
294  $this->day_end = $a_end;
295  }
296 
301  public function areConsultationHoursEnabled()
302  {
304  }
305 
310  public function enableConsultationHours($a_status)
311  {
312  $this->consultation_hours = $a_status;
313  }
314 
315 
323  public function getCalendarSettingsId()
324  {
325  return $this->cal_settings_id;
326  }
327 
333  function setEnableGroupMilestones($a_enablegroupmilestones)
334  {
335  $this->enablegroupmilestones = $a_enablegroupmilestones;
336  }
337 
344  {
345  return $this->enablegroupmilestones;
346  }
347 
353  {
354  return (bool) $this->sync_cache_enabled;
355  }
356 
361  public function enableSynchronisationCache($a_status)
362  {
363  $this->sync_cache_enabled = $a_status;
364  }
365 
371  public function setSynchronisationCacheMinutes($a_min)
372  {
373  $this->sync_cache_minutes = $a_min;
374  }
375 
381  {
383  }
384 
389  public function isNotificationEnabled()
390  {
391  return (bool) $this->notification;
392  }
393 
399  public function enableNotification($a_status)
400  {
401  $this->notification = $a_status;
402  }
403 
409  public function enableCGRegistration($a_status)
410  {
411  $this->cg_registration = $a_status;
412  }
413 
414  public function isCGRegistrationEnabled()
415  {
416  return $this->cg_registration;
417  }
418 
424  public function save()
425  {
426  $this->storage->set('enabled',(int) $this->isEnabled());
427  $this->storage->set('default_timezone',$this->getDefaultTimeZone());
428  $this->storage->set('default_week_start',$this->getDefaultWeekStart());
429  $this->storage->set('default_date_format',$this->getDefaultDateFormat());
430  $this->storage->set('default_time_format',$this->getDefaultTimeFormat());
431  $this->storage->set('enable_grp_milestones',(int) $this->getEnableGroupMilestones());
432  $this->storage->set('default_day_start',(int) $this->getDefaultDayStart());
433  $this->storage->set('default_day_end',(int) $this->getDefaultDayEnd());
434  $this->storage->set('cache_minutes',(int) $this->getCacheMinutes());
435  $this->storage->set('sync_cache_enabled',(int) $this->isSynchronisationCacheEnabled());
436  $this->storage->set('sync_cache_minutes',(int) $this->getSynchronisationCacheMinutes());
437  $this->storage->set('cache_enabled',(int) $this->isCacheUsed());
438  $this->storage->set('notification',(int) $this->isNotificationEnabled());
439  $this->storage->set('consultation_hours',(int) $this->areConsultationHoursEnabled());
440  $this->storage->set('cg_registration',(int) $this->isCGRegistrationEnabled());
441  }
442 
450  private function read()
451  {
452  $this->setEnabled($this->storage->get('enabled'));
453  $this->setDefaultTimeZone($this->storage->get('default_timezone',ilTimeZone::_getDefaultTimeZone()));
454  $this->setDefaultWeekStart($this->storage->get('default_week_start',self::WEEK_START_MONDAY));
455  $this->setDefaultDateFormat($this->storage->get('default_date_format',self::DATE_FORMAT_DMY));
456  $this->setDefaultTimeFormat($this->storage->get('default_time_format',self::TIME_FORMAT_24));
457  $this->setEnableGroupMilestones($this->storage->get('enable_grp_milestones'));
458  $this->setDefaultDayStart($this->storage->get('default_day_start',self::DEFAULT_DAY_START));
459  $this->setDefaultDayEnd($this->storage->get('default_day_end',self::DEFAULT_DAY_END));
460  $this->useCache($this->storage->get('cache_enabled'),$this->cache_enabled);
461  $this->setCacheMinutes($this->storage->get('cache_minutes',self::DEFAULT_CACHE_MINUTES));
462  $this->enableSynchronisationCache($this->storage->get('sync_cache_enabled'),$this->isSynchronisationCacheEnabled());
463  $this->setSynchronisationCacheMinutes($this->storage->get('sync_cache_minutes',self::DEFAULT_SYNC_CACHE_MINUTES));
464  $this->enableNotification($this->storage->get('notification',$this->isNotificationEnabled()));
465  $this->enableConsultationHours($this->storage->get('consultation_hours',$this->areConsultationHoursEnabled()));
466  $this->enableCGRegistration($this->storage->get('cg_registration',$this->isCGRegistrationEnabled()));
467  }
468 
476  private function readCalendarSettingsId()
477  {
478  global $ilDB;
479 
480  $query = "SELECT ref_id FROM object_reference obr ".
481  "JOIN object_data obd ON obd.obj_id = obr.obj_id ".
482  "WHERE type = 'cals'";
483 
484  $res = $this->db->query($query);
485  $row = $res->fetchRow();
486 
487  $this->cal_settings_id = $row[0];
488  return true;
489  }
490 
496  private function initStorage()
497  {
498  include_once('./Services/Administration/classes/class.ilSetting.php');
499  $this->storage = new ilSetting('calendar');
500  }
501 }
502 ?>