ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjCalendarSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 {
29 
34  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
35  {
36  global $DIC;
37 
38  $this->type = 'cals';
39  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
40  $this->initCalendarSettings();
41 
42  $this->lng->loadLanguageModule('dateplaner');
43  $this->lng->loadLanguageModule('jscalendar');
44  }
45 
46  public function executeCommand(): void
47  {
48  $next_class = $this->ctrl->getNextClass($this);
49  $cmd = $this->ctrl->getCmd();
50 
51  $this->prepareOutput();
52 
53  if (!$this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
54  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
55  }
56 
57  switch ($next_class) {
58  case 'ilpermissiongui':
59  $this->tabs_gui->setTabActive('perm_settings');
60  $perm_gui = new ilPermissionGUI($this);
61  $ret = $this->ctrl->forwardCommand($perm_gui);
62  break;
63 
64  default:
65  $this->tabs_gui->setTabActive('settings');
66  $this->initCalendarSettings();
67  if (!$cmd || $cmd == 'view') {
68  $cmd = "settings";
69  }
70  $this->$cmd();
71  break;
72  }
73  }
74 
75  public function getAdminTabs(): void
76  {
77  if ($this->access->checkAccess("read", '', $this->object->getRefId())) {
78  $this->tabs_gui->addTarget(
79  "settings",
80  $this->ctrl->getLinkTarget($this, "settings"),
81  array("settings", "view")
82  );
83  }
84 
85  if ($this->access->checkAccess('edit_permission', '', $this->object->getRefId())) {
86  $this->tabs_gui->addTarget(
87  "perm_settings",
88  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm"),
89  array(),
90  'ilpermissiongui'
91  );
92  }
93  }
94 
95  public function settings(?ilPropertyFormGUI $form = null): void
96  {
97  if (!$this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
98  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
99  }
100  $this->tabs_gui->setTabActive('settings');
101  if (!$form instanceof ilPropertyFormGUI) {
102  $form = $this->initFormSettings();
103  }
104  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.settings.html', 'Services/Calendar');
105  $this->tpl->setVariable('CAL_SETTINGS', $form->getHTML());
106  }
107 
112  protected function save()
113  {
114  $this->checkPermission('write');
115 
116  $form = $this->initFormSettings();
117  if ($form->checkInput()) {
118  $this->calendar_settings->setEnabled((bool) $form->getInput('enable'));
119  $this->calendar_settings->setDefaultWeekStart((int) $form->getInput('default_week_start'));
120  $this->calendar_settings->setDefaultTimeZone($form->getInput('default_timezone'));
121  $this->calendar_settings->setDefaultDateFormat((int) $form->getInput('default_date_format'));
122  $this->calendar_settings->setDefaultTimeFormat((int) $form->getInput('default_time_format'));
123  $this->calendar_settings->setEnableGroupMilestones((bool) $form->getInput('enable_grp_milestones'));
124  $this->calendar_settings->enableCourseCalendar((bool) $form->getInput('enabled_crs'));
125  $this->calendar_settings->setCourseCalendarVisible((bool) $form->getInput('visible_crs'));
126  $this->calendar_settings->enableGroupCalendar((bool) $form->getInput('enabled_grp'));
127  $this->calendar_settings->setGroupCalendarVisible((bool) $form->getInput('visible_grp'));
128  $this->calendar_settings->setDefaultDayStart((int) $form->getInput('dst'));
129  $this->calendar_settings->setDefaultDayEnd((int) $form->getInput('den'));
130  $this->calendar_settings->enableSynchronisationCache((bool) $form->getInput('sync_cache'));
131  $this->calendar_settings->setSynchronisationCacheMinutes((int) $form->getInput('sync_cache_time'));
132  $this->calendar_settings->setCacheMinutes((int) $form->getInput('cache_time'));
133  $this->calendar_settings->useCache((bool) $form->getInput('cache'));
134  $this->calendar_settings->enableNotification((bool) $form->getInput('cn'));
135  $this->calendar_settings->enableUserNotification((bool) $form->getInput('cnu'));
136  $this->calendar_settings->enableConsultationHours((bool) $form->getInput('ch'));
137  $this->calendar_settings->enableCGRegistration((bool) $form->getInput('cgr'));
138  $this->calendar_settings->enableWebCalSync((bool) $form->getInput('webcal'));
139  $this->calendar_settings->setWebCalSyncHours((int) $form->getInput('webcal_hours'));
140  $this->calendar_settings->setShowWeeks((bool) $form->getInput('show_weeks'));
141  $this->calendar_settings->enableBatchFileDownloads((bool) $form->getInput('batch_files'));
142  $this->calendar_settings->setDefaultCal((int) $form->getInput('default_calendar_view'));
143  $this->calendar_settings->setDefaultPeriod((int) $form->getInput('default_period'));
144  $this->calendar_settings->save();
145  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
146  $this->ctrl->redirect($this, 'settings');
147  }
148  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'), true);
149  $this->settings($form);
150  }
151 
155  protected function initCalendarSettings(): void
156  {
157  $this->calendar_settings = ilCalendarSettings::_getInstance();
158  }
159 
164  protected function initFormSettings(): ilPropertyFormGUI
165  {
166  $form = new ilPropertyFormGUI();
167  $form->setFormAction($this->ctrl->getFormAction($this));
168  $form->setTitle($this->lng->txt('cal_global_settings'));
169 
170  if ($this->checkPermissionBool('write')) {
171  $form->addCommandButton('save', $this->lng->txt('save'));
172  }
173 
174  $check = new ilCheckboxInputGUI($this->lng->txt('enable_calendar'), 'enable');
175  $check->setValue('1');
176  $check->setChecked($this->calendar_settings->isEnabled() ? true : false);
177  $form->addItem($check);
178 
179  // show weeks
180  $cb = new ilCheckboxInputGUI($this->lng->txt("cal_def_show_weeks"), "show_weeks");
181  $cb->setInfo($this->lng->txt("cal_show_weeks_info"));
182  $cb->setValue('1');
183  $cb->setChecked($this->calendar_settings->getShowWeeks());
184  $form->addItem($cb);
185 
188  $form,
189  $this
190  );
191 
192  //Batch File Downloads in Calendar
193  $batch_files_download = new ilCheckboxInputGUI($this->lng->txt('cal_batch_file_downloads'), "batch_files");
194  $batch_files_download->setValue('1');
195  $batch_files_download->setChecked($this->calendar_settings->isBatchFileDownloadsEnabled());
196  $batch_files_download->setInfo($this->lng->txt('cal_batch_file_downloads_info'));
197  $form->addItem($batch_files_download);
198 
199  $def = new ilFormSectionHeaderGUI();
200  $def->setTitle($this->lng->txt('cal_default_settings'));
201  $form->addItem($def);
202 
203  $server_tz = new ilNonEditableValueGUI($this->lng->txt('cal_server_tz'));
205  $form->addItem($server_tz);
206 
207  $select = new ilSelectInputGUI($this->lng->txt('cal_def_timezone'), 'default_timezone');
208  $select->setOptions(ilCalendarUtil::_getShortTimeZoneList());
209  $select->setInfo($this->lng->txt('cal_def_timezone_info'));
210  $select->setValue($this->calendar_settings->getDefaultTimeZone());
211  $form->addItem($select);
212 
213  $year = date("Y");
214  $select = new ilSelectInputGUI($this->lng->txt('cal_def_date_format'), 'default_date_format');
215  $select->setOptions(array(
216  ilCalendarSettings::DATE_FORMAT_DMY => '31.10.' . $year,
217  ilCalendarSettings::DATE_FORMAT_YMD => $year . "-10-31",
218  ilCalendarSettings::DATE_FORMAT_MDY => "10/31/" . $year
219  ));
220  $select->setInfo($this->lng->txt('cal_def_date_format_info'));
221  $select->setValue($this->calendar_settings->getDefaultDateFormat());
222  $form->addItem($select);
223 
224  $select = new ilSelectInputGUI($this->lng->txt('cal_def_time_format'), 'default_time_format');
225  $select->setOptions(array(
228  ));
229  $select->setInfo($this->lng->txt('cal_def_time_format_info'));
230  $select->setValue($this->calendar_settings->getDefaultTimeFormat());
231  $form->addItem($select);
232 
233  // Weekstart
234  $radio = new ilRadioGroupInputGUI($this->lng->txt('cal_def_week_start'), 'default_week_start');
235  $radio->setValue((string) $this->calendar_settings->getDefaultWeekStart());
236 
237  $option = new ilRadioOption($this->lng->txt('l_su'), '0');
238  $radio->addOption($option);
239  $option = new ilRadioOption($this->lng->txt('l_mo'), '1');
240  $radio->addOption($option);
241 
242  $form->addItem($radio);
243 
244  $default_cal_view = new ilRadioGroupInputGUI($this->lng->txt('cal_def_view'), 'default_calendar_view');
245 
246  $option = new ilRadioOption($this->lng->txt("day"), (string) ilCalendarSettings::DEFAULT_CAL_DAY);
247  $default_cal_view->addOption($option);
248  $option = new ilRadioOption($this->lng->txt("week"), (string) ilCalendarSettings::DEFAULT_CAL_WEEK);
249  $default_cal_view->addOption($option);
250  $option = new ilRadioOption($this->lng->txt("month"), (string) ilCalendarSettings::DEFAULT_CAL_MONTH);
251  $default_cal_view->addOption($option);
252 
253  $option = new ilRadioOption($this->lng->txt("cal_list"), (string) ilCalendarSettings::DEFAULT_CAL_LIST);
254 
255  $list_views = new ilSelectInputGUI($this->lng->txt("cal_list"), "default_period");
256  $list_views->setOptions([
257  ilCalendarAgendaListGUI::PERIOD_DAY => "1 " . $this->lng->txt("day"),
258  ilCalendarAgendaListGUI::PERIOD_WEEK => "1 " . $this->lng->txt("week"),
259  ilCalendarAgendaListGUI::PERIOD_MONTH => "1 " . $this->lng->txt("month"),
260  ilCalendarAgendaListGUI::PERIOD_HALF_YEAR => "6 " . $this->lng->txt("months")
261  ]);
262 
263  $list_views->setValue($this->calendar_settings->getDefaultPeriod());
264  $option->addSubItem($list_views);
265  $default_cal_view->addOption($option);
266  $default_cal_view->setValue((string) $this->calendar_settings->getDefaultCal());
267 
268  $form->addItem($default_cal_view);
269 
270  // Day start
271  $day_start = new ilSelectInputGUI($this->lng->txt('cal_def_day_start'), 'dst');
272  $day_start->setOptions(
273  ilCalendarUtil::getHourSelection($this->calendar_settings->getDefaultTimeFormat())
274  );
275  $day_start->setValue($this->calendar_settings->getDefaultDayStart());
276  $form->addItem($day_start);
277 
278  $day_end = new ilSelectInputGUI($this->lng->txt('cal_def_day_end'), 'den');
279  $day_end->setOptions(
280  ilCalendarUtil::getHourSelection($this->calendar_settings->getDefaultTimeFormat())
281  );
282  $day_end->setValue($this->calendar_settings->getDefaultDayEnd());
283  $form->addItem($day_end);
284 
285  // enable milestone planning in groups
286  $mil = new ilFormSectionHeaderGUI();
287  $mil->setTitle($this->lng->txt('cal_milestone_settings'));
288  $form->addItem($mil);
289 
290  $checkm = new ilCheckboxInputGUI($this->lng->txt('cal_enable_group_milestones'), 'enable_grp_milestones');
291  $checkm->setValue('1');
292  $checkm->setChecked($this->calendar_settings->getEnableGroupMilestones());
293  $checkm->setInfo($this->lng->txt('cal_enable_group_milestones_desc'));
294  $form->addItem($checkm);
295 
296  // Consultation hours
297  $con = new ilFormSectionHeaderGUI();
298  $con->setTitle($this->lng->txt('cal_ch_form_header'));
299  $form->addItem($con);
300 
301  $ch = new ilCheckboxInputGUI($this->lng->txt('cal_ch_form'), 'ch');
302  $ch->setInfo($this->lng->txt('cal_ch_form_info'));
303  $ch->setValue('1');
304  $ch->setChecked($this->calendar_settings->areConsultationHoursEnabled());
305  $form->addItem($ch);
306 
307  // repository visibility default
308  $rep = new ilFormSectionHeaderGUI();
309  $rep->setTitle($GLOBALS['DIC']['lng']->txt('cal_setting_global_vis_repos'));
310  $form->addItem($rep);
311 
312  $crs_active = new ilCheckboxInputGUI(
313  $this->lng->txt('cal_setting_global_crs_act'),
314  'enabled_crs'
315  );
316  $crs_active->setInfo($this->lng->txt('cal_setting_global_crs_act_info'));
317  $crs_active->setValue('1');
318  $crs_active->setChecked($this->calendar_settings->isCourseCalendarEnabled());
319  $form->addItem($crs_active);
320 
321  $crs = new ilCheckboxInputGUI($GLOBALS['DIC']['lng']->txt('cal_setting_global_crs_vis'), 'visible_crs');
322  $crs->setInfo($GLOBALS['DIC']['lng']->txt('cal_setting_global_crs_vis_info'));
323  $crs->setValue('1');
324  $crs->setChecked($this->calendar_settings->isCourseCalendarVisible());
325  $crs_active->addSubItem($crs);
326 
327  $grp_active = new ilCheckboxInputGUI(
328  $this->lng->txt('cal_setting_global_grp_act'),
329  'enabled_grp'
330  );
331  $grp_active->setInfo($this->lng->txt('cal_setting_global_grp_act_info'));
332  $grp_active->setValue('1');
333  $grp_active->setChecked($this->calendar_settings->isGroupCalendarEnabled());
334  $form->addItem($grp_active);
335 
336  $grp = new ilCheckboxInputGUI($GLOBALS['DIC']['lng']->txt('cal_setting_global_grp_vis'), 'visible_grp');
337  $grp->setInfo($GLOBALS['DIC']['lng']->txt('cal_setting_global_grp_vis_info'));
338  $grp->setValue('1');
339  $grp->setInfo($GLOBALS['DIC']['lng']->txt('cal_setting_global_grp_vis_info'));
340  $grp->setChecked($this->calendar_settings->isGroupCalendarVisible());
341  $grp_active->addSubItem($grp);
342 
343  // Notifications
344  $not = new ilFormSectionHeaderGUI();
345  $not->setTitle($this->lng->txt('notifications'));
346  $form->addItem($not);
347 
348  $cgn = new ilCheckboxInputGUI($this->lng->txt('cal_notification'), 'cn');
349  $cgn->setOptionTitle($this->lng->txt('cal_notification_crsgrp'));
350  $cgn->setValue('1');
351  $cgn->setChecked($this->calendar_settings->isNotificationEnabled());
352  $cgn->setInfo($this->lng->txt('cal_adm_notification_info'));
353  $form->addItem($cgn);
354 
355  $cnu = new ilCheckboxInputGUI('', 'cnu');
356  $cnu->setOptionTitle($this->lng->txt('cal_notification_users'));
357  $cnu->setValue('1');
358  $cnu->setChecked($this->calendar_settings->isUserNotificationEnabled());
359  $cnu->setInfo($this->lng->txt('cal_adm_notification_user_info'));
360  $form->addItem($cnu);
361 
362  // Registration
363  $book = new ilFormSectionHeaderGUI();
364  $book->setTitle($this->lng->txt('cal_registrations'));
365  $form->addItem($book);
366 
367  $cgn = new ilCheckboxInputGUI($this->lng->txt('cal_cg_registrations'), 'cgr');
368  $cgn->setValue('1');
369  $cgn->setChecked($this->calendar_settings->isCGRegistrationEnabled());
370  $cgn->setInfo($this->lng->txt('cal_cg_registration_info'));
371  $form->addItem($cgn);
372 
373  // Synchronisation cache
374  $sec = new ilFormSectionHeaderGUI();
375  $sec->setTitle($this->lng->txt('cal_cache_settings'));
376  $form->addItem($sec);
377 
378  $cache = new ilRadioGroupInputGUI($this->lng->txt('cal_sync_cache'), 'sync_cache');
379  $cache->setValue((string) (int) $this->calendar_settings->isSynchronisationCacheEnabled());
380  $cache->setInfo($this->lng->txt('cal_sync_cache_info'));
381  $cache->setRequired(true);
382 
383  $sync_cache = new ilRadioOption($this->lng->txt('cal_sync_disabled'), '0');
384  $cache->addOption($sync_cache);
385 
386  $sync_cache = new ilRadioOption($this->lng->txt('cal_sync_enabled'), '1');
387  $cache->addOption($sync_cache);
388 
389  $cache_t = new ilNumberInputGUI('', 'sync_cache_time');
390  $cache_t->setValue((string) $this->calendar_settings->getSynchronisationCacheMinutes());
391  $cache_t->setMinValue(0);
392  $cache_t->setSize(3);
393  $cache_t->setMaxLength(3);
394  $cache_t->setSuffix($this->lng->txt('form_minutes'));
395  $sync_cache->addSubItem($cache_t);
396 
397  $form->addItem($cache);
398 
399  // Calendar cache
400  $cache = new ilRadioGroupInputGUI($this->lng->txt('cal_cache'), 'cache');
401  $cache->setValue((string) (int) $this->calendar_settings->isCacheUsed());
402  $cache->setInfo($this->lng->txt('cal_cache_info'));
403  $cache->setRequired(true);
404 
405  $sync_cache = new ilRadioOption($this->lng->txt('cal_cache_disabled'), '0');
406  $cache->addOption($sync_cache);
407 
408  $sync_cache = new ilRadioOption($this->lng->txt('cal_cache_enabled'), '1');
409  $cache->addOption($sync_cache);
410 
411  $cache_t = new ilNumberInputGUI('', 'cache_time');
412  $cache_t->setValue((string) $this->calendar_settings->getCacheMinutes());
413  $cache_t->setMinValue(0);
414  $cache_t->setSize(3);
415  $cache_t->setMaxLength(3);
416  $cache_t->setSuffix($this->lng->txt('form_minutes'));
417  $sync_cache->addSubItem($cache_t);
418  $form->addItem($cache);
419  return $form;
420  }
421 
422  public function addToExternalSettingsForm(int $a_form_id): array
423  {
424  switch ($a_form_id) {
426 
427  $this->initCalendarSettings();
428 
429  $fields = array();
430 
431  $subitems = array(
432  'cal_setting_global_crs_act' => [
433  $this->calendar_settings->isCourseCalendarEnabled(),
435  ],
436  'cal_setting_global_crs_vis' =>
437  array($this->calendar_settings->isCourseCalendarVisible(),
439  ),
440 
441  );
442  $fields['cal_setting_global_vis_repos'] = array(null, null, $subitems);
443 
444  $subitems = array(
445  'cal_notification_crsgrp' => array($this->calendar_settings->isNotificationEnabled(),
447  ),
448  'cal_notification_users' => array($this->calendar_settings->isUserNotificationEnabled(),
450  )
451  );
452  $fields['cal_notification'] = array(null, null, $subitems);
453 
454  $fields['cal_cg_registrations'] = array($this->calendar_settings->isCGRegistrationEnabled(),
456  );
457 
458  return array(array("settings", $fields));
459 
461 
462  $this->initCalendarSettings();
463 
464  $fields = array();
465 
466  $subitems = array(
467  'cal_setting_global_grp_act' => [
468  $this->calendar_settings->isGroupCalendarEnabled(),
470  ],
471  'cal_setting_global_grp_vis' =>
472  array($this->calendar_settings->isGroupCalendarVisible(),
474  ),
475 
476  );
477 
478  $fields['cal_setting_global_vis_repos'] = array(null, null, $subitems);
479 
480  $subitems = array(
481  'cal_notification_crsgrp' => array($this->calendar_settings->isNotificationEnabled(),
483  ),
484  'cal_notification_users' => array($this->calendar_settings->isUserNotificationEnabled(),
486  )
487  );
488  $fields['cal_notification'] = array(null, null, $subitems);
489 
490  $fields['cal_cg_registrations'] = array($this->calendar_settings->isCGRegistrationEnabled(),
492  );
493 
494  return array(array("settings", $fields));
495  }
496  return [];
497  }
498 }
static _getDefaultTimeZone()
Calculate and set default time zone.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
prepareOutput(bool $show_sub_objects=true)
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.
global $DIC
Definition: feed.php:28
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Constructor public.
This class represents a property in a property form.
settings(?ilPropertyFormGUI $form=null)
This class represents a number property in a property form.
Class ilObjectGUI Basic methods of all Output classes.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
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...
__construct(Container $dic, ilPlugin $plugin)
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
$check
Definition: buildRTE.php:81
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
initCalendarSettings()
init calendar settings
initFormSettings()
Init settings property form protected.
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
setOptionTitle(string $a_optiontitle)