ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilObjEmployeeTalkGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
34 
46 final class ilObjEmployeeTalkGUI extends ilObjectGUI
47 {
48  protected HttpServices $http;
49  protected Refinery $refinery;
52  protected bool $isReadonly;
57  private string $link_to_parent;
58 
59  public function __construct()
60  {
61  global $DIC;
62 
63  $this->http = $DIC->http();
64  $this->refinery = $DIC->refinery();
65  $refId = $this->http->wrapper()->query()->retrieve(
66  "ref_id",
67  $this->refinery->kindlyTo()->int()
68  );
69  parent::__construct([], $refId, true, false);
70 
71  $DIC->language()->loadLanguageModule('mst');
72  $DIC->language()->loadLanguageModule('trac');
73  $DIC->language()->loadLanguageModule('etal');
74  $DIC->language()->loadLanguageModule('dateplaner');
75  $this->lng = $DIC->language();
76  $this->ui_factory = $DIC->ui()->factory();
77 
78  $this->type = 'etal';
79 
80  $this->omitLocator();
81  $DIC->ui()->mainTemplate()->setTitle($this->lng->txt('mst_my_staff'));
82  $this->talkAccess = ilObjEmployeeTalkAccess::getInstance();
83  $this->repository = new IliasDBEmployeeTalkSeriesRepository($this->user, $DIC->database());
84  $this->md_handler = new MetadataHandler();
85  $this->notif_handler = new NotificationHandler(new VCalendarGenerator($DIC->language()));
86  }
87 
88  private function checkAccessOrFail(): void
89  {
90  if (!$this->talkAccess->canRead($this->object->getRefId())) {
91  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
92  $this->ctrl->redirectByClass(ilDashboardGUI::class, "");
93  }
94  }
95 
96  public function setLinkToParentGUI(string $link): void
97  {
98  $this->link_to_parent = $link;
99  }
100 
101  public function redirectToParentGUI(): void
102  {
103  if (isset($this->link_to_parent)) {
104  $this->ctrl->redirectToURL($this->link_to_parent);
105  }
106  $this->ctrl->redirectByClass(strtolower(ilEmployeeTalkMyStaffListGUI::class));
107  }
108 
109  public function executeCommand(): void
110  {
111  $this->checkAccessOrFail();
112  $this->isReadonly = !$this->talkAccess->canEdit($this->object->getRefId());
113 
114  // determine next class in the call structure
115  $next_class = $this->ctrl->getNextClass($this);
116 
117  switch ($next_class) {
118  case 'ilpermissiongui':
119  parent::prepareOutput();
120  $this->tabs_gui->activateTab('perm_settings');
121  $ilPermissionGUI = new ilPermissionGUI($this);
122  $this->ctrl->forwardCommand($ilPermissionGUI);
123  break;
124  case 'ilinfoscreengui':
125  parent::prepareOutput();
126  $this->tabs_gui->activateTab('info_short');
127  $ilInfoScreenGUI = new ilInfoScreenGUI($this);
128  $this->ctrl->forwardCommand($ilInfoScreenGUI);
129  break;
130  case strtolower(ilRepositorySearchGUI::class):
131  $repo = new ilRepositorySearchGUI();
132  //TODO: Add user filter
134  //$repo->addUserAccessFilterCallable(function () {
135  // $orgUnitUser = ilOrgUnitUser::getInstanceById($this->container->user()->getId());
136  // $orgUnitUser->addPositions() ;
137  //});
138  $this->ctrl->forwardCommand($repo);
139  break;
140  case strtolower(ilEmployeeTalkAppointmentGUI::class):
141  $appointmentGUI = new ilEmployeeTalkAppointmentGUI(
142  $this->tpl,
143  $this->lng,
144  $this->ctrl,
145  $this->http,
146  $this->refinery,
147  $this->tabs_gui,
148  $this->notif_handler,
149  $this->object
150  );
151  $this->ctrl->forwardCommand($appointmentGUI);
152  break;
153  case strtolower(ilPropertyFormGUI::class):
154  /*
155  * Only used for async loading of the repository tree in custom md
156  * internal links (see #43636). This is necessary since EmployeeTalks don't
157  * use ilObjectMetaDataGUI.
158  */
159  $form = $this->getMetadataForm()->getFormGUI();
160  $this->ctrl->forwardCommand($form);
161  break;
162  default:
163  parent::executeCommand();
164  }
165  }
166 
167  public function editObject(): void
168  {
169  $this->tabs_gui->activateTab('settings');
170 
171  $form = $this->initEditForm();
172  $values = $this->getEditFormValues();
173  if ($values) {
174  $form->setValuesByArray($values);
175  }
176 
178  $this->tpl->setContent($form->getHTML());
179  }
180 
181  protected function validateCustom(ilPropertyFormGUI $form): bool
182  {
183  $refId = $this->object->getRefId();
184  $settings = $this->repository->readEmployeeTalkSerieSettings($this->object->getId());
185  $oldLockSettings = $settings->isLockedEditing();
186  $lockEdititngForOthers = boolval(
187  intval($form->getInput('etal_settings_locked_for_others'))
188  );
189  if ($oldLockSettings === $lockEdititngForOthers) {
190  return true;
191  }
192 
193  return $this->talkAccess->canEditTalkLockStatus($refId);
194  }
195 
196  public function updateObject(): void
197  {
198  $form = $this->initEditForm();
199  $this->addExternalEditFormCustom($form);
200  if ($form->checkInput() &&
201  $this->validateCustom($form) &&
203  $this->object->setTitle($form->getInput("title"));
204  $this->object->setDescription($form->getInput("desc"));
205  $this->updateCustom($form);
206  $this->object->update();
207 
208  $this->afterUpdate();
209  return;
210  }
211 
212  // display form again to correct errors
213  $this->tabs_gui->activateTab("settings");
215  $form->setValuesByPost();
216  $this->tpl->setContent($form->getHtml());
217  }
218 
219  public function confirmedDeleteObject(): void
220  {
221  if (!$this->talkAccess->canDelete($this->ref_id)) {
222  ilSession::clear("saved_post");
223  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
224  $this->redirectToParentGUI();
225 
226  return;
227  }
228 
229  if ($this->post_wrapper->has("interruptive_items")) {
230  $ref_id = $this->post_wrapper->retrieve(
231  "interruptive_items",
232  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
233  );
234  $saved_post = array_unique(array_merge(ilSession::get('saved_post') ?? [], $ref_id));
235  ilSession::set('saved_post', $saved_post);
236  }
237 
238  $ru = new ilRepositoryTrashGUI($this);
239  $ref_ids = ilSession::get("saved_post");
240  $talks = [];
241 
242  foreach ($ref_ids as $refId) {
243  $talks[] = new ilObjEmployeeTalk(intval($refId), true);
244  }
245 
246  $this->sendNotification(...$talks);
247 
248  $ru->deleteObjects($this->requested_ref_id, $ref_ids);
249  $trashEnabled = boolval($this->settings->get('enable_trash'));
250 
251  if ($trashEnabled) {
253  }
254 
255  ilSession::clear("saved_post");
256 
257  $this->redirectToParentGUI();
258  }
259 
260  private function sendNotification(ilObjEmployeeTalk ...$talks): void
261  {
262  $this->notif_handler->send(NotificationType::CANCELLATION, ...$talks);
263  }
264 
265  private function sendUpdateNotification(ilObjEmployeeTalk ...$talks): void
266  {
267  $this->notif_handler->send(NotificationType::UPDATE, ...$talks);
268  }
269 
270  protected function initEditForm(): ilPropertyFormGUI
271  {
272  $lng = $this->lng;
273 
277  $data = $this->object->getData();
278 
279  $lng->loadLanguageModule('etal');
280  $lng->loadLanguageModule('orgu');
281 
282  $form = new ilPropertyFormGUI();
283  $form->setFormAction($this->ctrl->getFormAction($this, "update"));
284 
285  $form->setTitle($this->lng->txt('talk_serial'));
286 
287  $generalSection = new ilFormSectionHeaderGUI();
288  $generalSection->setTitle($this->lng->txt($this->object->getType() . "_edit"));
289 
290  // title
291  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
292  $ti->setInfo($this->lng->txt('will_update_series_info_title'));
293  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
294  $ti->setMaxLength(ilObject::TITLE_LENGTH);
295  $ti->setRequired(true);
296  $ti->setDisabled($this->isReadonly);
297  $form->addItem($ti);
298 
299  $superior = new ilTextInputGUI($this->lng->txt("superior"), "etal_superior");
300  $superior->setDisabled(true);
301  $form->addItem($superior);
302 
303  $login = new ilTextInputGUI($this->lng->txt("employee"), "etal_employee");
304  $login->setDisabled(true);
305  $form->addItem($login);
306 
307  $writeLockForOthers = new ilCheckboxInputGUI($this->lng->txt("lock_edititng_for_others"), "etal_settings_locked_for_others");
308  $writeLockForOthers->setInfo($this->lng->txt('will_update_series_info_lock'));
309  $writeLockForOthers->setDisabled(
310  $this->isReadonly ||
311  !$this->talkAccess->canEditTalkLockStatus($this->object->getRefId())
312  );
313  $form->addItem($writeLockForOthers);
314 
315  $form->addItem($generalSection);
316 
317  // description
318  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
319  $ta->setCols(40);
320  $ta->setRows(2);
321  $ta->setDisabled($this->isReadonly);
322  $form->addItem($ta);
323 
324  $location = new ilTextInputGUI($this->lng->txt('location'), 'etal_location');
325  $location->setMaxLength(200);
326  $location->setDisabled($this->isReadonly);
327  $form->addItem($location);
328 
329  $completed = new ilCheckboxInputGUI($this->lng->txt('etal_status_completed'), 'etal_completed');
330  $completed->setDisabled($this->isReadonly);
331  $form->addItem($completed);
332 
333  $this->initEditCustomForm($form);
334 
335  if (!$this->isReadonly) {
336  $form->addCommandButton("update", $this->lng->txt("save"));
337  }
338 
339  return $form;
340  }
341 
342  public function addChangeDateButtonsToToolbar(): void
343  {
344  if ($this->isReadonly) {
345  return;
346  }
347  $appointment_class = strtolower(ilEmployeeTalkAppointmentGUI::class);
348  $this->ctrl->setParameterByClass($appointment_class, 'ref_id', $this->ref_id);
349 
350  $this->ctrl->setParameterByClass(
351  $appointment_class,
354  );
355  $link_single = $this->ctrl->getLinkTargetByClass(
356  $appointment_class,
357  ControlFlowCommand::UPDATE_INDEX
358  );
359  $button_single = $this->ui_factory->button()->standard(
360  $this->lng->txt('change_date_of_talk'),
361  $link_single
362  );
363 
364  $this->ctrl->setParameterByClass(
365  $appointment_class,
368  );
369  $link_all = $this->ctrl->getLinkTargetByClass(
370  $appointment_class,
371  ControlFlowCommand::UPDATE_INDEX
372  );
373  $button_all = $this->ui_factory->button()->standard(
374  $this->lng->txt('change_date_of_series'),
375  $link_all
376  );
377 
378  $this->ctrl->clearParametersByClass($appointment_class);
379 
380  $this->toolbar->addComponent($button_single);
381  $this->toolbar->addComponent($button_all);
382  }
383 
384  protected function getEditFormCustomValues(array &$a_values): void
385  {
389  $data = $this->object->getData();
390  $parent = $this->object->getParent();
391  $settings = $this->repository->readEmployeeTalkSerieSettings(intval($parent->getId()));
392 
393  $a_values['etal_superior'] = ilObjUser::_lookupLogin($this->object->getOwner());
394  $a_values['etal_employee'] = ilObjUser::_lookupLogin($data->getEmployee());
395  $a_values['etal_settings_locked_for_others'] = $settings->isLockedEditing();
396  $a_values['etal_location'] = $data->getLocation();
397  $a_values['etal_completed'] = $data->isCompleted();
398  }
399 
400  protected function updateCustom(ilPropertyFormGUI $form): void
401  {
405  $series = $this->object->getParent();
406  $updated_series = false;
407 
408  $location = $form->getInput('etal_location');
409  $completed = boolval(
410  intval($form->getInput('etal_completed'))
411  );
412  $lockEdititngForOthers = boolval(
413  intval($form->getInput('etal_settings_locked_for_others'))
414  );
415 
416  $settings = $this->repository->readEmployeeTalkSerieSettings($series->getId());
417  if ($lockEdititngForOthers !== $settings->isLockedEditing()) {
418  $settings->setLockedEditing($lockEdititngForOthers);
419  $this->repository->storeEmployeeTalkSerieSettings($settings);
420  $updated_series = true;
421  }
422 
423 
427  $data = $this->object->getData();
428  $data->setCompleted($completed);
429  $data->setLocation($location ?? '');
430  $this->object->setData($data);
431 
435  $parent = $this->object->getParent();
439  $subTree = $parent->getSubItems()['_all'];
440 
441 
442  $talks = [];
443  $talks[] = $this->object;
444  // Update the title of the talk series
445  if ($parent->getTitle() !== $this->object->getTitle()) {
446  $parent->setTitle($this->object->getTitle());
447  $parent->update();
448  }
449  // Update the title of every talk which belongs to the talk series
450  foreach ($subTree as $treeNode) {
451  if (boolval($treeNode['deleted']) === true) {
452  continue;
453  }
454  $talk = new ilObjEmployeeTalk(intval($treeNode['ref_id']));
455  if ($talk->getId() === $this->object->getId()) {
456  continue;
457  }
458  if ($talk->getTitle() !== $this->object->getTitle()) {
459  $talk->setTitle($this->object->getTitle());
460  $talk->update();
461  $talks[] = $talk;
462  } elseif ($updated_series) {
463  $talks[] = $talk;
464  }
465  }
466 
467  parent::updateCustom($form);
468 
469  $this->sendUpdateNotification(...$talks);
470  }
471 
472  public function viewObject(): void
473  {
474  $this->tabs_gui->activateTab('view_content');
475  $form = $this->getMetadataForm();
476  $this->tpl->setContent($form->render());
477  }
478 
479  public function updateMetadataObject(): void
480  {
484  $talk_object = $this->object;
485  $series = $talk_object->getParent();
486 
487  $form = $this->getMetadataForm();
488 
489  if ($form->importFromPostAndValidate()) {
490  $form->updateMetadata();
491  $this->tpl->setOnScreenMessage("success", $this->lng->txt("msg_obj_modified"), true);
492  $this->sendUpdateNotification($talk_object);
493  $this->ctrl->redirect($this, ControlFlowCommand::INDEX);
494  }
495 
496  $this->tabs_gui->activateTab('view_content');
497  $this->tpl->setContent($form->render());
498  }
499 
500  protected function getTabs(): void
501  {
502  $this->tabs_gui->addTab(
503  'view_content',
504  $this->lng->txt("content"),
505  $this->ctrl->getLinkTarget($this, ControlFlowCommand::INDEX)
506  );
507  $this->tabs_gui->addTab(
508  "info_short",
509  "Info",
510  $this->ctrl->getLinkTargetByClass(strtolower(ilInfoScreenGUI::class), "showSummary")
511  );
512  $this->tabs_gui->addTab(
513  'settings',
514  $this->lng->txt("settings"),
515  $this->ctrl->getLinkTarget($this, ControlFlowCommand::UPDATE)
516  );
517  }
518 
522  public function getAdminTabs(): void
523  {
524  $this->getTabs();
525 
526  if ($this->checkPermissionBool("edit_permission")) {
527  $this->tabs_gui->addTab(
528  'perm_settings',
529  $this->lng->txt('perm_settings'),
530  $this->ctrl->getLinkTargetByClass(
531  [
532  get_class($this),
533  'ilpermissiongui'
534  ],
535  'perm'
536  )
537  );
538  }
539  }
540 
541  protected function getMetadataForm(): EditFormInterface
542  {
546  $series = $this->object->getParent();
547 
548  if ($this->isReadonly) {
549  return $this->md_handler->getDisabledEditForm(
550  $series->getType(),
551  $series->getId(),
552  $this->object->getType(),
553  $this->object->getId()
554  );
555  }
556 
557  return $this->md_handler->getEditForm(
558  $series->getType(),
559  $series->getId(),
560  $this->object->getType(),
561  $this->object->getId(),
562  $this->ctrl->getFormAction($this, 'updateMetadata'),
563  'updateMetadata',
564  $this->lng->txt('save')
565  );
566  }
567 
568  public static function _goto(string $refId): void
569  {
573  $container = $GLOBALS['DIC'];
574  if (!ilObject::_exists((int) $refId, true)) {
575  $container["tpl"]->setOnScreenMessage(
576  'failure',
577  $container->language()->txt("permission_denied"),
578  true
579  );
580  $container->ctrl()->redirectByClass(ilDashboardGUI::class, "");
581  }
582  $container->ctrl()->setParameterByClass(strtolower(self::class), 'ref_id', $refId);
583  $container->ctrl()->redirectByClass([
584  strtolower(ilDashboardGUI::class),
585  strtolower(ilMyStaffGUI::class),
586  strtolower(ilEmployeeTalkMyStaffListGUI::class),
587  strtolower(self::class),
588  ], ControlFlowCommand::INDEX);
589  }
590 }
static get(string $a_var)
omitLocator(bool $omit=true)
validateCustom(ilPropertyFormGUI $form)
sendNotification(ilObjEmployeeTalk ... $talks)
const TITLE_LENGTH
$location
Definition: buildRTE.php:22
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
MetadataHandlerInterface $md_handler
$refId
Definition: xapitoken.php:58
loadLanguageModule(string $a_module)
Load language module.
setTitle(string $title)
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-...
NotificationHandlerInterface $notif_handler
addExternalEditFormCustom(ilPropertyFormGUI $form)
$container
Definition: wac.php:36
ilLanguage $lng
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static http()
Fetches the global http state from ILIAS.
Class ilObjEmployeeTalkGUI.
$GLOBALS["DIC"]
Definition: wac.php:53
setFormAction(string $a_formaction)
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: shib_login.php:22
Repository GUI Utilities.
sendUpdateNotification(ilObjEmployeeTalk ... $talks)
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
IliasDBEmployeeTalkSeriesRepository $repository
static removeObjectsFromSystem(array $a_ref_ids, bool $a_from_recovery_folder=false)
remove objects from trash bin and all entries therefore every object needs a specific deleteObject() ...
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
getEditFormCustomValues(array &$a_values)
Add values to custom edit fields.
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
Class ilEmployeeTalkAppointmentGUI.
afterUpdate()
Post (successful) object update hook.
updateCustom(ilPropertyFormGUI $form)
Insert custom update form values into object.
static clear(string $a_var)
ilObjEmployeeTalkAccess $talkAccess
ilSetting $settings
static set(string $a_var, $a_val)
Set a value.
initEditCustomForm(ilPropertyFormGUI $a_form)
Add custom fields to update form.
static _lookupLogin(int $a_user_id)