ILIAS  Release_4_0_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  public static $instances = array();
17 
18  protected $user;
19  protected $settings;
20 
22  private $timezone;
23  private $weekstart;
24  private $time_format;
25 
26  private $day_start;
27  private $day_end;
28 
36  private function __construct($a_user_id)
37  {
38  global $ilUser;
39 
40  if($ilUser->getId() == $a_user_id)
41  {
42  $this->user = $ilUser;
43  }
44  else
45  {
46  $this->user = ilObjectFactory::getInstanceByObjId($a_user_id,false);
47  }
48  $this->settings = ilCalendarSettings::_getInstance();
49  $this->read();
50  }
51 
60  public static function _getInstanceByUserId($a_user_id)
61  {
62  if(isset(self::$instances[$a_user_id]))
63  {
64  return self::$instances[$a_user_id];
65  }
66  return self::$instances[$a_user_id] = new ilCalendarUserSettings($a_user_id);
67  }
68 
75  public static function _getInstance()
76  {
77  global $ilUser;
78 
79  return self::_getInstanceByUserId($ilUser->getId());
80  }
81 
89  public function getTimeZone()
90  {
91  return $this->timezone;
92  }
93 
101  public function setTimeZone($a_tz)
102  {
103  $this->timezone = $a_tz;
104  }
105 
113  public function setWeekStart($a_weekstart)
114  {
115  $this->weekstart = $a_weekstart;
116  }
117 
124  public function getWeekStart()
125  {
126  return (int) $this->weekstart;
127  }
128 
134  public function setDayStart($a_start)
135  {
136  $this->day_start = $a_start;
137  }
138 
143  public function getDayStart()
144  {
145  return $this->day_start;
146  }
147 
153  public function setDayEnd($a_end)
154  {
155  $this->day_end = $a_end;
156  }
157 
162  public function getDayEnd()
163  {
164  return $this->day_end;
165  }
166 
174  public function setTimeFormat($a_format)
175  {
176  $this->time_format = $a_format;
177  }
178 
185  public function getTimeFormat()
186  {
187  return $this->time_format;
188  }
189 
196  public function getCalendarSelectionType()
197  {
199  }
200 
206  public function setCalendarSelectionType($a_type)
207  {
208  $this->calendar_selection_type = $a_type;
209  }
210 
216  public function save()
217  {
218  $this->user->writePref('user_tz',$this->getTimeZone());
219  $this->user->writePref('weekstart',$this->getWeekStart());
220  $this->user->writePref('time_format',$this->getTimeFormat());
221  $this->user->writePref('calendar_selection_type',$this->getCalendarSelectionType());
222  $this->user->writePref('day_start',$this->getDayStart());
223  $this->user->writePref('day_end',$this->getDayEnd());
224  }
225 
226 
232  protected function read()
233  {
234  $this->timezone = $this->user->getTimeZone();
235  $this->time_format = $this->user->getTimeFormat();
236  if(($weekstart = $this->user->getPref('weekstart')) === false)
237  {
238  $weekstart = $this->settings->getDefaultWeekStart();
239  }
240  $this->calendar_selection_type = $this->user->getPref('calendar_selection_type') ?
241  $this->user->getPref('calendar_selection_type') :
243 
244  $this->weekstart = $weekstart;
245 
246  $this->setDayStart($this->user->getPref('day_start') !== false ?
247  $this->user->getPref('day_start') :
249  );
250  $this->setDayEnd($this->user->getPref('day_end') !== false ?
251  $this->user->getPref('day_end') :
253  );
254  }
255 
256 }
257 ?>