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