ILIAS  release_8 Revision v8.24
class.ilConsultationHoursGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use ILIAS\Refinery\Factory as RefineryFactory;
22use ILIAS\HTTP\Services as HttpServices;
23
30{
31 protected const MODE_CREATE = 1;
32 protected const MODE_UPDATE = 2;
33 protected const MODE_MULTI = 3;
34
35 protected const MAX_APPOINTMENTS_PER_SEQUENCE = 1000;
36
38 protected ilLanguage $lng;
41 protected ilHelpGUI $help;
42 protected ilTabsGUI $tabs;
44 protected RefineryFactory $refinery;
45 protected HttpServices $http;
46
47
48 private int $user_id;
50 private ?ilBookingEntry $booking = null;
51
52 private ?ilPropertyFormGUI $form = null;
53
57 public function __construct()
58 {
59 global $DIC;
60
61 $this->http = $DIC->http();
62 $this->refinery = $DIC->refinery();
63
64 $user_id = 0;
65 if ($this->http->wrapper()->query()->has('user_id')) {
66 $user_id = $this->http->wrapper()->query()->retrieve(
67 'user_id',
68 $this->refinery->kindlyTo()->int()
69 );
70 }
71 if ($user_id) {
72 if (in_array($user_id, array_keys(ilConsultationHourAppointments::getManagedUsers()))) {
73 $this->user_id = $user_id;
74 } else {
75 $user_id = false;
76 }
77 }
78 if (!$user_id) {
79 $this->user_id = $DIC->user()->getId();
80 }
81
82 $this->ctrl = $DIC->ctrl();
83 $this->lng = $DIC->language();
84 $this->tpl = $DIC->ui()->mainTemplate();
85 $this->help = $DIC->help();
86 $this->tabs = $DIC->tabs();
87 $this->toolbar = $DIC->toolbar();
88 $this->global_user = $DIC->user();
89 }
90
91 protected function initSearchAssignmentToAppointments($a_default = false): bool
92 {
93 $this->search_assignment_to_appointments = $a_default;
94 if ($this->http->wrapper()->query()->has('assignM')) {
95 $this->search_assignment_to_appointments = $this->http->wrapper()->query()->retrieve(
96 'assignM',
97 $this->refinery->kindlyTo()->bool()
98 );
99 }
101 }
102
103 protected function initGroupIdFromQuery(): int
104 {
105 if ($this->http->wrapper()->query()->has('grp_id')) {
106 return $this->http->wrapper()->query()->retrieve(
107 'grp_id',
108 $this->refinery->kindlyTo()->int()
109 );
110 }
111 return 0;
112 }
113
114 protected function initAppointmentIdsFromQuery(): array
115 {
116 if ($this->http->wrapper()->query()->has('apps')) {
117 return [$this->http->wrapper()->query()->retrieve('apps', $this->refinery->kindlyTo()->int())];
118 }
119 return [];
120 }
121
122 protected function initAppointmentIdsFromPost(): array
123 {
124 if ($this->http->wrapper()->post()->has('apps')) {
125 return $this->http->wrapper()->post()->retrieve(
126 'apps',
127 $this->refinery->kindlyTo()->dictOf(
128 $this->refinery->kindlyTo()->int()
129 )
130 );
131 }
132 return [];
133 }
134
135 protected function initAppointmentIdsFromPostString(): array
136 {
137 if ($this->http->wrapper()->post()->has('apps_string')) {
138 $app_string = $this->http->wrapper()->post()->retrieve(
139 'apps_string',
140 $this->refinery->kindlyTo()->string()
141 );
142 return array_map('intval', explode(';', $app_string));
143 }
144 return [];
145 }
146
147 protected function initGroupIdsFromPost(): array
148 {
149 if ($this->http->wrapper()->post()->has('groups')) {
150 return $this->http->wrapper()->post()->retrieve(
151 'groups',
152 $this->refinery->kindlyTo()->listOf(
153 $this->refinery->kindlyTo()->int()
154 )
155 );
156 }
157 return [];
158 }
159
163 protected function initBookingUsersFromPost(): array
164 {
165 if ($this->http->wrapper()->post()->has('bookuser')) {
166 return $this->http->wrapper()->post()->retrieve(
167 'bookuser',
168 $this->refinery->kindlyTo()->dictOf(
169 $this->refinery->kindlyTo()->string()
170 )
171 );
172 }
173 return [];
174 }
175
179 protected function initBookingUsersFromQuery(): array
180 {
181 if ($this->http->wrapper()->query()->has('bookuser')) {
182 return [
183 $this->http->wrapper()->query()->retrieve(
184 'bookuser',
185 $this->refinery->kindlyTo()->string()
186 )
187 ];
188 }
189 return [];
190 }
191
192 public function executeCommand(): void
193 {
194 $this->help->setScreenIdComponent("cal");
195 switch ($this->ctrl->getNextClass($this)) {
196 case "ilpublicuserprofilegui":
197 #22168 don't send the current user if no GET user_id
198 //$profile = new ilPublicUserProfileGUI($this->user_id);
199 $profile = new ilPublicUserProfileGUI();
200 $profile->setBackUrl($this->getProfileBackUrl());
201 $ret = $this->ctrl->forwardCommand($profile);
202 $this->tpl->setContent($ret);
203 break;
204
205 case 'ilrepositorysearchgui':
206 $rep_search = new ilRepositorySearchGUI();
208 $rep_search->setCallback(
209 $this,
210 'assignUsersToAppointments',
211 array()
212 );
213 $this->ctrl->setParameter($this, 'assignM', 1);
214 $this->ctrl->setReturn($this, 'appointmentList');
215 $this->tabs->activateSubTab('cal_ch_app_list');
216 } elseif ($this->initGroupIdFromQuery()) {
217 $rep_search->setCallback(
218 $this,
219 'assignUsersToGroup',
220 array()
221 );
222 $this->ctrl->saveParameter($this, 'grp_id');
223 $this->ctrl->setReturn($this, 'groupList');
224 $this->tabs->activateSubTab('cal_ch_app_grp');
225 } elseif (count($this->initAppointmentIdsFromPost())) {
226 $rep_search->setCallback(
227 $this,
228 'assignUsersToAppointment',
229 array()
230 );
231 $this->ctrl->saveParameter($this, 'apps');
232 $this->ctrl->setReturn($this, 'appointmentList');
233 $this->tabs->activateSubTab('cal_ch_app_list');
234 } elseif ($this->initAppointmentIdsFromQuery()) {
235 $rep_search->setCallback(
236 $this,
237 'assignUsersToAppointment',
238 array()
239 );
240 $this->ctrl->saveParameter($this, 'apps');
241 $this->ctrl->setReturn($this, 'appointmentList');
242 $this->tabs->activateSubTab('cal_ch_app_list');
243 }
244 $this->ctrl->forwardCommand($rep_search);
245 break;
246
247 default:
248 $this->tpl->setTitle($this->lng->txt("cal_ch_form_header")); // #12220
249
250 $this->setTabs();
251 if ($this->global_user->getId() != $this->user_id) {
252 $this->ctrl->setParameter($this, 'user_id', $this->user_id);
253 }
254 $cmd = $this->ctrl->getCmd('appointmentList');
255 $this->$cmd();
256 }
257 }
258
259 public function getUserId(): int
260 {
261 return $this->user_id;
262 }
263
264 protected function searchUsersForAppointments(): void
265 {
266 $apps = [];
267 if ($this->initAppointmentIdsFromPost() !== []) {
268 $apps = $this->initAppointmentIdsFromPost();
269 } elseif ($this->initAppointmentIdsFromQuery() !== []) {
270 $apps = $this->initAppointmentIdsFromQuery();
271 }
272
273 if ($apps === []) {
274 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
275 $this->ctrl->redirect($this, 'appointmentList');
276 }
277 ilSession::set('ch_apps', $apps);
278 $this->ctrl->setParameterByClass(ilConsultationHoursGUI::class, 'assignM', 1);
279 $this->ctrl->redirectByClass(ilRepositorySearchGUI::class, '');
280 }
281
286 protected function sendInfoAboutUnassignedUsers(array $unassigned): bool
287 {
288 if (!$unassigned) {
289 return true;
290 }
291 $users = array();
292 foreach ($unassigned as $user_id) {
294 }
295 $this->tpl->setOnScreenMessage('info', $this->lng->txt('cal_ch_user_assignment_failed_info') .
296 '<br />' . implode('<br />', $users), true);
297 return true;
298 }
299
303 public function assignUsersToAppointments(array $users)
304 {
305 $unassigned_users = [];
306 $ch_apps = (array) (ilSession::get('ch_apps') ?? []);
307 foreach ($ch_apps as $app) {
308 $unassigned_users = array_unique(array_merge(
309 $unassigned_users,
310 $this->assignUsersToAppointment($users, $app, false)
311 ));
312 }
313
314 $this->sendInfoAboutUnassignedUsers($unassigned_users);
315 $this->ctrl->redirect($this, 'appointmentList');
316 }
317
326 public function assignUsersToAppointment(array $users, int $a_app = 0, bool $a_redirect = true): array
327 {
328 if ($a_app) {
329 $app = $a_app;
330 } elseif ($this->initBookingUsersFromPost() !== []) {
332 $app = current($app);
333 } elseif ($this->initAppointmentIdsFromQuery() !== []) {
335 $app = current($app);
336 }
337 if (!count($users)) {
338 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
339 return [];
340 }
342 $assigned_users = array();
343 foreach ($users as $user) {
345 break;
346 }
347 if (!ilBookingEntry::lookupBookingsOfUser((array) $app, $user)) {
349 $assigned_users[] = $user;
350 }
351 }
352 $unassigned_users = array_diff($users, $assigned_users);
353 if ($a_redirect) {
354 $this->sendInfoAboutUnassignedUsers($unassigned_users);
355 $this->ctrl->redirect($this, 'appointmentList');
356 } else {
357 return $unassigned_users;
358 }
359 return [];
360 }
361
365 public function assignUsersToGroup(array $usr_ids): void
366 {
367 $group_id = $this->initGroupIdFromQuery();
368
369 $tomorrow = new ilDateTime(time(), IL_CAL_UNIX);
370 $tomorrow->increment(IL_CAL_DAY, 1);
371
372 // Get all future consultation hours
374 $this->user_id,
375 $group_id,
376 $tomorrow
377 );
378 $users = $usr_ids;
379 $assigned_users = array();
380 foreach ($apps as $app) {
382 foreach ($users as $user) {
384 break;
385 }
386 if (!ilBookingEntry::lookupBookingsOfUser($apps, $user)) {
388 $assigned_users[] = $user;
389 }
390 }
391 }
392
393 $this->sendInfoAboutUnassignedUsers(array_diff($users, $assigned_users));
394 $this->ctrl->redirect($this, 'bookingList');
395 }
396
400 protected function groupList(): void
401 {
402 $this->help->setScreenId("consultation_hours");
403
404 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
405 $this->toolbar->addButton($this->lng->txt('cal_ch_add_grp'), $this->ctrl->getLinkTarget($this, 'addGroup'));
406
407 $this->setSubTabs();
408 $this->tabs->activateSubTab('cal_ch_app_grp');
409
410 $gtbl = new ilConsultationHourGroupTableGUI($this, 'groupList', $this->getUserId());
412
413 $this->tpl->setContent($gtbl->getHTML());
414 }
415
419 protected function addGroup(?ilPropertyFormGUI $form = null): void
420 {
421 $this->setSubTabs();
422 $this->tabs->activateSubTab('cal_ch_app_grp');
423
424 if ($form == null) {
425 $form = $this->initGroupForm();
426 }
427 $this->tpl->setContent($form->getHTML());
428 }
429
433 protected function saveGroup(): void
434 {
435 $form = $this->initGroupForm();
436 if ($form->checkInput()) {
437 $group = new ilConsultationHourGroup();
438 $group->setTitle($form->getInput('title'));
439 $group->setMaxAssignments((int) $form->getInput('multiple'));
440 $group->setUserId($this->getUserId());
441 $group->save();
442
443 $this->tpl->setOnScreenMessage('success', $GLOBALS['DIC']['lng']->txt('settings_saved'), true);
444 $GLOBALS['DIC']['ilCtrl']->redirect($this, 'groupList');
445 }
446
447 $this->tpl->setOnScreenMessage('failure', $GLOBALS['DIC']['lng']->txt('err_check_input'), true);
448 $this->addGroup($form);
449 }
450
454 protected function editGroup(?ilPropertyFormGUI $form = null): void
455 {
456 $this->ctrl->setParameter($this, 'grp_id', $this->initGroupIdFromQuery());
457 $this->setSubTabs();
458 $this->tabs->activateSubTab('cal_ch_app_grp');
459
460 if ($form == null) {
461 $form = $this->initGroupForm($this->initGroupIdFromQuery());
462 }
463 $this->tpl->setContent($form->getHTML());
464 }
465
469 protected function updateGroup(): void
470 {
471 $group_id = $this->initGroupIdFromQuery();
472 $this->ctrl->setParameter($this, 'grp_id', $group_id);
473
474 $form = $this->initGroupForm($group_id);
475 if ($form->checkInput()) {
476 $group = new ilConsultationHourGroup($group_id);
477 $group->setTitle($form->getInput('title'));
478 $group->setMaxAssignments((int) $form->getInput('multiple'));
479 $group->setUserId($this->getUserId());
480 $group->update();
481
482 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
483 $this->ctrl->redirect($this, 'groupList');
484 }
485
486 $this->tpl->setOnScreenMessage('failure', $GLOBALS['DIC']['lng']->txt('err_check_input'), true);
487 $this->editGroup($form);
488 }
489
493 protected function confirmDeleteGroup(): void
494 {
495 $group_id = $this->initGroupIdFromQuery();
496 $this->ctrl->setParameter($this, 'grp_id', $group_id);
497 $groups = array($group_id);
498
499 $this->setSubTabs();
500 $this->tabs->activateSubTab('cal_ch_app_grp');
501 $confirm = new ilConfirmationGUI();
502 $confirm->setFormAction($this->ctrl->getFormAction($this));
503 $confirm->setHeaderText($GLOBALS['DIC']['lng']->txt('cal_ch_grp_delete_sure'));
504 $confirm->setConfirm($GLOBALS['DIC']['lng']->txt('delete'), 'deleteGroup');
505 $confirm->setCancel($GLOBALS['DIC']['lng']->txt('cancel'), 'groupList');
506
507 foreach ($groups as $grp_id) {
508 $group = new ilConsultationHourGroup($grp_id);
509
510 $confirm->addItem('groups[]', (string) $grp_id, $group->getTitle());
511 }
512 $this->tpl->setContent($confirm->getHTML());
513 }
514
518 protected function deleteGroup(): void
519 {
520 foreach ($this->initGroupIdsFromPost() as $grp_id) {
521 $group = new ilConsultationHourGroup($grp_id);
522 $group->delete();
523 }
524 $this->tpl->setOnScreenMessage('success', $this->lng->txt('cal_ch_grp_deleted'));
525 $this->ctrl->redirect($this, 'groupList');
526 }
527
528 protected function initGroupForm(int $a_group_id = 0): ilPropertyFormGUI
529 {
530 $group = new ilConsultationHourGroup($a_group_id);
531
532 $form = new ilPropertyFormGUI();
533 $form->setFormAction($GLOBALS['DIC']['ilCtrl']->getFormAction($this));
534
535 if ($a_group_id) {
536 $form->setTitle($GLOBALS['DIC']['lng']->txt('cal_ch_grp_update_tbl'));
537 $form->addCommandButton('updateGroup', $GLOBALS['DIC']['lng']->txt('save'));
538 $form->addCommandButton('groupList', $GLOBALS['DIC']['lng']->txt('cancel'));
539 } else {
540 $form->setTitle($GLOBALS['DIC']['lng']->txt('cal_ch_grp_add_tbl'));
541 $form->addCommandButton('saveGroup', $GLOBALS['DIC']['lng']->txt('save'));
542 $form->addCommandButton('appointmentList', $GLOBALS['DIC']['lng']->txt('cancel'));
543 }
544
545 $title = new ilTextInputGUI($GLOBALS['DIC']['lng']->txt('title'), 'title');
546 $title->setMaxLength(128);
547 $title->setSize(40);
548 $title->setRequired(true);
549 $title->setValue($group->getTitle());
550 $form->addItem($title);
551
552 $multiple = new ilNumberInputGUI($GLOBALS['DIC']['lng']->txt('cal_ch_grp_multiple'), 'multiple');
553 $multiple->setRequired(true);
554 $multiple->setMinValue(1);
555 $multiple->setSize(1);
556 $multiple->setMaxLength(2);
557 $multiple->setInfo($GLOBALS['DIC']['lng']->txt('cal_ch_grp_multiple_info'));
558 $multiple->setValue((string) $group->getMaxAssignments());
559 $form->addItem($multiple);
560
561 return $form;
562 }
563
567 protected function bookingList(): void
568 {
569 $this->help->setScreenId("consultation_hours");
570
571 $this->setSubTabs();
572 $this->tabs->activateSubTab('cal_ch_app_bookings');
573
574 $btable = new ilConsultationHourBookingTableGUI($this, 'bookingList', $this->getUserId());
576 $this->tpl->setContent($btable->getHTML());
577 }
578
582 protected function confirmDeleteBooking(): void
583 {
584 $this->confirmRejectBooking(false);
585 }
586
590 protected function confirmRejectBooking(bool $a_send_notification = true): void
591 {
592 $bookusers = [];
593 if ($this->initBookingUsersFromPost() !== []) {
594 $bookusers = $this->initBookingUsersFromPost();
595 } elseif ($this->initBookingUsersFromQuery() !== []) {
596 $bookusers = $this->initBookingUsersFromQuery();
597 }
598
599 if ($bookusers === []) {
600 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
601 $this->bookingList();
602 return;
603 }
604 $this->setSubTabs();
605 $this->tabs->activateSubTab('cal_ch_app_bookings');
606
607 $confirm = new ilConfirmationGUI();
608 $confirm->setFormAction($this->ctrl->getFormAction($this));
609
610 if ($a_send_notification) {
611 $this->tpl->setOnScreenMessage('info', $this->lng->txt('cal_ch_cancel_booking_info'));
612 $confirm->setHeaderText($this->lng->txt('cal_ch_cancel_booking_sure'));
613 $confirm->setConfirm($this->lng->txt('cal_ch_reject_booking'), 'rejectBooking');
614 } else {
615 $this->tpl->setOnScreenMessage('info', $this->lng->txt('cal_ch_delete_booking_info'));
616 $confirm->setHeaderText($this->lng->txt('cal_ch_delete_booking_sure'));
617 $confirm->setConfirm($this->lng->txt('cal_ch_delete_booking'), 'deleteBooking');
618 }
619
620 $confirm->setCancel($this->lng->txt('cancel'), 'bookingList');
621
622 foreach ($bookusers as $bookuser) {
623 $ids = explode('_', $bookuser);
624
625 $entry = new ilCalendarEntry((int) $ids[0]);
626 $confirm->addItem(
627 'bookuser[]',
628 $bookuser,
630 $ids[1],
631 true,
632 false,
633 '',
634 true,
635 true
636 ) . ', ' . ilDatePresentation::formatDate($entry->getStart())
637 );
638 }
639 $this->tpl->setContent($confirm->getHTML());
640 }
641
645 protected function deleteBooking(): void
646 {
647 $this->rejectBooking(false);
648 }
649
650 protected function rejectBooking(bool $a_send_notification = true): void
651 {
652 foreach ($this->initBookingUsersFromPost() as $bookuser) {
653 $ids = explode('_', $bookuser);
654 ilConsultationHourUtils::cancelBooking((int) $ids[1], (int) $ids[0], $a_send_notification);
655 }
656 if ($a_send_notification) {
657 $this->tpl->setOnScreenMessage('success', $this->lng->txt('cal_ch_canceled_bookings'), true);
658 } else {
659 $this->tpl->setOnScreenMessage('success', $this->lng->txt('cal_ch_deleted_bookings'), true);
660 }
661 $this->ctrl->redirect($this, 'bookingList');
662 }
663
668 protected function appointmentList(): void
669 {
670 $this->help->setScreenId("consultation_hours");
671
672 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
673 $this->toolbar->addButton(
674 $this->lng->txt('cal_ch_add_sequence'),
675 $this->ctrl->getLinkTarget($this, 'createSequence')
676 );
677
678 $this->setSubTabs();
679 $this->tabs->activateSubTab('cal_ch_app_list');
680
681 $tbl = new ilConsultationHoursTableGUI($this, 'appointmentList', $this->getUserId());
682 $tbl->parse();
683 $this->tpl->setContent($tbl->getHTML());
684 }
685
689 protected function createSequence(): void
690 {
691 $this->initFormSequence(self::MODE_CREATE);
692
693 $this->booking = new ilBookingEntry();
694 $this->form->getItemByPostVar('bo')->setValue((string) $this->booking->getNumberOfBookings());
695 $this->form->getItemByPostVar('ap')->setValue("1");
696 $this->form->getItemByPostVar('du')->setMinutes(15);
697 $this->form->getItemByPostVar('st')->setDate(
698 new ilDateTime(mktime(8, 0, 0, (int) date('n', time()), (int) date('d', time()), (int) date('Y', time())), IL_CAL_UNIX)
699 );
700 $this->tpl->setContent($this->form->getHTML());
701 }
702
706 protected function initFormSequence(int $a_mode): ilPropertyFormGUI
707 {
709
710 $this->form = new ilPropertyFormGUI();
711 $this->form->setFormAction($this->ctrl->getFormAction($this));
712
713 switch ($a_mode) {
715 $this->form->setTitle($this->lng->txt('cal_ch_add_sequence'));
716 $this->form->addCommandButton('saveSequence', $this->lng->txt('save'));
717 $this->form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
718 break;
719
720 case self::MODE_MULTI:
721 $this->form->setTitle($this->lng->txt('cal_ch_multi_edit_sequence'));
722 $this->form->addCommandButton('updateMulti', $this->lng->txt('save'));
723 $this->form->addCommandButton('appointmentList', $this->lng->txt('cancel'));
724 break;
725 }
726
727 // in case of existing groups show a selection
728 if (count($options = ilConsultationHourGroups::getGroupSelectOptions($this->getUserId()))) {
729 $group = new ilSelectInputGUI($this->lng->txt('cal_ch_grp_selection'), 'grp');
730 $group->setOptions($options);
731 $group->setRequired(false);
732 $this->form->addItem($group);
733 }
734
735 // Title
736 $ti = new ilTextInputGUI($this->lng->txt('title'), 'ti');
737 $ti->setSize(32);
738 $ti->setMaxLength(128);
739 $ti->setRequired(true);
740 $this->form->addItem($ti);
741
742 if ($a_mode != self::MODE_MULTI) {
743 // Start
744 $dur = new ilDateTimeInputGUI($this->lng->txt('cal_start'), 'st');
745 $dur->setShowTime(true);
746 $dur->setRequired(true);
747 $this->form->addItem($dur);
748
749 // Duration
750 $du = new ilDurationInputGUI($this->lng->txt('cal_ch_duration'), 'du');
751 $du->setShowMinutes(true);
752 $du->setShowHours(true);
753 $this->form->addItem($du);
754
755 // Number of appointments
756 $nu = new ilNumberInputGUI($this->lng->txt('cal_ch_num_appointments'), 'ap');
757 $nu->setInfo($this->lng->txt('cal_ch_num_appointments_info'));
758 $nu->setSize(2);
759 $nu->setMaxLength(2);
760 $nu->setRequired(true);
761 $nu->setMinValue(1);
762 $this->form->addItem($nu);
763
764 // Recurrence
765 $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'), 'frequence');
766 $rec->setEnabledSubForms(
767 array(
771 )
772 );
773 $this->form->addItem($rec);
774 }
775
776 // Number of bookings
777 $nu = new ilNumberInputGUI($this->lng->txt('cal_ch_num_bookings'), 'bo');
778 $nu->setSize(2);
779 $nu->setMaxLength(2);
780 $nu->setMinValue(1);
781 $nu->setRequired(true);
782 $this->form->addItem($nu);
783
784 // Deadline
785 $dead = new ilDurationInputGUI($this->lng->txt('cal_ch_deadline'), 'dead');
786 $dead->setInfo($this->lng->txt('cal_ch_deadline_info'));
787 $dead->setShowMinutes(false);
788 $dead->setShowHours(true);
789 $dead->setShowDays(true);
790 $this->form->addItem($dead);
791
792 // Location
793 $lo = new ilTextInputGUI($this->lng->txt('cal_where'), 'lo');
794 $lo->setSize(32);
795 $lo->setMaxLength(128);
796 $this->form->addItem($lo);
797
798 // Description
799 $de = new ilTextAreaInputGUI($this->lng->txt('description'), 'de');
800 $de->setRows(10);
801 $de->setCols(60);
802 $this->form->addItem($de);
803
804 // Target Object
805 $tgt = new ilTextInputGUI($this->lng->txt('cal_ch_target_object'), 'tgt');
806 $tgt->setInfo($this->lng->txt('cal_ch_target_object_info'));
807 $tgt->setSize(16);
808 $tgt->setMaxLength(128);
809 $this->form->addItem($tgt);
810 return $this->form;
811 }
812
816 protected function saveSequence(): void
817 {
818 $this->initFormSequence(self::MODE_CREATE);
819
820 if ($this->form->checkInput()) {
821 $this->form->setValuesByPost();
822
823 $booking = new ilBookingEntry();
824 $booking->setObjId($this->getUserId());
825 $booking->setNumberOfBookings((int) $this->form->getInput('bo'));
826
827 $deadline = $this->form->getInput('dead');
828 $deadline = $deadline['dd'] * 24 + $deadline['hh'];
829 $booking->setDeadlineHours($deadline);
830
831 // consultation hour group
833 $booking->setBookingGroup((int) $this->form->getInput('grp'));
834 }
835
836 $tgt = array_map('intval', explode(',', $this->form->getInput('tgt')));
837 $obj_ids = array();
838 foreach ($tgt as $ref_id) {
839 if ($ref_id === 0) {
840 continue;
841 }
843 $type = ilObject::_lookupType($obj_id);
844 $valid_types = array('crs', 'grp');
845 if (!$obj_id or !in_array($type, $valid_types)) {
846 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('cal_ch_unknown_repository_object'));
847 $this->tpl->setContent($this->form->getHTML());
848 return;
849 }
850
851 $obj_ids[] = $obj_id;
852 }
853 $booking->setTargetObjIds($obj_ids);
854 $booking->save();
855 $this->createAppointments($booking);
856 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
857 $this->ctrl->redirect($this, 'appointmentList');
858 } else {
859 $this->form->setValuesByPost();
860 $this->tpl->setContent($this->form->getHTML());
861 }
862 }
863
868 {
869 $concurrent_dates = new ilDateList(ilDateList::TYPE_DATETIME);
870 $start = clone $this->form->getItemByPostVar('st')->getDate();
871 for ($i = 0; $i < $this->form->getItemByPostVar('ap')->getValue(); $i++) {
872 $concurrent_dates->add(clone $start);
873
874 $start->increment(ilDateTime::MINUTE, $this->form->getItemByPostVar('du')->getMinutes());
875 $start->increment(ilDateTime::HOUR, $this->form->getItemByPostVar('du')->getHours());
876 #$start = new ilDateTime(,IL_CAL_UNIX);
877 }
878
881 $this->getUserId(),
882 $this->lng->txt('cal_ch_personal_ch'),
883 true
884 );
885
886 // Add calendar appointment for each
887
888 $num_appointments = 0;
889 foreach ($concurrent_dates as $dt) {
890 if ($num_appointments >= self::MAX_APPOINTMENTS_PER_SEQUENCE) {
891 break;
892 }
893
894 $end = clone $dt;
895 $end->increment(ilDateTime::MINUTE, $this->form->getItemByPostVar('du')->getMinutes());
896 $end->increment(ilDateTime::HOUR, $this->form->getItemByPostVar('du')->getHours());
897
899 new ilBookingPeriod($dt, $end),
900 $this->form->getItemByPostVar('frequence')->getRecurrence()
901 );
902
903 // Calculate with one year limit
904 $limit = clone $dt;
905 $limit->increment(ilDateTime::YEAR, 1);
906
907 $date_list = $calc->calculateDateList($dt, $limit);
908
909 $num = 0;
910 foreach ($date_list as $app_start) {
911 $app_end = clone $app_start;
912 $app_end->increment(ilDateTime::MINUTE, $this->form->getItemByPostVar('du')->getMinutes());
913 $app_end->increment(ilDateTime::HOUR, $this->form->getItemByPostVar('du')->getHours());
914
915 $entry = new ilCalendarEntry();
916 $entry->setContextId($booking->getId());
917 $entry->setTitle($this->form->getInput('ti'));
918 $entry->setSubtitle("#consultationhour#"); // dynamic, see ilCalendarEntry
919 $entry->setDescription($this->form->getInput('de'));
920 $entry->setLocation($this->form->getInput('lo'));
921 $entry->setStart($app_start);
922 $entry->setEnd($app_end);
923
924 $entry->setTranslationType(ilCalendarEntry::TRANSLATION_SYSTEM);
925 $entry->save();
926
927 $cat_assign = new ilCalendarCategoryAssignments($entry->getEntryId());
928 $cat_assign->addAssignment($def_cat->getCategoryID());
929
930 $num_appointments++;
931 }
932 }
933 }
934
935 protected function setTabs(): void
936 {
937 $this->ctrl->setParameter($this, 'user_id', '');
938 $this->tabs->addTab(
939 'consultation_hours_' . $this->user_id,
940 $this->lng->txt('cal_ch_ch'),
941 $this->ctrl->getLinkTarget($this, 'appointmentList')
942 );
943
945 $this->ctrl->setParameter($this, 'user_id', $user_id);
946 $this->tabs->addTab(
947 'consultation_hours_' . $user_id,
948 $this->lng->txt('cal_ch_ch') . ': ' . $login,
949 $this->ctrl->getLinkTarget($this, 'appointmentList')
950 );
951 }
952 $this->ctrl->setParameter($this, 'user_id', '');
953 $this->tabs->addTab('ch_settings', $this->lng->txt('settings'), $this->ctrl->getLinkTarget($this, 'settings'));
954 $this->tabs->activateTab('consultation_hours_' . $this->getUserId());
955 }
956
957 protected function setSubTabs(): void
958 {
959 $this->ctrl->setParameter($this, 'user_id', $this->getUserId());
960 $this->tabs->addSubTab(
961 'cal_ch_app_list',
962 $this->lng->txt('cal_ch_app_list'),
963 $this->ctrl->getLinkTarget($this, 'appointmentList')
964 );
965 $this->tabs->addSubTab(
966 'cal_ch_app_grp',
967 $this->lng->txt('cal_ch_app_grp'),
968 $this->ctrl->getLinkTarget($this, 'groupList')
969 );
970 $this->tabs->addSubTab(
971 'cal_ch_app_bookings',
972 $this->lng->txt('cal_ch_app_bookings'),
973 $this->ctrl->getLinkTarget($this, 'bookingList')
974 );
975 }
976
980 public function edit(): void
981 {
982 // first read from hidden input
983 $apps = [];
984 if ($this->initAppointmentIdsFromPostString() !== []) {
985 $apps = $this->initAppointmentIdsFromPostString();
986 } elseif ($this->initAppointmentIdsFromPost() !== []) {
987 $apps = $this->initAppointmentIdsFromPost();
988 } elseif ($this->initAppointmentIdsFromQuery()) {
989 $apps = $this->initAppointmentIdsFromQuery();
990 }
991 if (!count($apps)) {
992 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
993 $this->appointmentList();
994 return;
995 }
996
997 $this->initFormSequence(self::MODE_MULTI);
998 $hidden = new ilHiddenInputGUI('apps_string');
999 $hidden->setValue(implode(';', $apps));
1000 $this->form->addItem($hidden);
1001
1002 $first = $apps;
1003 $first = array_shift($apps);
1004 $entry = new ilCalendarEntry($first);
1005
1006 $this->form->getItemByPostVar('ti')->setValue($entry->getTitle());
1007 $this->form->getItemByPostVar('lo')->setValue($entry->getLocation());
1008 $this->form->getItemByPostVar('de')->setValue($entry->getDescription());
1009
1010 $booking = new ilBookingEntry($entry->getContextId());
1011
1012 $this->form->getItemByPostVar('bo')->setValue((string) $booking->getNumberOfBookings());
1013
1014 $ref_ids = array();
1015 foreach ($booking->getTargetObjIds() as $obj_id) {
1016 $refs = ilObject::_getAllReferences($obj_id);
1017 $ref_ids[] = end($refs);
1018 }
1019 $this->form->getItemByPostVar('tgt')->setValue(implode(',', $ref_ids));
1020
1021 $deadline = $booking->getDeadlineHours();
1022 $this->form->getItemByPostVar('dead')->setDays((int) floor($deadline / 24));
1023 $this->form->getItemByPostVar('dead')->setHours($deadline % 24);
1024
1025 if ($booking->getBookingGroup()) {
1026 $this->form->getItemByPostVar('grp')->setValue($booking->getBookingGroup());
1027 }
1028 $this->tpl->setContent($this->form->getHTML());
1029 }
1030
1031 protected function createNewBookingEntry(ilPropertyFormGUI $validate_form): ?ilBookingEntry
1032 {
1033 $booking = new \ilBookingEntry();
1034 $booking->setObjId($this->user_id);
1035 $booking->setNumberOfBookings((int) $this->form->getInput('bo'));
1036
1037 $deadline = $this->form->getInput('dead');
1038 $deadline = $deadline['dd'] * 24 + $deadline['hh'];
1039 $booking->setDeadlineHours($deadline);
1040
1041 $tgt = array_map('intval', explode(',', (string) $this->form->getInput('tgt')));
1042 $obj_ids = [];
1043 foreach ($tgt as $ref_id) {
1044 if ($ref_id === 0) {
1045 continue;
1046 }
1048 $type = ilObject::_lookupType($obj_id);
1049 $valid_types = ['crs', 'grp'];
1050 if (!$obj_id or !in_array($type, $valid_types)) {
1051 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('cal_ch_unknown_repository_object'));
1052 return null;
1053 }
1054 $obj_ids[] = $obj_id;
1055 }
1056 $booking->setTargetObjIds($obj_ids);
1057
1059 $booking->setBookingGroup((int) $this->form->getInput('grp'));
1060 }
1061 $booking->save();
1062 return $booking;
1063 }
1064
1067 array $appointments,
1069 ): void {
1070 foreach ($appointments as $appointment_id) {
1071 $booking_appointment = new \ilCalendarEntry($appointment_id);
1072 $booking_start = $booking_appointment->getStart();
1073 $booking_end = $booking_appointment->getEnd();
1074
1075 $deprecatedBooking = \ilBookingEntry::getInstanceByCalendarEntryId($appointment_id);
1076 if (!$deprecatedBooking instanceof \ilBookingEntry) {
1077 // @todo error handling
1078 continue;
1079 }
1080
1082 $deprecatedBooking,
1083 $booking_start,
1084 $booking_end
1085 );
1086 foreach ($relevant_appointments as $relevant_appointment_id) {
1087 $entry = new \ilCalendarEntry($relevant_appointment_id);
1088 $entry->setContextId($booking->getId());
1089 $entry->setTitle($form->getInput('ti'));
1090 $entry->setLocation($form->getInput('lo'));
1091 $entry->setDescription($form->getInput('de'));
1092 $entry->update();
1093 }
1094 }
1095 }
1096
1100 protected function updateMulti(): void
1101 {
1102 $this->initFormSequence(self::MODE_MULTI);
1103 if (!$this->form->checkInput()) {
1104 $this->form->setValuesByPost();
1105 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
1106 $this->edit();
1107 return;
1108 }
1109
1110 $this->form->setValuesByPost();
1111 $apps = $this->initAppointmentIdsFromPostString();
1112
1113 // create new booking
1114 $booking = $this->createNewBookingEntry($this->form);
1115 if (!$booking instanceof \ilBookingEntry) {
1116 $this->edit();
1117 return;
1118 }
1119 $this->rewriteBookingIdsForAppointments($booking, $apps, $this->form);
1121
1122 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1123 $this->ctrl->redirect($this, 'appointmentList');
1124 $this->tpl->setContent($this->form->getHTML());
1125 }
1126
1130 public function confirmDelete(): void
1131 {
1132 $apps = [];
1133 if ($this->initAppointmentIdsFromPost() !== []) {
1134 $apps = $this->initAppointmentIdsFromPost();
1135 } elseif ($this->initAppointmentIdsFromQuery() !== []) {
1136 $apps = $this->initAppointmentIdsFromQuery();
1137 }
1138 if ($apps === []) {
1139 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
1140 $this->appointmentList();
1141 return;
1142 }
1143
1144 $this->ctrl->saveParameter($this, array('seed', 'app_id', 'dt'));
1145 $confirm = new ilConfirmationGUI();
1146 $confirm->setFormAction($this->ctrl->getFormAction($this));
1147 $confirm->setHeaderText($this->lng->txt('cal_delete_app_sure'));
1148 $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
1149
1150 $bookings_available = array();
1151 foreach ($apps as $entry_id) {
1152 $entry = new ilCalendarEntry($entry_id);
1153 $confirm->addItem(
1154 'apps[]',
1155 (string) $entry_id,
1156 ilDatePresentation::formatDate($entry->getStart()) . ', ' . $entry->getTitle()
1157 );
1158
1160 $bookings_available[] = ilDatePresentation::formatDate($entry->getStart()) . ', ' . $entry->getTitle();
1161 }
1162 }
1163 if ($bookings_available) {
1164 $this->tpl->setOnScreenMessage('info', $this->lng->txt('cal_ch_delete_app_booking_info') . '<br />' . implode(
1165 '<br />',
1166 $bookings_available
1167 ));
1168 }
1169 $confirm->setConfirm($this->lng->txt('delete'), 'delete');
1170 $confirm->setCancel($this->lng->txt('cancel'), 'appointmentList');
1171 $this->tpl->setContent($confirm->getHTML());
1172 }
1173
1177 public function delete(): void
1178 {
1179 if (!count($this->initAppointmentIdsFromPost())) {
1180 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
1181 $this->appointmentList();
1182 return;
1183 }
1184 foreach ($this->initAppointmentIdsFromPost() as $entry_id) {
1185 // cancel booking for users
1187 if ($booking) {
1188 foreach ($booking->getCurrentBookings($entry_id) as $user_id) {
1189 ilConsultationHourUtils::cancelBooking($user_id, $entry_id, false);
1190 }
1191 }
1192 // remove calendar entries
1193 $entry = new ilCalendarEntry($entry_id);
1194 $entry->delete();
1196 }
1198 $this->tpl->setOnScreenMessage('success', $this->lng->txt('cal_deleted_app'), true);
1199 $this->ctrl->redirect($this, 'appointmentList');
1200 }
1201
1205 public function showProfile(): void
1206 {
1207 $this->tabs->clearTargets();
1208
1209 $user_id = 0;
1210 if ($this->http->wrapper()->query()->has('user')) {
1211 $user_id = $this->http->wrapper()->query()->retrieve(
1212 'user',
1213 $this->refinery->kindlyTo()->int()
1214 );
1215 }
1216 $profile = new ilPublicUserProfileGUI($user_id);
1217 $profile->setBackUrl($this->getProfileBackUrl());
1218 $this->tpl->setContent($this->ctrl->getHTML($profile));
1219 }
1220
1224 protected function getProfileBackUrl(): string
1225 {
1226 // from repository
1227 if ($this->http->wrapper()->query()->has('ref_id')) {
1228 $url = $this->ctrl->getLinkTargetByClass('ilCalendarMonthGUI');
1229 } // from panel
1230 elseif ($this->http->wrapper()->query()->has('panel')) {
1231 $url = $this->ctrl->getLinkTargetByClass('ilCalendarPresentationGUI');
1232 } // from appointments
1233 else {
1234 $url = $this->ctrl->getLinkTarget($this, 'appointmentList');
1235 }
1236 return $url;
1237 }
1238
1242 public function settings(): void
1243 {
1244 $this->help->setScreenId("consultation_hours_settings");
1245 $this->tabs->activateTab('ch_settings');
1246
1247 $form = $this->initSettingsForm();
1248 $this->tpl->setContent($form->getHTML());
1249 }
1250
1255 {
1256 $form = new ilPropertyFormGUI();
1257 $form->setFormAction($this->ctrl->getFormAction($this));
1258
1259 $mng = new ilTextInputGUI($this->lng->txt('cal_ch_manager'), 'mng');
1260 $mng->setInfo($this->lng->txt('cal_ch_manager_info'));
1261 $form->addItem($mng);
1262
1263 $mng->setValue(ilConsultationHourAppointments::getManager(true));
1264
1265 $form->setTitle($this->lng->txt('settings'));
1266 $form->addCommandButton('updateSettings', $this->lng->txt('save'));
1267 return $form;
1268 }
1269
1273 public function updateSettings(): void
1274 {
1275 $form = $this->initSettingsForm();
1276 if ($form->checkInput()) {
1277 $mng = $form->getInput('mng');
1279 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1280 $this->ctrl->redirect($this, 'settings');
1281 } else {
1282 $this->tabs->activateTab('ch_settings');
1283
1284 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('cal_ch_unknown_user'));
1285 $field = $form->getItemByPostVar('mng');
1286 $field->setValue($mng);
1287 $this->tpl->setContent($form->getHTML());
1288 return;
1289 }
1290 }
1291 }
1292}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
const IL_CAL_UNIX
const IL_CAL_DAY
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByCalendarEntryId(int $a_id)
Get instance by calendar entry.
getCurrentNumberOfBookings(int $a_entry_id)
get current number of bookings
static lookupBookingsOfUser(array $a_app_ids, int $a_usr_id, ?ilDateTime $start=null)
Lookup bookings of user.
static removeObsoleteEntries()
Remove unused booking entries.
setDeadlineHours(int $a_hours)
static lookupBookingsForAppointment(int $a_app_id)
Lookup booked users for appointment.
setTargetObjIds(?array $a_obj_id)
setNumberOfBookings(int $a_num)
Booking period Used for calculation of recurring events.
static _deleteByAppointmentId(int $a_app_id)
Delete appointment assignment.
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...
static initDefaultCalendarByType(int $a_type_id, int $a_usr_id, string $a_title, bool $a_create=false)
Init the default calendar for given type and user.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAppointmentIdsByGroup(int $a_user_id, int $a_ch_group_id, ?ilDateTime $start=null)
Get appointment ids by consultation hour group.
static getManagedUsers()
Get all managed consultation hours users for current users.
static setManager(string $a_user_name)
Set consultation hour manager for current user.
static getManager(bool $a_as_name=false, bool $a_full_name=false, int $a_user_id=null)
Get consultation hour manager for current user or specific user.
static getAppointmentIds(int $a_user_id, int $a_context_id=null, ?ilDateTime $a_start=null, ?int $a_type=null, bool $a_check_owner=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getGroupSelectOptions(int $a_user_id)
Get group selection options.
static getCountGroupsOfUser(int $a_user_id)
Get number of consultation hour groups.
static getGroupsOfUser(int $a_user_id)
Get a all groups of an user.
static cancelBooking(int $a_usr_id, int $a_app_id, bool $a_send_notification=true)
Cancel a booking.
static bookAppointment(int $a_usr_id, int $a_app_id)
Book an appointment.
static findCalendarAppointmentsForBooking(ilBookingEntry $booking, ilDateTime $start, ilDateTime $end)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addGroup(?ilPropertyFormGUI $form=null)
Show add group form.
editGroup(?ilPropertyFormGUI $form=null)
Edit group.
confirmDelete()
confirm delete for multiple entries
appointmentList()
Show settings of consultation hours.
groupList()
Show consultation hour group.
edit()
Edit multiple sequence items.
confirmRejectBooking(bool $a_send_notification=true)
Show delete booking confirmation.
rewriteBookingIdsForAppointments(ilBookingEntry $booking, array $appointments, ilPropertyFormGUI $form)
showProfile()
show public profile of given user
initSearchAssignmentToAppointments($a_default=false)
assignUsersToAppointments(array $users)
Assign users to multiple appointments.
bookingList()
Show list of bookings.
updateMulti()
Update multiple sequence items.
confirmDeleteBooking()
Show delete booking confirmation.
sendInfoAboutUnassignedUsers(array $unassigned)
Send info message about unassigned users.
assignUsersToAppointment(array $users, int $a_app=0, bool $a_redirect=true)
Assign users to an appointment.
ilGlobalTemplateInterface $tpl
createNewBookingEntry(ilPropertyFormGUI $validate_form)
createAppointments(ilBookingEntry $booking)
Create calendar appointments.
rejectBooking(bool $a_send_notification=true)
getProfileBackUrl()
Build context-sensitive profile back url.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
List of dates.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_formaction)
Help GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
This class represents a number property in a property form.
User class.
static _lookupFullname(int $a_user_id)
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
This class represents a property form user interface.
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
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 selection list property in a property form.
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text area property in a property form.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static initDomEvent(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI DomEvent used in Services/Calendar, Modules/Session, Modules/Test (Jan 2022)
$app
Definition: cli.php:39
global $DIC
Definition: feed.php:28
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...
$ref_id
Definition: ltiauth.php:67
$i
Definition: metadata.php:41
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd)
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:47
$type
$url