ILIAS  Release_4_0_x_branch Revision 61816
 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 TIME_FORMAT_24 = 1;
44  const TIME_FORMAT_12 = 2;
45 
48 
49 
50  private static $instance = null;
51 
52  private $db = null;
53  private $storage = null;
54  private $timezone = null;
55  private $time_format = null;
56  private $week_start = 0;
57  private $day_start = null;
58  private $day_end = null;
59  private $enabled = false;
60  private $cal_settings_id = 0;
61 
62  private $cache_enabled = true;
63  private $cache_minutes = 1;
64 
65  private $sync_cache_enabled = true;
66  private $sync_cache_minutes = 10;
67 
74  private function __construct()
75  {
76  global $ilDB;
77 
78  $this->db = $ilDB;
79 
80  $this->initStorage();
81  $this->read();
82  $this->readCalendarSettingsId();
83  }
84 
92  public static function _getInstance()
93  {
94  if(self::$instance)
95  {
96  return self::$instance;
97  }
98  return self::$instance = new ilCalendarSettings();
99  }
100 
106  public function useCache($a_status)
107  {
108  $this->cache_enabled = $a_status;
109  }
110 
115  public function isCacheUsed()
116  {
117  return $this->cache_enabled;
118  }
119 
125  public function setCacheMinutes($a_min)
126  {
127  $this->cache_minutes = $a_min;
128  }
129 
134  public function getCacheMinutes()
135  {
136  return (int) $this->cache_minutes;
137  }
138 
145  public function setEnabled($a_enabled)
146  {
147  $this->enabled = $a_enabled;
148  }
149 
156  public function isEnabled()
157  {
158  return (bool) $this->enabled;
159  }
160 
167  public function setDefaultWeekStart($a_start)
168  {
169  $this->week_start = $a_start;
170  }
171 
178  public function getDefaultWeekStart()
179  {
180  return $this->week_start;
181  }
182 
188  public function setDefaultTimeZone($a_zone)
189  {
190  $this->timezone = $a_zone;
191  }
192 
198  public function getDefaultTimeZone()
199  {
200  return $this->timezone;
201  }
202 
210  public function setDefaultTimeFormat($a_format)
211  {
212  $this->time_format = $a_format;
213  }
214 
221  public function getDefaultTimeFormat()
222  {
223  return $this->time_format;
224  }
225 
230  public function getDefaultDayStart()
231  {
232  return $this->day_start;
233  }
234 
240  public function setDefaultDayStart($a_start)
241  {
242  $this->day_start = $a_start;
243  }
244 
249  public function getDefaultDayEnd()
250  {
251  return $this->day_end;
252  }
253 
259  public function setDefaultDayEnd($a_end)
260  {
261  $this->day_end = $a_end;
262  }
263 
264 
272  public function getCalendarSettingsId()
273  {
274  return $this->cal_settings_id;
275  }
276 
282  function setEnableGroupMilestones($a_enablegroupmilestones)
283  {
284  $this->enablegroupmilestones = $a_enablegroupmilestones;
285  }
286 
293  {
294  return $this->enablegroupmilestones;
295  }
296 
302  {
303  return (bool) $this->sync_cache_enabled;
304  }
305 
310  public function enableSynchronisationCache($a_status)
311  {
312  $this->sync_cache_enabled = $a_status;
313  }
314 
320  public function setSynchronisationCacheMinutes($a_min)
321  {
322  $this->sync_cache_minutes = $a_min;
323  }
324 
330  {
332  }
333 
339  public function save()
340  {
341  $this->storage->set('enabled',(int) $this->isEnabled());
342  $this->storage->set('default_timezone',$this->getDefaultTimeZone());
343  $this->storage->set('default_week_start',$this->getDefaultWeekStart());
344  $this->storage->set('default_time_format',$this->getDefaultTimeFormat());
345  $this->storage->set('enable_grp_milestones',(int) $this->getEnableGroupMilestones());
346  $this->storage->set('default_day_start',(int) $this->getDefaultDayStart());
347  $this->storage->set('default_day_end',(int) $this->getDefaultDayEnd());
348  $this->storage->set('cache_minutes',(int) $this->getCacheMinutes());
349  $this->storage->set('sync_cache_enabled',(int) $this->isSynchronisationCacheEnabled());
350  $this->storage->set('sync_cache_minutes',(int) $this->getSynchronisationCacheMinutes());
351  $this->storage->set('cache_enabled',(int) $this->isCacheUsed());
352  }
353 
361  private function read()
362  {
363  $this->setEnabled($this->storage->get('enabled'));
364  $this->setDefaultTimeZone($this->storage->get('default_timezone',ilTimeZone::_getDefaultTimeZone()));
365  $this->setDefaultWeekStart($this->storage->get('default_week_start',self::WEEK_START_MONDAY));
366  $this->setDefaultTimeFormat($this->storage->get('default_time_format',self::TIME_FORMAT_24));
367  $this->setEnableGroupMilestones($this->storage->get('enable_grp_milestones'));
368  $this->setDefaultDayStart($this->storage->get('default_day_start',self::DEFAULT_DAY_START));
369  $this->setDefaultDayEnd($this->storage->get('default_day_end',self::DEFAULT_DAY_END));
370  $this->useCache($this->storage->get('cache_enabled'),$this->cache_enabled);
371  $this->setCacheMinutes($this->storage->get('cache_minutes',self::DEFAULT_CACHE_MINUTES));
372  $this->enableSynchronisationCache($this->storage->get('sync_cache_enabled'),$this->isSynchronisationCacheEnabled());
373  $this->setSynchronisationCacheMinutes($this->storage->get('sync_cache_minutes',self::DEFAULT_SYNC_CACHE_MINUTES));
374  }
375 
383  private function readCalendarSettingsId()
384  {
385  global $ilDB;
386 
387  $query = "SELECT ref_id FROM object_reference obr ".
388  "JOIN object_data obd ON obd.obj_id = obr.obj_id ".
389  "WHERE type = 'cals'";
390 
391  $res = $this->db->query($query);
392  $row = $res->fetchRow();
393 
394  $this->cal_settings_id = $row[0];
395  return true;
396  }
397 
403  private function initStorage()
404  {
405  include_once('./Services/Administration/classes/class.ilSetting.php');
406  $this->storage = new ilSetting('calendar');
407  }
408 }
409 ?>