ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCalendarUserSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /*
5  +-----------------------------------------------------------------------------+
6  | ILIAS open source |
7  +-----------------------------------------------------------------------------+
8  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9  | |
10  | This program is free software; you can redistribute it and/or |
11  | modify it under the terms of the GNU General Public License |
12  | as published by the Free Software Foundation; either version 2 |
13  | of the License, or (at your option) any later version. |
14  | |
15  | This program is distributed in the hope that it will be useful, |
16  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18  | GNU General Public License for more details. |
19  | |
20  | You should have received a copy of the GNU General Public License |
21  | along with this program; if not, write to the Free Software |
22  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23  +-----------------------------------------------------------------------------+
24 */
25 
32 {
35  protected ilLanguage $lng;
36  protected ilObjUser $user;
39 
45  public function __construct()
46  {
47  global $DIC;
48 
49  $this->tpl = $DIC->ui()->mainTemplate();
50  $this->lng = $DIC->language();
51  $this->lng->loadLanguageModule('dateplaner');
52  $this->lng->loadLanguageModule('jscalendar');
53 
54  $this->ctrl = $DIC->ctrl();
55  $this->user = $DIC->user();
57  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
58  }
59 
60  public function executeCommand(): void
61  {
62  $next_class = $this->ctrl->getNextClass();
63  switch ($next_class) {
64  default:
65  $cmd = $this->ctrl->getCmd("show");
66  $this->$cmd();
67  break;
68  }
69  }
70 
71  public function show(?ilPropertyFormGUI $form = null): void
72  {
73  if (!$form instanceof ilPropertyFormGUI) {
74  $form = $this->initSettingsForm();
75  }
76  $this->tpl->setContent($form->getHTML());
77  }
78 
79  public function cancel(): void
80  {
81  $this->ctrl->returnToParent($this);
82  }
83 
84  public function save()
85  {
86  $form = $this->initSettingsForm();
87  if ($form->checkInput()) {
88  $this->user_settings->setTimeZone($form->getInput('timezone'));
89  $this->user_settings->setExportTimeZoneType((int) $form->getInput('export_tz'));
90  $this->user_settings->setWeekStart((int) $form->getInput('weekstart'));
91  $this->user_settings->setDateFormat((int) $form->getInput('date_format'));
92  $this->user_settings->setTimeFormat((int) $form->getInput('time_format'));
93  $this->user_settings->setDayStart((int) $form->getInput('dst'));
94  $this->user_settings->setDayEnd((int) $form->getInput('den'));
95  $this->user_settings->setShowWeeks((bool) $form->getInput('show_weeks'));
96  $this->user_settings->save();
97  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
98  $this->ctrl->redirect($this, "show");
99  } else {
100  $form->setValuesByPost();
101  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'), true);
102  $this->show();
103  }
104  }
105 
107  {
108  $form = new ilPropertyFormGUI();
109  $form->setFormAction($this->ctrl->getFormAction($this, 'save'));
110  $form->setTitle($this->lng->txt('cal_user_settings'));
111  $form->addCommandButton('save', $this->lng->txt('save'));
112  //$form->addCommandButton('cancel',$this->lng->txt('cancel'));
113 
114  $select = new ilSelectInputGUI($this->lng->txt('cal_user_timezone'), 'timezone');
115  $select->setOptions(ilCalendarUtil::_getShortTimeZoneList());
116  $select->setInfo($this->lng->txt('cal_timezone_info'));
117  $select->setValue($this->user_settings->getTimeZone());
118  $form->addItem($select);
119 
120  $export_type = new ilRadioGroupInputGUI($this->lng->txt('cal_export_timezone'), 'export_tz');
121  $export_type->setValue((string) $this->user_settings->getExportTimeZoneType());
122 
123  $export_tz = new ilRadioOption(
124  $this->lng->txt('cal_export_timezone_tz'),
126  );
127  $export_type->addOption($export_tz);
128  $export_utc = new ilRadioOption(
129  $this->lng->txt('cal_export_timezone_utc'),
131  );
132  $export_type->addOption($export_utc);
133  $form->addItem($export_type);
134 
135  $year = date("Y");
136  $select = new ilSelectInputGUI($this->lng->txt('cal_user_date_format'), 'date_format');
137  $select->setOptions(array(
138  ilCalendarSettings::DATE_FORMAT_DMY => '31.10.' . $year,
139  ilCalendarSettings::DATE_FORMAT_YMD => $year . "-10-31",
140  ilCalendarSettings::DATE_FORMAT_MDY => "10/31/" . $year
141  ));
142  $select->setInfo($this->lng->txt('cal_date_format_info'));
143  $select->setValue($this->user_settings->getDateFormat());
144  $form->addItem($select);
145 
146  $select = new ilSelectInputGUI($this->lng->txt('cal_user_time_format'), 'time_format');
147  $select->setOptions(array(
150  ));
151  $select->setInfo($this->lng->txt('cal_time_format_info'));
152  $select->setValue($this->user_settings->getTimeFormat());
153  $form->addItem($select);
154 
155  // Week/Month View
156  $week_month = new ilFormSectionHeaderGUI();
157  $week_month->setTitle($this->lng->txt('cal_week_month_view'));
158  $form->addItem($week_month);
159 
160  $radio = new ilRadioGroupInputGUI($this->lng->txt('cal_week_start'), 'weekstart');
161  $radio->setValue((string) $this->user_settings->getWeekStart());
162 
163  $option = new ilRadioOption($this->lng->txt('l_su'), "0");
164  $radio->addOption($option);
165  $option = new ilRadioOption($this->lng->txt('l_mo'), "1");
166  $radio->addOption($option);
167  $form->addItem($radio);
168 
169  if ($this->settings->getShowWeeks()) {
170  //
171  $cb = new ilCheckboxInputGUI($this->lng->txt("cal_usr_show_weeks"), "show_weeks");
172  $cb->setInfo($this->lng->txt("cal_usr_show_weeks_info"));
173  $cb->setValue("1");
174  $cb->setChecked($this->user_settings->getShowWeeks());
175  $form->addItem($cb);
176  }
177 
178  // Day/Week View
179  $week_month = new ilFormSectionHeaderGUI();
180  $week_month->setTitle($this->lng->txt('cal_day_week_view'));
181  $form->addItem($week_month);
182 
183  $day_start = new ilSelectInputGUI($this->lng->txt('cal_day_start'), 'dst');
184  $day_start->setOptions(
185  ilCalendarUtil::getHourSelection($this->user_settings->getTimeFormat())
186  );
187  $day_start->setValue($this->user_settings->getDayStart());
188  $form->addItem($day_start);
189 
190  $day_end = new ilSelectInputGUI($this->lng->txt('cal_day_end'), 'den');
191  $day_end->setOptions(
192  ilCalendarUtil::getHourSelection($this->user_settings->getTimeFormat())
193  );
194  $day_end->setValue($this->user_settings->getDayEnd());
195  $form->addItem($day_end);
196  return $form;
197  }
198 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
static _getShortTimeZoneList()
get short timezone list
static getHourSelection(int $a_format)
Get hour selection depending on user specific hour format.
static _getInstanceByUserId(int $a_user_id)
global $DIC
Definition: feed.php:28
This class represents a property in a property form.
show(?ilPropertyFormGUI $form=null)