ILIAS  Release_3_10_x_branch Revision 61812
 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 TIME_FORMAT_24 = 1;
41  const TIME_FORMAT_12 = 2;
42 
43  private static $instance = null;
44 
45  private $db = null;
46  private $storage = null;
47  private $timezone = null;
48  private $time_format = null;
49  private $week_start = 0;
50  private $enabled = false;
51  private $cal_settings_id = 0;
52 
59  private function __construct()
60  {
61  global $ilDB;
62 
63  $this->db = $ilDB;
64 
65  $this->initStorage();
66  $this->read();
67  $this->readCalendarSettingsId();
68  }
69 
77  public static function _getInstance()
78  {
79  if(self::$instance)
80  {
81  return self::$instance;
82  }
83  return self::$instance = new ilCalendarSettings();
84  }
85 
92  public function setEnabled($a_enabled)
93  {
94  $this->enabled = $a_enabled;
95  }
96 
103  public function isEnabled()
104  {
105  return (bool) $this->enabled;
106  }
107 
114  public function setDefaultWeekStart($a_start)
115  {
116  $this->week_start = $a_start;
117  }
118 
125  public function getDefaultWeekStart()
126  {
127  return $this->week_start;
128  }
129 
135  public function setDefaultTimeZone($a_zone)
136  {
137  $this->timezone = $a_zone;
138  }
139 
145  public function getDefaultTimeZone()
146  {
147  return $this->timezone;
148  }
149 
157  public function setDefaultTimeFormat($a_format)
158  {
159  $this->time_format = $a_format;
160  }
161 
168  public function getDefaultTimeFormat()
169  {
170  return $this->time_format;
171  }
172 
180  public function getCalendarSettingsId()
181  {
182  return $this->cal_settings_id;
183  }
184 
185 
191  public function save()
192  {
193  $this->storage->set('enabled',(int) $this->isEnabled());
194  $this->storage->set('default_timezone',$this->getDefaultTimeZone());
195  $this->storage->set('default_week_start',$this->getDefaultWeekStart());
196  $this->storage->set('default_time_format',$this->getDefaultTimeFormat());
197  }
198 
206  private function read()
207  {
208  $this->setEnabled($this->storage->get('enabled'));
209  $this->setDefaultTimeZone($this->storage->get('default_timezone',ilTimeZone::_getDefaultTimeZone()));
210  $this->setDefaultWeekStart($this->storage->get('default_week_start',self::WEEK_START_MONDAY));
211  $this->setDefaultTimeFormat($this->storage->get('default_time_format',self::TIME_FORMAT_24));
212  }
213 
221  private function readCalendarSettingsId()
222  {
223  $query = "SELECT ref_id FROM object_reference AS obr ".
224  "JOIN object_data AS obd ON obd.obj_id = obr.obj_id ".
225  "WHERE type = 'cals'";
226 
227  $res = $this->db->query($query);
228  $row = $res->fetchRow();
229 
230  $this->cal_settings_id = $row[0];
231  return true;
232  }
233 
239  private function initStorage()
240  {
241  include_once('./Services/Administration/classes/class.ilSetting.php');
242  $this->storage = new ilSetting('calendar');
243  }
244 }
245 ?>