ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarUserSettings.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
10 {
11  public const CAL_SELECTION_MEMBERSHIP = 1;
12  public const CAL_SELECTION_ITEMS = 2;
13 
14  public const CAL_EXPORT_TZ_TZ = 1;
15  public const CAL_EXPORT_TZ_UTC = 2;
16 
17  public static array $instances = array();
18 
19  protected ilObjUser $user;
21 
22  private int $calendar_selection_type = 1;
23  private string $timezone = ilTimeZone::UTC;
24  private int $export_tz_type = self::CAL_EXPORT_TZ_TZ;
25  private int $weekstart = 0;
26  private int $time_format = 0;
27  private int $date_format = 0;
28 
29  private int $day_start = 0;
30  private int $day_end = 0;
31  private bool $show_weeks = true;
32 
33  private function __construct(int $a_user_id)
34  {
35  global $DIC;
36 
37  $this->user = $DIC->user();
38 
39  if ($this->user->getId() !== $a_user_id) {
40  $user = ilObjectFactory::getInstanceByObjId($a_user_id, false);
41  if ($user instanceof ilObjUser) {
42  $this->user = $user;
43  } else {
44  throw new DomainException('Invalid user id given: ' . $a_user_id);
45  }
46  }
48  $this->read();
49  }
50 
51  public static function _getInstanceByUserId(int $a_user_id): ilCalendarUserSettings
52  {
53  if (isset(self::$instances[$a_user_id])) {
54  return self::$instances[$a_user_id];
55  }
56  return self::$instances[$a_user_id] = new ilCalendarUserSettings($a_user_id);
57  }
58 
59  public static function _getInstance(): ilCalendarUserSettings
60  {
61  global $DIC;
62 
63  $ilUser = $DIC['ilUser'];
64  return self::_getInstanceByUserId($ilUser->getId());
65  }
66 
67  public function getTimeZone(): string
68  {
69  return $this->timezone;
70  }
71 
72  public function setTimeZone(string $a_tz): void
73  {
74  $this->timezone = $a_tz;
75  }
76 
77  public function getExportTimeZoneType(): int
78  {
79  return $this->export_tz_type;
80  }
81 
82  public function setExportTimeZoneType(int $a_type): void
83  {
84  $this->export_tz_type = $a_type;
85  }
86 
87  public function getExportTimeZone(): string
88  {
89  switch ($this->getExportTimeZoneType()) {
90  case self::CAL_EXPORT_TZ_TZ:
91  return $this->getTimeZone();
92 
93  case self::CAL_EXPORT_TZ_UTC:
94  return ilTimeZone::UTC;
95  }
96  return '';
97  }
98 
99  public function setWeekStart(int $a_weekstart): void
100  {
101  $this->weekstart = $a_weekstart;
102  }
103 
104  public function getWeekStart(): int
105  {
106  return $this->weekstart;
107  }
108 
109  public function setDayStart(int $a_start): void
110  {
111  $this->day_start = $a_start;
112  }
113 
114  public function getDayStart(): int
115  {
116  return $this->day_start;
117  }
118 
119  public function setDayEnd(int $a_end): void
120  {
121  $this->day_end = $a_end;
122  }
123 
124  public function getDayEnd(): int
125  {
126  return $this->day_end;
127  }
128 
129  public function setDateFormat(int $a_format): void
130  {
131  $this->date_format = $a_format;
132  }
133 
134  public function getDateFormat(): int
135  {
136  return $this->date_format;
137  }
138 
139  public function setTimeFormat(int $a_format): void
140  {
141  $this->time_format = $a_format;
142  }
143 
144  public function getTimeFormat(): int
145  {
146  return $this->time_format;
147  }
148 
153  public function getCalendarSelectionType(): int
154  {
156  }
157 
163  public function setCalendarSelectionType(int $a_type)
164  {
165  $this->calendar_selection_type = $a_type;
166  }
167 
168  public function setShowWeeks(bool $a_val): void
169  {
170  $this->show_weeks = $a_val;
171  }
172 
173  public function getShowWeeks(): bool
174  {
175  return $this->show_weeks;
176  }
177 
178  public function save()
179  {
180  $this->user->writePref('user_tz', $this->getTimeZone());
181  $this->user->writePref('export_tz_type', (string) $this->getExportTimeZoneType());
182  $this->user->writePref('weekstart', (string) $this->getWeekStart());
183  $this->user->writePref('date_format', (string) $this->getDateFormat());
184  $this->user->writePref('time_format', (string) $this->getTimeFormat());
185  $this->user->writePref('calendar_selection_type', (string) $this->getCalendarSelectionType());
186  $this->user->writePref('day_start', (string) $this->getDayStart());
187  $this->user->writePref('day_end', (string) $this->getDayEnd());
188  $this->user->writePref('show_weeks', (string) $this->getShowWeeks());
189  }
190 
191  protected function read(): void
192  {
193  $this->timezone = (string) $this->user->getTimeZone();
194  $this->export_tz_type = (int) (
195  ($this->user->getPref('export_tz_type') !== false) ?
196  $this->user->getPref('export_tz_type') :
198  );
199  $this->date_format = (int) $this->user->getDateFormat();
200  $this->time_format = (int) $this->user->getTimeFormat();
201  if (($weekstart = $this->user->getPref('weekstart')) === false) {
202  $weekstart = $this->settings->getDefaultWeekStart();
203  }
204  $this->calendar_selection_type = (int) $this->user->getPref('calendar_selection_type') ?
205  (int) $this->user->getPref('calendar_selection_type') :
206  self::CAL_SELECTION_MEMBERSHIP;
207 
208  $this->weekstart = (int) $weekstart;
209 
210  $this->setDayStart(
211  $this->user->getPref('day_start') ?
212  (int) $this->user->getPref('day_start') :
213  $this->settings->getDefaultDayStart()
214  );
215  $this->setDayEnd(
216  $this->user->getPref('day_end') ?
217  (int) $this->user->getPref('day_end') :
218  $this->settings->getDefaultDayEnd()
219  );
220  $this->setShowWeeks(
221  $this->user->getPref('show_weeks') !== null ?
222  (bool) $this->user->getPref('show_weeks') :
223  $this->settings->getShowWeeks()
224  );
225  }
226 }
setCalendarSelectionType(int $a_type)
set calendar selection type
static _getInstanceByUserId(int $a_user_id)
global $DIC
Definition: feed.php:28
getCalendarSelectionType()
get calendar selection type ("MyMembership" or "Selected Items")
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
$ilUser
Definition: imgupload.php:34