ILIAS  release_8 Revision v8.24
class.ilObjEmployeeTalkGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27
40{
41 private \ILIAS\DI\Container $container;
43 private bool $isReadonly;
46
47 public function __construct()
48 {
49 $this->container = $GLOBALS["DIC"];
50
51 $refId = $this->container
52 ->http()
53 ->wrapper()
54 ->query()
55 ->retrieve("ref_id", $this->container->refinery()->kindlyTo()->int());
56 parent::__construct([], $refId, true, false);
57
58 $this->container->language()->loadLanguageModule('mst');
59 $this->container->language()->loadLanguageModule('trac');
60 $this->container->language()->loadLanguageModule('etal');
61 $this->container->language()->loadLanguageModule('dateplaner');
62
63 $this->type = 'etal';
64
65 $this->setReturnLocation("save", strtolower(ilEmployeeTalkMyStaffListGUI::class));
66
67 $this->omitLocator();
68 $this->container->ui()->mainTemplate()->setTitle($this->container->language()->txt('mst_my_staff'));
69 $this->talkAccess = ilObjEmployeeTalkAccess::getInstance();
70 $this->repository = new IliasDBEmployeeTalkSeriesRepository($this->user, $this->container->database());
71 }
72
73 private function checkAccessOrFail(): void
74 {
75 if (!$this->talkAccess->canRead(intval($this->object->getRefId()))) {
76 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
77 $this->ctrl->redirectByClass(ilDashboardGUI::class, "");
78 }
79 }
80
81 public function executeCommand(): void
82 {
83 $this->checkAccessOrFail();
84 $this->isReadonly = !$this->talkAccess->canEdit(intval($this->object->getRefId()));
85
86 // determine next class in the call structure
87 $next_class = $this->container->ctrl()->getNextClass($this);
88
89 switch ($next_class) {
90 case 'ilpermissiongui':
91 parent::prepareOutput();
92 $this->tabs_gui->activateTab('perm_settings');
93 $ilPermissionGUI = new ilPermissionGUI($this);
94 $this->ctrl->forwardCommand($ilPermissionGUI);
95 break;
96 case 'ilinfoscreengui':
97 parent::prepareOutput();
98 $this->tabs_gui->activateTab('info_short');
99 $ilInfoScreenGUI = new ilInfoScreenGUI($this);
100 $this->ctrl->forwardCommand($ilInfoScreenGUI);
101 break;
102 case strtolower(ilRepositorySearchGUI::class):
103 $repo = new ilRepositorySearchGUI();
104 //TODO: Add user filter
106 //$repo->addUserAccessFilterCallable(function () {
107 // $orgUnitUser = ilOrgUnitUser::getInstanceById($this->container->user()->getId());
108 // $orgUnitUser->addPositions() ;
109 //});
110 $this->container->ctrl()->forwardCommand($repo);
111 break;
112 case strtolower(ilEmployeeTalkAppointmentGUI::class):
113 $appointmentGUI = new ilEmployeeTalkAppointmentGUI(
114 $this->tpl,
115 $this->lng,
116 $this->ctrl,
117 $this->container->http(),
118 $this->container->refinery(),
119 $this->container->tabs(),
120 $this->object
121 );
122 $this->container->ctrl()->forwardCommand($appointmentGUI);
123 break;
124 default:
125 parent::executeCommand();
126 }
127 }
128
129 public function editObject(): void
130 {
131 $this->tabs_gui->activateTab('view_content');
132
133 $form = $this->initEditForm();
134 $values = $this->getEditFormValues();
135 if ($values) {
136 $form->setValuesByArray($values);
137 }
138
139 $this->addExternalEditFormCustom($form);
140
141 $this->tpl->setContent($form->getHTML());
142 }
143
144 protected function validateCustom(ilPropertyFormGUI $a_form): bool
145 {
146 $refId = intval($this->object->getRefId());
147 $settings = $this->repository->readEmployeeTalkSerieSettings(intval($this->object->getId()));
148 $oldLockSettings = $settings->isLockedEditing();
149 $lockEdititngForOthers = boolval(
150 intval($a_form->getInput('etal_settings_locked_for_others'))
151 );
152 if ($oldLockSettings === $lockEdititngForOthers) {
153 return true;
154 }
155
156 return $this->talkAccess->canEditTalkLockStatus($refId);
157 }
158
159 public function updateObject(): void
160 {
161 $form = $this->initEditForm();
162 $this->addExternalEditFormCustom($form);
163 if ($form->checkInput() &&
164 $this->validateCustom($form) &&
165 !$this->isReadonly) {
166 $this->object->setTitle($form->getInput("title"));
167 $this->object->setDescription($form->getInput("desc"));
168 $this->updateCustom($form);
169 $this->object->update();
170
171 $this->afterUpdate();
172 return;
173 }
174
175 // display form again to correct errors
176 $this->tabs_gui->activateTab("view_content");
178 $this->tpl->setContent($form->getHtml());
179 }
180
181 public function confirmedDeleteObject(): void
182 {
183 if (!$this->talkAccess->canDelete($this->ref_id)) {
184 ilSession::clear("saved_post");
185 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
186 $this->ctrl->redirectByClass(strtolower(ilEmployeeTalkMyStaffListGUI::class), ControlFlowCommand::DEFAULT, "", false);
187
188 return;
189 }
190
191 if ($this->post_wrapper->has("mref_id")) {
192 $mref_id = $this->post_wrapper->retrieve(
193 "mref_id",
194 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
195 );
196 $saved_post = array_unique(array_merge(ilSession::get('saved_post'), $mref_id));
197 ilSession::set('saved_post', $saved_post);
198 }
199
200 $ru = new ilRepositoryTrashGUI($this);
201 $refIds = ilSession::get("saved_post");
202 $talks = [];
203
204 foreach ($refIds as $refId) {
205 $talks[] = new ilObjEmployeeTalk(intval($refId), true);
206 }
207
208 $ru->deleteObjects($this->requested_ref_id, $refIds);
209 $trashEnabled = boolval($this->container->settings()->get('enable_trash'));
210
211 $this->sendNotification($talks);
212 if ($trashEnabled) {
213 foreach ($talks as $talk) {
214 $talk->delete();
215 }
216 }
217
218 ilSession::clear("saved_post");
219
220 $this->ctrl->redirectByClass(strtolower(ilEmployeeTalkMyStaffListGUI::class), ControlFlowCommand::DEFAULT, "", false);
221 }
222
226 private function sendNotification(array $talks): void
227 {
228 $firstTalk = $talks[0];
229 $talk_title = $firstTalk->getTitle();
230 $superior = new ilObjUser($firstTalk->getOwner());
231 $employee = new ilObjUser($firstTalk->getData()->getEmployee());
232 $superiorName = $superior->getFullname();
233 $series = $firstTalk->getParent();
234
235 $dates = array_map(
236 fn (ilObjEmployeeTalk $t) => $t->getData()->getStartDate(),
237 $talks
238 );
239 usort($dates, function (ilDateTime $a, ilDateTime $b) {
240 $a = $a->getUnixTime();
241 $b = $b->getUnixTime();
242 if ($a === $b) {
243 return 0;
244 }
245 return $a < $b ? -1 : 1;
246 });
247
248 $add_time = $firstTalk->getData()->isAllDay() ? 0 : 1;
250 $timezone = $employee->getTimeZone();
251 $dates = array_map(function (ilDateTime $d) use ($add_time, $format, $timezone) {
252 return $d->get(IL_CAL_FKT_DATE, $format, $timezone);
253 }, $dates);
254
256 $firstTalk->getRefId(),
257 $talk_title,
258 $firstTalk->getDescription(),
259 $firstTalk->getData()->getLocation(),
260 'notification_talks_subject_update',
261 'notification_talks_removed',
262 $superiorName,
263 $dates,
264 false
265 );
266
267 // Check if we deleted the last talk of the series
268 $vCalSender = null;
269 if ($series->hasChildren()) {
270 $vCalSender = new EmployeeTalkEmailNotificationService(
271 $message,
272 $talk_title,
273 $employee,
274 $superior,
275 VCalendarFactory::getInstanceFromTalks($series)
276 );
277 } else {
278 $vCalSender = new EmployeeTalkEmailNotificationService(
279 $message,
280 $talk_title,
281 $employee,
282 $superior,
283 VCalendarFactory::getEmptyInstance($series, $talk_title)
284 );
285 }
286
287 $vCalSender->send();
288 }
289
293 private function sendUpdateNotification(array $talks): void
294 {
295 if (count($talks) === 0) {
296 return;
297 }
298
299 $firstTalk = $talks[0];
300 $talk_title = $firstTalk->getTitle();
301 $superior = new ilObjUser($firstTalk->getOwner());
302 $employee = new ilObjUser($firstTalk->getData()->getEmployee());
303 $superiorName = $superior->getFullname();
304
305 $dates = array_map(
306 fn (ilObjEmployeeTalk $t) => $t->getData()->getStartDate(),
307 $talks
308 );
309 usort($dates, function (ilDateTime $a, ilDateTime $b) {
310 $a = $a->getUnixTime();
311 $b = $b->getUnixTime();
312 if ($a === $b) {
313 return 0;
314 }
315 return $a < $b ? -1 : 1;
316 });
317
318 $add_time = $firstTalk->getData()->isAllDay() ? 0 : 1;
320 $timezone = $employee->getTimeZone();
321 $dates = array_map(function (ilDateTime $d) use ($add_time, $format, $timezone) {
322 return $d->get(IL_CAL_FKT_DATE, $format, $timezone);
323 }, $dates);
324
326 $firstTalk->getRefId(),
327 $talk_title,
328 $firstTalk->getDescription(),
329 $firstTalk->getData()->getLocation(),
330 'notification_talks_subject_update',
331 'notification_talks_updated',
332 $superiorName,
333 $dates
334 );
335
336 $vCalSender = new EmployeeTalkEmailNotificationService(
337 $message,
338 $talk_title,
339 $employee,
340 $superior,
341 VCalendarFactory::getInstanceFromTalks($firstTalk->getParent())
342 );
343
344 $vCalSender->send();
345 }
346
347 public function cancelDeleteObject(): void
348 {
349 ilSession::clear("saved_post");
350
351 $this->ctrl->redirectByClass(strtolower(ilEmployeeTalkMyStaffListGUI::class), ControlFlowCommand::DEFAULT, "", false);
352 }
353
354 protected function initEditForm(): ilPropertyFormGUI
355 {
357
361 $data = $this->object->getData();
362
363 $lng->loadLanguageModule('etal');
364 $lng->loadLanguageModule('orgu');
365
366 $form = new ilPropertyFormGUI();
367 $form->setFormAction($this->ctrl->getFormAction($this, "update"));
368
369 $form->setTitle($this->lng->txt('talk_serial'));
370
371 $generalSection = new ilFormSectionHeaderGUI();
372 $generalSection->setTitle($this->lng->txt($this->object->getType() . "_edit"));
373
374 // title
375 $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
376 $ti->setInfo($this->lng->txt('will_update_series_info_title'));
377 $ti->setSize(min(40, ilObject::TITLE_LENGTH));
378 $ti->setMaxLength(ilObject::TITLE_LENGTH);
379 $ti->setRequired(true);
380 $ti->setDisabled($this->isReadonly);
381 $form->addItem($ti);
382
383 $superior = new ilTextInputGUI($this->lng->txt("superior"), "etal_superior");
384 $superior->setDisabled(true);
385 $form->addItem($superior);
386
387 $login = new ilTextInputGUI($this->lng->txt("employee"), "etal_employee");
388 $login->setDisabled(true);
389 $form->addItem($login);
390
391 $writeLockForOthers = new ilCheckboxInputGUI($this->lng->txt("lock_edititng_for_others"), "etal_settings_locked_for_others");
392 $writeLockForOthers->setInfo($this->lng->txt('will_update_series_info_lock'));
393 $writeLockForOthers->setDisabled($this->isReadonly || !$this->talkAccess->canEditTalkLockStatus(intval($this->object->getRefId())));
394 $form->addItem($writeLockForOthers);
395
396 $form->addItem($generalSection);
397
398 // description
399 $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
400 $ta->setCols(40);
401 $ta->setRows(2);
402 $ta->setDisabled($this->isReadonly);
403 $form->addItem($ta);
404
405 $this->initEditCustomForm($form);
406
407 if (!$this->isReadonly) {
408 $form->addCommandButton("update", $this->lng->txt("save"));
409 }
410 //$this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
411
412 return $form;
413 }
414
415 public function addExternalEditFormCustom(ilPropertyFormGUI $a_form): void
416 {
420 $data = $this->object->getData();
421
422 $location = new ilTextInputGUI($this->lng->txt('location'), 'etal_location');
423 $location->setMaxLength(200);
424 $location->setValue($data->getLocation());
425 $location->setDisabled($this->isReadonly);
426 $a_form->addItem($location);
427
428 $completed = new ilCheckboxInputGUI($this->lng->txt('etal_status_completed'), 'etal_completed');
429 $completed->setChecked($data->isCompleted());
430 $completed->setDisabled($this->isReadonly);
431 $a_form->addItem($completed);
432
433 $this->container->ctrl()->setParameterByClass(strtolower(ilEmployeeTalkAppointmentGUI::class), 'ref_id', $this->ref_id);
434
435 if (!$this->isReadonly) {
436 $btnChangeThis = ilLinkButton::getInstance();
437 $btnChangeThis->setCaption("change_date_of_talk");
439 $btnChangeThis->setUrl($this->ctrl->getLinkTargetByClass(strtolower(ilEmployeeTalkAppointmentGUI::class), ControlFlowCommand::UPDATE_INDEX) . $editMode);
440 $this->toolbar->addButtonInstance($btnChangeThis);
441
442 $btnChangeAll = ilLinkButton::getInstance();
443 $btnChangeAll->setCaption("change_date_of_series");
445 $btnChangeAll->setUrl($this->ctrl->getLinkTargetByClass(strtolower(ilEmployeeTalkAppointmentGUI::class), ControlFlowCommand::UPDATE_INDEX) . $editMode);
446 $this->toolbar->addButtonInstance($btnChangeAll);
447 }
448
449 $md = $this->initMetaDataForm($a_form);
450 $md->parse();
451
452 // this is necessary to disable the md fields
453 if ($this->isReadonly) {
454 foreach ($a_form->getInputItemsRecursive() as $item) {
455 if ($item instanceof ilCombinationInputGUI) {
456 $item->__call('setValue', ['']);
457 $item->__call('setDisabled', [true]);
458 }
459 if (method_exists($item, 'setDisabled')) {
461 $item->setDisabled(true);
462 }
463 }
464 }
465
466 parent::addExternalEditFormCustom($a_form);
467 }
468
469 protected function getEditFormCustomValues(array &$a_values): void
470 {
474 $data = $this->object->getData();
475 $parent = $this->object->getParent();
476 $settings = $this->repository->readEmployeeTalkSerieSettings(intval($parent->getId()));
477
478 $a_values['etal_superior'] = ilObjUser::_lookupLogin(intval($this->object->getOwner()));
479 $a_values['etal_employee'] = ilObjUser::_lookupLogin($data->getEmployee());
480 $a_values['etal_settings_locked_for_others'] = $settings->isLockedEditing();
481 }
482
483 protected function updateCustom(ilPropertyFormGUI $a_form): void
484 {
488 $series = $this->object->getParent();
489 $updated_series = false;
490
491 $md = $this->initMetaDataForm($a_form);
492 $md->parse();
493 $md->importEditFormPostValues();
494 $md->writeEditForm($series->getId(), $this->object->getId());
495
496 $location = $a_form->getInput('etal_location');
497 $completed = boolval(
498 intval($a_form->getInput('etal_completed'))
499 );
500 $lockEdititngForOthers = boolval(
501 intval($a_form->getInput('etal_settings_locked_for_others'))
502 );
503
504 $settings = $this->repository->readEmployeeTalkSerieSettings(intval($series->getId()));
505 if ($lockEdititngForOthers !== $settings->isLockedEditing()) {
506 $settings->setLockedEditing($lockEdititngForOthers);
507 $this->repository->storeEmployeeTalkSerieSettings($settings);
508 $updated_series = true;
509 }
510
511
515 $data = $this->object->getData();
516 $data->setCompleted($completed);
517 $data->setLocation($location ?? '');
518 $this->object->setData($data);
519
523 $parent = $this->object->getParent();
527 $subTree = $parent->getSubItems()['_all'];
528
529
530 $talks = [];
531 $talks[] = $this->object;
532 // Update the title of the talk series
533 if ($parent->getTitle() !== $this->object->getTitle()) {
534 $parent->setTitle($this->object->getTitle());
535 $parent->update();
536 }
537 // Update the title of every talk which belongs to the talk series
538 foreach ($subTree as $treeNode) {
539 if (boolval($treeNode['deleted']) === true) {
540 continue;
541 }
542 $talk = new ilObjEmployeeTalk(intval($treeNode['ref_id']));
543 if ($talk->getId() === $this->object->getId()) {
544 continue;
545 }
546 if ($talk->getTitle() !== $this->object->getTitle()) {
547 $talk->setTitle($this->object->getTitle());
548 $talk->update();
549 $talks[] = $talk;
550 } elseif ($updated_series) {
551 $talks[] = $talk;
552 }
553 }
554
555 parent::updateCustom($a_form);
556
557 $this->sendUpdateNotification($talks);
558 }
559
560 public function viewObject(): void
561 {
562 $this->tabs_gui->activateTab('view_content');
563 $this->editObject();
564 }
565
566 protected function getTabs(): void
567 {
568 $this->tabs_gui->addTab('view_content', $this->lng->txt("content"), $this->ctrl->getLinkTarget($this, ControlFlowCommand::UPDATE));
569 $this->tabs_gui->addTab("info_short", "Info", $this->ctrl->getLinkTargetByClass(strtolower(ilInfoScreenGUI::class), "showSummary"));
570 //$this->tabs_gui->addTab('settings', $this->lng->txt("settings"), $this->ctrl->getLinkTarget($this, "edit"));
571 }
572
576 public function getAdminTabs(): void
577 {
578 $this->getTabs();
579
580 if ($this->checkPermissionBool("edit_permission")) {
581 $this->tabs_gui->addTab(
582 'perm_settings',
583 $this->lng->txt('perm_settings'),
584 $this->ctrl->getLinkTargetByClass(
585 [
586 get_class($this),
587 'ilpermissiongui'
588 ],
589 'perm'
590 )
591 );
592 }
593 }
594
595 private function initMetaDataForm(ilPropertyFormGUI $form): ilAdvancedMDRecordGUI
596 {
600 $series = $this->object->getParent();
601 $md = new ilAdvancedMDRecordGUI(
603 $series->getType(),
604 $series->getId(),
605 $this->object->getType(),
606 $this->object->getId(),
607 false
608 );
609 $md->setPropertyForm($form);
610 return $md;
611 }
612
613 public static function _goto(string $refId): void
614 {
618 $container = $GLOBALS['DIC'];
619 if (!ilObject::_exists((int) $refId, true)) {
620 $container["tpl"]->setOnScreenMessage(
621 'failure',
622 $container->language()->txt("permission_denied"),
623 true
624 );
625 $container->ctrl()->redirectByClass(ilDashboardGUI::class, "");
626 }
627 $container->ctrl()->setParameterByClass(strtolower(self::class), 'ref_id', $refId);
628 $container->ctrl()->redirectByClass([
629 strtolower(ilDashboardGUI::class),
630 strtolower(ilMyStaffGUI::class),
631 strtolower(ilEmployeeTalkMyStaffListGUI::class),
632 strtolower(self::class),
633 ], ControlFlowCommand::INDEX);
634 }
635}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
const IL_CAL_FKT_DATE
static getUserDateFormat(int $a_add_time=0, bool $a_for_parsing=false)
Parse current user setting into date/time format.
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
Class ilEmployeeTalkAppointmentGUI.
setFormAction(string $a_formaction)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilInfoScreenGUI.
loadLanguageModule(string $a_module)
Load language module.
Class ilObjEmployeeTalkGUI.
ilObjEmployeeTalkAccess $talkAccess
cancelDeleteObject()
cancel deletion of object
viewObject()
viewObject container presentation for "administration -> repository, trash, permissions"
confirmedDeleteObject()
confirmed deletion of object -> objects are moved to trash or deleted immediately,...
validateCustom(ilPropertyFormGUI $a_form)
Validate custom values (if not possible with checkInput())
IliasDBEmployeeTalkSeriesRepository $repository
getTabs()
@abstract overwrite in derived GUI class of your object type
updateObject()
updates object entry in object_data
User class.
static _lookupLogin(int $a_user_id)
Class ilObjectGUI Basic methods of all Output classes.
setReturnLocation(string $cmd, string $location)
set specific return location for command
addExternalEditFormCustom(ilPropertyFormGUI $form)
afterUpdate()
Post (successful) object update hook.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
updateCustom(ilPropertyFormGUI $form)
Insert custom update form values into object.
ilSetting $settings
omitLocator(bool $omit=true)
getEditFormCustomValues(array &$a_values)
Add values to custom edit fields.
initEditCustomForm(ilPropertyFormGUI $a_form)
Add custom fields to update form.
ilLanguage $lng
const TITLE_LENGTH
setTitle(string $title)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
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-...
getInputItemsRecursive()
returns a flat array of all input items including the possibly existing subitems recursively
Repository GUI Utilities.
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
This class represents a text area property in a property form.
This class represents a text property in a property form.
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$format
Definition: metadata.php:235
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$message
Definition: xapiexit.php:32
$refId
Definition: xapitoken.php:58