ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarUserSettings.php
Go to the documentation of this file.
1 <?php
9 include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
10 
12 {
15 
16  const CAL_EXPORT_TZ_TZ = 1;
17  const CAL_EXPORT_TZ_UTC = 2;
18 
19  public static $instances = array();
20 
21  protected $user;
22  protected $settings;
23 
25  private $timezone;
27  private $weekstart;
28  private $time_format;
29  private $date_format;
30 
31  private $day_start;
32  private $day_end;
33 
41  private function __construct($a_user_id)
42  {
43  global $ilUser;
44 
45  if($ilUser->getId() == $a_user_id)
46  {
47  $this->user = $ilUser;
48  }
49  else
50  {
51  $this->user = ilObjectFactory::getInstanceByObjId($a_user_id,false);
52  }
53  $this->settings = ilCalendarSettings::_getInstance();
54  $this->read();
55  }
56 
65  public static function _getInstanceByUserId($a_user_id)
66  {
67  if(isset(self::$instances[$a_user_id]))
68  {
69  return self::$instances[$a_user_id];
70  }
71  return self::$instances[$a_user_id] = new ilCalendarUserSettings($a_user_id);
72  }
73 
80  public static function _getInstance()
81  {
82  global $ilUser;
83 
84  return self::_getInstanceByUserId($ilUser->getId());
85  }
86 
94  public function getTimeZone()
95  {
96  return $this->timezone;
97  }
98 
106  public function setTimeZone($a_tz)
107  {
108  $this->timezone = $a_tz;
109  }
110 
115  public function getExportTimeZoneType()
116  {
117  return $this->export_tz_type;
118  }
119 
124  public function setExportTimeZoneType($a_type)
125  {
126  $this->export_tz_type = $a_type;
127  }
128 
133  public function getExportTimeZone()
134  {
135  switch($this->getExportTimeZoneType())
136  {
137  case self::CAL_EXPORT_TZ_TZ:
138  return $this->getTimeZone();
139 
140  case self::CAL_EXPORT_TZ_UTC:
141  include_once './Services/Calendar/classes/class.ilTimeZone.php';
142  return ilTimeZone::UTC;
143  }
144  }
145 
146 
147 
155  public function setWeekStart($a_weekstart)
156  {
157  $this->weekstart = $a_weekstart;
158  }
159 
166  public function getWeekStart()
167  {
168  return (int) $this->weekstart;
169  }
170 
176  public function setDayStart($a_start)
177  {
178  $this->day_start = $a_start;
179  }
180 
185  public function getDayStart()
186  {
187  return $this->day_start;
188  }
189 
195  public function setDayEnd($a_end)
196  {
197  $this->day_end = $a_end;
198  }
199 
204  public function getDayEnd()
205  {
206  return $this->day_end;
207  }
208 
216  public function setDateFormat($a_format)
217  {
218  $this->date_format = $a_format;
219  }
220 
227  public function getDateFormat()
228  {
229  return $this->date_format;
230  }
231 
239  public function setTimeFormat($a_format)
240  {
241  $this->time_format = $a_format;
242  }
243 
250  public function getTimeFormat()
251  {
252  return $this->time_format;
253  }
254 
261  public function getCalendarSelectionType()
262  {
264  }
265 
271  public function setCalendarSelectionType($a_type)
272  {
273  $this->calendar_selection_type = $a_type;
274  }
275 
281  public function save()
282  {
283  $this->user->writePref('user_tz',$this->getTimeZone());
284  $this->user->writePref('export_tz_type',$this->getExportTimeZoneType());
285  $this->user->writePref('weekstart',$this->getWeekStart());
286  $this->user->writePref('date_format',$this->getDateFormat());
287  $this->user->writePref('time_format',$this->getTimeFormat());
288  $this->user->writePref('calendar_selection_type',$this->getCalendarSelectionType());
289  $this->user->writePref('day_start',$this->getDayStart());
290  $this->user->writePref('day_end',$this->getDayEnd());
291  }
292 
293 
299  protected function read()
300  {
301 
302 
303  $this->timezone = $this->user->getTimeZone();
304  $this->export_tz_type = (
305  ($this->user->getPref('export_tz_type') !== FALSE) ?
306  $this->user->getPref('export_tz_type') :
308  );
309  $this->date_format = $this->user->getDateFormat();
310  $this->time_format = $this->user->getTimeFormat();
311  if(($weekstart = $this->user->getPref('weekstart')) === false)
312  {
313  $weekstart = $this->settings->getDefaultWeekStart();
314  }
315  $this->calendar_selection_type = $this->user->getPref('calendar_selection_type') ?
316  $this->user->getPref('calendar_selection_type') :
318 
319  $this->weekstart = $weekstart;
320 
321  $this->setDayStart($this->user->getPref('day_start') !== false ?
322  $this->user->getPref('day_start') :
324  );
325  $this->setDayEnd($this->user->getPref('day_end') !== false ?
326  $this->user->getPref('day_end') :
328  );
329  }
330 
331 }
332 ?>