ILIAS  eassessment Revision 61809
 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  public static $instances = array();
17 
18  protected $user;
19  protected $settings;
20 
22  private $timezone;
23  private $weekstart;
24  private $time_format;
25  private $date_format;
26 
27  private $day_start;
28  private $day_end;
29 
37  private function __construct($a_user_id)
38  {
39  global $ilUser;
40 
41  if($ilUser->getId() == $a_user_id)
42  {
43  $this->user = $ilUser;
44  }
45  else
46  {
47  $this->user = ilObjectFactory::getInstanceByObjId($a_user_id,false);
48  }
49  $this->settings = ilCalendarSettings::_getInstance();
50  $this->read();
51  }
52 
61  public static function _getInstanceByUserId($a_user_id)
62  {
63  if(isset(self::$instances[$a_user_id]))
64  {
65  return self::$instances[$a_user_id];
66  }
67  return self::$instances[$a_user_id] = new ilCalendarUserSettings($a_user_id);
68  }
69 
76  public static function _getInstance()
77  {
78  global $ilUser;
79 
80  return self::_getInstanceByUserId($ilUser->getId());
81  }
82 
90  public function getTimeZone()
91  {
92  return $this->timezone;
93  }
94 
102  public function setTimeZone($a_tz)
103  {
104  $this->timezone = $a_tz;
105  }
106 
114  public function setWeekStart($a_weekstart)
115  {
116  $this->weekstart = $a_weekstart;
117  }
118 
125  public function getWeekStart()
126  {
127  return (int) $this->weekstart;
128  }
129 
135  public function setDayStart($a_start)
136  {
137  $this->day_start = $a_start;
138  }
139 
144  public function getDayStart()
145  {
146  return $this->day_start;
147  }
148 
154  public function setDayEnd($a_end)
155  {
156  $this->day_end = $a_end;
157  }
158 
163  public function getDayEnd()
164  {
165  return $this->day_end;
166  }
167 
175  public function setDateFormat($a_format)
176  {
177  $this->date_format = $a_format;
178  }
179 
186  public function getDateFormat()
187  {
188  return $this->date_format;
189  }
190 
198  public function setTimeFormat($a_format)
199  {
200  $this->time_format = $a_format;
201  }
202 
209  public function getTimeFormat()
210  {
211  return $this->time_format;
212  }
213 
220  public function getCalendarSelectionType()
221  {
223  }
224 
230  public function setCalendarSelectionType($a_type)
231  {
232  $this->calendar_selection_type = $a_type;
233  }
234 
240  public function save()
241  {
242  $this->user->writePref('user_tz',$this->getTimeZone());
243  $this->user->writePref('weekstart',$this->getWeekStart());
244  $this->user->writePref('date_format',$this->getDateFormat());
245  $this->user->writePref('time_format',$this->getTimeFormat());
246  $this->user->writePref('calendar_selection_type',$this->getCalendarSelectionType());
247  $this->user->writePref('day_start',$this->getDayStart());
248  $this->user->writePref('day_end',$this->getDayEnd());
249  }
250 
251 
257  protected function read()
258  {
259  $this->timezone = $this->user->getTimeZone();
260  $this->date_format = $this->user->getDateFormat();
261  $this->time_format = $this->user->getTimeFormat();
262  if(($weekstart = $this->user->getPref('weekstart')) === false)
263  {
264  $weekstart = $this->settings->getDefaultWeekStart();
265  }
266  $this->calendar_selection_type = $this->user->getPref('calendar_selection_type') ?
267  $this->user->getPref('calendar_selection_type') :
269 
270  $this->weekstart = $weekstart;
271 
272  $this->setDayStart($this->user->getPref('day_start') !== false ?
273  $this->user->getPref('day_start') :
275  );
276  $this->setDayEnd($this->user->getPref('day_end') !== false ?
277  $this->user->getPref('day_end') :
279  );
280  }
281 
282 }
283 ?>