ILIAS  trunk Revision v12.0_alpha-1329-g1094ddb0c33
class.ilGuidedTourAdminGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28
32class ilGuidedTourAdminGUI // implements ilCtrlBaseClassInterface
33{
34 private \ILIAS\Help\GuidedTour\Step\StepManager $step_manager;
35 protected \ILIAS\Help\GuidedTour\UserFinished\UserFinishedManager $finish_manager;
36 protected \ILIAS\Help\GuidedTour\Tour\TourManager $tm;
37
38 public function __construct(
39 protected \ILIAS\Help\GuidedTour\InternalDataService $data,
40 protected \ILIAS\Help\GuidedTour\InternalDomainService $domain,
41 protected \ILIAS\Help\GuidedTour\InternalGUIService $gui,
42 protected bool $edit = false
43 ) {
44 $ctrl = $this->gui->ctrl();
45 $this->tm = $domain->tour();
46 $ctrl->saveParameterByClass(self::class, "tour_id");
47 $this->step_manager = $domain->step();
48 $this->finish_manager = $domain->userFinished();
49 }
50
51 public function executeCommand(): void
52 {
53 $ctrl = $this->gui->ctrl();
54 $mt = $this->gui->ui()->mainTemplate();
55
56 $next_class = $ctrl->getNextClass($this);
57 $cmd = $ctrl->getCmd("listTours");
58
59 switch ($next_class) {
60 case strtolower(ilExportGUI::class):
61 $this->setStepsHeader();
62 $this->setSettingsTabs("export");
63 $tour_id = $this->gui->standardRequest()->getTourId();
64 $exp_gui = new ilExportGUI($this->gui->objectGUI($tour_id));
65 $exp_gui->addFormat("xml");
66 $ctrl->forwardCommand($exp_gui);
67 break;
68
69 case strtolower(ilGuidedTourPageGUI::class):
70 $mt = $this->gui->mainTemplate();
71 $lng = $this->domain->lng();
72 $this->setStepsHeader();
73 $mt->setOnScreenMessage("info", $lng->txt("gdtr_edit_page_info"));
74 $ctrl->setReturnByClass(self::class, "listSteps");
75 $ctrl->saveParameterByClass(self::class, "step_id");
76 $ret = $this->forwardToPageObject();
77 $mt->setContent($ret);
78 break;
79
80 case strtolower(ilRepoStandardUploadHandlerGUI::class):
81 $form = $this->getImportForm();
82 $gui = $form->getRepoStandardUploadHandlerGUI("import");
83 $ctrl->forwardCommand($gui);
84 break;
85
86 default:
87 if (in_array($cmd, [
88 "listTours",
89 "addTour",
90 "saveTour",
91 "deleteTour",
92 "listSteps",
93 "addStep",
94 "saveStep",
95 "tableCommand",
96 "editStep",
97 "editPage",
98 "editSettings",
99 "saveSettings",
100 "idSettings",
101 "saveIdSettings",
102 "saveOrder",
103 "confirmStepDeletion",
104 "deleteStep",
105 "resetTour",
106 "importTourForm",
107 "importTour"
108 ])) {
109 $this->$cmd();
110 }
111 }
112 }
113
114 protected function setSettingsTabs(string $active): void
115 {
116 $tabs = $this->gui->tabs();
117 $lng = $this->domain->lng();
118 $ctrl = $this->gui->ctrl();
119 $tabs->clearTargets();
120 $this->gui->help()->setScreenIdComponent("hlps_gdtr");
121 $tabs->setBackTarget(
122 $lng->txt("gdtr_guided_tours"),
123 $ctrl->getLinkTargetByClass(self::class, "listTours")
124 );
125 $ctrl->saveParameterByClass(self::class, "tour_id");
126 $tabs->addTab(
127 "steps",
128 $lng->txt("gdtr_tour_steps"),
129 $ctrl->getLinkTargetByClass(self::class, "listSteps")
130 );
131 $tabs->addTab(
132 "settings",
133 $lng->txt("settings"),
134 $ctrl->getLinkTargetByClass(self::class, "editSettings")
135 );
136 $tabs->addTab(
137 "export",
138 $lng->txt("export"),
139 $ctrl->getLinkTargetByClass(ilexportGUI::class, "export", ""),
140 );
141 $tabs->activateTab($active);
142 }
143
144 public function forwardToPageObject(): string
145 {
146 $tabs = $this->gui->tabs();
147 $lng = $this->domain->lng();
148 $ctrl = $this->gui->ctrl();
149 $step_id = $this->gui->standardRequest()->getStepId();
150 $tour_id = $this->gui->standardRequest()->getTourId();
151
152 $tabs->clearTargets();
153
154 $tabs->setBackTarget(
155 $lng->txt("back"),
156 $ctrl->getLinkTargetByClass(ilGuidedTourPageGUI::class, "edit")
157 );
158
160 "gdtr",
161 $step_id
162 )) {
163 $new_page_object = new ilGuidedTourPage();
164 $new_page_object->setParentId($tour_id);
165 $new_page_object->setId($step_id);
166 $new_page_object->createFromXML();
167 }
168
169 // get page object
170 $page_gui = new ilGuidedTourPageGUI($step_id);
171 /*$page_gui->setStyleId(
172 $style->getEffectiveStyleId()
173 );*/
174 $page_gui->setTemplateTargetVar("ADM_CONTENT");
175 $page_gui->setFileDownloadLink("");
176 $page_gui->setPresentationTitle("");
177 $page_gui->setTemplateOutput(false);
178
179 // style tab
180 //$page_gui->setTabHook($this, "addPageTabs");
181
182 return $ctrl->forwardCommand($page_gui);
183 }
184
185
186 protected function listTours(): void
187 {
188 $mt = $this->gui->ui()->mainTemplate();
189 $f = $this->gui->ui()->factory();
190 $r = $this->gui->ui()->renderer();
191 $this->setSubTabs("tours");
192 $ctrl = $this->gui->ctrl();
193 $lng = $this->domain->lng();
194
195 $mt->setOnScreenMessage("info", $lng->txt("gdtr_list_tours_mess"));
196
197 if ($this->edit) {
198 $b = $f->button()->standard(
199 $lng->txt("gdtr_add_tour"),
200 $ctrl->getLinkTarget($this, "addTour")
201 );
202 $this->gui->toolbar()->addComponent($b);
203 $b = $f->button()->standard(
204 $lng->txt("gdtr_import_tour"),
205 $ctrl->getLinkTarget($this, "importTourForm")
206 );
207 $this->gui->toolbar()->addComponent($b);
208 }
209
210 $items = [];
211 $ui_items = [];
212 foreach ($this->tm->getAll() as $tour) {
213 $ctrl->setParameterByClass(self::class, "tour_id", $tour->getId());
214 $actions = [];
215 $actions[] = $f->link()->standard(
216 $lng->txt("gdtr_edit_steps"),
217 $ctrl->getLinkTargetByClass(self::class, "listSteps")
218 );
219 $actions[] = $f->link()->standard(
220 $lng->txt("gdtr_tour_settings"),
221 $ctrl->getLinkTargetByClass(self::class, "editSettings")
222 );
223 $reset_modal = $this->getResetTourModal($tour->getId());
224 $actions[] = $f->button()->shy(
225 $lng->txt("gdtr_reset_tour"),
226 "#"
227 )->withOnClick($reset_modal->getShowSignal());
228 $ui_items[] = $reset_modal;
229 $delete_modal = $this->getDeleteTourModal($tour->getId());
230 $actions[] = $f->button()->shy(
231 $lng->txt("gdtr_delete_tour"),
232 "#"
233 )->withOnClick($delete_modal->getShowSignal());
234 $ui_items[] = $delete_modal;
235 $properties = [];
236 $settings = $this->domain->tourSettings()->getByObjId($tour->getId());
237 $properties[$lng->txt("active")] = $settings?->isActive()
238 ? $lng->txt("yes")
239 : $lng->txt("no");
240 if (!$this->edit) {
241 $actions = [];
242 }
243 $items[] = $f->item()->standard($tour->getTitle())
244 ->withActions($f->dropdown()->standard($actions))
245 ->withProperties($properties);
246 }
247 if (count($items) > 0) {
248 $grp = $f->item()->group("", $items);
249 $panel = $f->panel()->listing()->standard(
250 $lng->txt("gdtr_guided_tours"),
251 [$grp]
252 );
253 $ui_items[] = $panel;
254 $mt->setContent($r->render($ui_items));
255 }
256 }
257
258 protected function getResetTourModal(int $tour_id): \ILIAS\UI\Component\Modal\Interruptive
259 {
260 $tour = $this->tm->getByObjId($tour_id);
261 $f = $this->gui->ui()->factory();
262 $r = $this->gui->ui()->renderer();
263 $lng = $this->domain->lng();
264 $ctrl = $this->gui->ctrl();
265 $res_items = [];
266 $res_items[] = $f->modal()->interruptiveItem()->keyValue(
267 (string) $tour_id,
268 $tour->getTitle(),
269 ""
270 );
271 $ctrl->setParameterByClass(self::class, "tour_id", $tour_id);
272 $action = $ctrl->getLinkTargetByClass(self::class, "resetTour");
273
274 return $f->modal()->interruptive(
275 $lng->txt("gdtr_reset_tour"),
276 $lng->txt("gdtr_reset_tour_mess"),
277 $action
278 )->withAffectedItems($res_items)
279 ->withActionButtonLabel($lng->txt("gdtr_reset_tour"));
280 }
281
282 protected function resetTour(): void
283 {
284 if (!$this->edit) {
285 return;
286 }
287 $mt = $this->gui->ui()->mainTemplate();
288 $lng = $this->domain->lng();
289 $ctrl = $this->gui->ctrl();
290 $tour_id = $this->gui->standardRequest()->getTourId();
291 $this->finish_manager->resetTour($tour_id);
292 $mt->setOnScreenMessage("success", $lng->txt("gdtr_tour_has_been_reset"), true);
293 $ctrl->redirectByClass(self::class, "listTours");
294 }
295
296 protected function getDeleteTourModal(int $tour_id): \ILIAS\UI\Component\Modal\Interruptive
297 {
298 $tour = $this->tm->getByObjId($tour_id);
299 $f = $this->gui->ui()->factory();
300 $r = $this->gui->ui()->renderer();
301 $lng = $this->domain->lng();
302 $ctrl = $this->gui->ctrl();
303 $del_items = [];
304 $del_items[] = $f->modal()->interruptiveItem()->keyValue(
305 (string) $tour_id,
306 $tour->getTitle(),
307 ""
308 );
309 $ctrl->setParameterByClass(self::class, "tour_id", $tour_id);
310 $action = $ctrl->getLinkTargetByClass(self::class, "deleteTour");
311
312 return $f->modal()->interruptive(
313 $lng->txt("gdtr_delete_tour"),
314 $lng->txt("gdtr_delete_tour_mess"),
315 $action
316 )->withAffectedItems($del_items);
317 }
318
319 protected function deleteTour(): void
320 {
321 if (!$this->edit) {
322 return;
323 }
324 $mt = $this->gui->ui()->mainTemplate();
325 $lng = $this->domain->lng();
326 $ctrl = $this->gui->ctrl();
327 $tour_id = $this->gui->standardRequest()->getTourId();
328 $this->tm->deleteTour($tour_id);
329 $mt->setOnScreenMessage("success", $lng->txt("gdtr_deleted_tour"), true);
330 $ctrl->redirectByClass(self::class, "listTours");
331 }
332
333 protected function getCreateForm(): FormAdapterGUI
334 {
335 $lng = $this->domain->lng();
336 return $this->gui->form([self::class], "saveTour")
337 ->section("sec", $lng->txt("gdtr_add_tour"))
338 ->addStdTitleAndDescription(0, "gdtr");
339 }
340
341 protected function addTour(): void
342 {
343 $mt = $this->gui->ui()->mainTemplate();
344 $mt->setContent($this->getCreateForm()->render());
345 }
346
347 public function saveTour(): void
348 {
349 if (!$this->edit) {
350 return;
351 }
352 $mt = $this->gui->ui()->mainTemplate();
353 $lng = $this->domain->lng();
354 $ctrl = $this->gui->ctrl();
355 $form = $this->getCreateForm();
356 if ($form->isValid()) {
357 $obj_id = $this->tm->createTour("dummy", "");
358 $form->saveStdTitleAndDescription($obj_id, "gdtr");
359 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
360 $ctrl->redirectByClass(self::class, "listTours");
361 } else {
362 $mt->setContent($form->render());
363 }
364 }
365
366 protected function editSettings(): void
367 {
368 $this->setStepsHeader();
369 $this->setSettingsTabs("settings");
370 $mt = $this->gui->ui()->mainTemplate();
371 $mt->setContent($this->getSettingsForm()->render());
372 }
373
374 protected function getSettingsForm(): FormAdapterGUI
375 {
376 $tour_id = $this->gui->standardRequest()->getTourId();
377 $lng = $this->domain->lng();
378 $settings = $this->domain->tourSettings()->getByObjId($tour_id);
379 $perm_val = (string) $settings?->getPermission()->value;
380 if ($perm_val === "0") {
381 $perm_val = "";
382 }
383 $lang_val = (string) $settings?->getLanguage();
384 $lang_vals = $this->domain->tourSettings()->getLangOptions($lang_val);
385 if ($perm_val === "0") {
386 $perm_val = "";
387 }
388 return $this
389 ->gui
390 ->form([self::class], "saveSettings")
391 ->section("sec", $lng->txt("settings"))
392 ->addStdTitleAndDescription($tour_id, "gdtr")
393 ->checkbox(
394 "active",
395 $lng->txt("gdtr_active"),
396 "",
397 $settings?->isActive()
398 )
399 ->section("sec2", $lng->txt("gdtr_presentation_limitation"))
400 ->text(
401 "screen_ids",
402 $lng->txt("gdtr_screen_ids"),
403 $lng->txt("gdtr_screen_ids_info"),
404 $settings?->getScreenIds()
405 )
406 ->select(
407 "permission",
408 $lng->txt("gdtr_permission"),
409 [
410 (string) PermissionType::Read->value => $lng->txt("read"),
411 (string) PermissionType::Write->value => $lng->txt("write"),
412 (string) PermissionType::Create->value => $lng->txt("create"),
413 ],
414 $lng->txt("gdtr_permission_info"),
415 $perm_val
416 )
417 ->select(
418 "lang",
419 $lng->txt("gdtr_language"),
420 $lang_vals,
421 $lng->txt("gdtr_language_info"),
422 $lang_val
423 );
424
425 }
426
427 public function saveSettings(): void
428 {
429 if (!$this->edit) {
430 return;
431 }
432 $mt = $this->gui->ui()->mainTemplate();
433 $form = $this->getSettingsForm();
434 $tour_id = $this->gui->standardRequest()->getTourId();
435 $lng = $this->domain->lng();
436 $ctrl = $this->gui->ctrl();
437
438 $tour_settings = $this->domain->tourSettings();
439 if ($form->isValid()) {
440 $form->saveStdTitleAndDescription($tour_id, "gdtr");
441 $tour_settings->save($this->data->settings(
442 $tour_id,
443 (bool) $form->getData("active"),
444 $form->getData("screen_ids"),
445 PermissionType::from((int) $form->getData("permission")),
446 $form->getData("lang")
447 ));
448 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
449 $ctrl->redirectByClass(self::class, "editSettings");
450 } else {
451 $mt->setContent($form->render());
452 }
453 }
454
455
456 protected function setStepsHeader(): void
457 {
458 $tabs = $this->gui->tabs();
459 $lng = $this->domain->lng();
460 $mt = $this->gui->ui()->mainTemplate();
461 $ctrl = $this->gui->ctrl();
462 $tour = $this->tm->getByObjId($this->gui->standardRequest()->getTourId());
463 $mt->setTitle($lng->txt("guided_tour") . ": " . $tour?->getTitle());
464 $mt->setDescription($tour?->getDescription());
465 $tabs->clearTargets();
466 $tabs->setBackTarget(
467 $lng->txt("back"),
468 $ctrl->getLinkTargetByClass(self::class, "listTours")
469 );
470 }
471
472 protected function setSingleStepHeader(): void
473 {
474 $this->setStepsHeader();
475 $tabs = $this->gui->tabs();
476 $lng = $this->domain->lng();
477 $ctrl = $this->gui->ctrl();
478 $tabs->setBackTarget(
479 $lng->txt("back"),
480 $ctrl->getLinkTargetByClass(self::class, "listSteps")
481 );
482 }
483
484 protected function listSteps(): void
485 {
486 $mt = $this->gui->ui()->mainTemplate();
487 $f = $this->gui->ui()->factory();
488 $ctrl = $this->gui->ctrl();
489 $lng = $this->domain->lng();
490
491 $table = $this->getStepTable();
492 if ($table->handleCommand()) {
493 return;
494 }
495
496 $this->setStepsHeader();
497 $this->setSettingsTabs("steps");
498
499 $b = $f->button()->standard(
500 $lng->txt("gdtr_add_step"),
501 $ctrl->getLinkTarget($this, "addStep")
502 );
503 $this->gui->toolbar()->addComponent($b);
504
505 $mt->setContent($table->render());
506 }
507
508 protected function getStepTable(): \ILIAS\Repository\Table\TableAdapterGUI
509 {
510 return $this->gui->stepTableGUI(
511 $this->gui->standardRequest()->getTourId(),
512 $this,
513 "listSteps"
514 );
515 }
516
517 /*
518 public function tableCommand(): void
519 {
520 $table = $this->getStepTable();
521 $table->handleCommand();
522 }*/
523
524 protected function addStep(): void
525 {
526 $this->setSingleStepHeader();
527 $mt = $this->gui->ui()->mainTemplate();
528 $lng = $this->domain->lng();
529 $mt->setOnScreenMessage("info", $lng->txt("gdtr_edit_step_info"));
530 $mt->setContent($this->getStepForm()->render());
531 }
532
533 protected function getStepForm(?Step $step = null): FormAdapterGUI
534 {
535 $lng = $this->domain->lng();
536 $type_val = (string) $step?->getType()->value;
537 $mb_element_id = $step?->getType()->value === StepType::Mainbar->value
538 ? $step?->getElementId()
539 : null;
540 $mt_element_id = $step?->getType()->value === StepType::Metabar->value
541 ? $step?->getElementId()
542 : null;
543 $tab_element_id = $step?->getType()->value === StepType::Tab->value
544 ? $step?->getElementId()
545 : null;
546 return $this->gui->form([self::class], "saveStep")
547 ->section("sec", $lng->txt("gdtr_step"))
548 ->switch("type", $lng->txt("gdtr_step_type"), "", $type_val)
549 ->group((string) StepType::Mainbar->value, $lng->txt("gdtr_mainbar"), $lng->txt("gdtr_mainbar_info"))
550 ->text("mb_element_id", $lng->txt("gdtr_element_id"), "", $mb_element_id)
551 ->group((string) StepType::Metabar->value, $lng->txt("gdtr_metabar"), $lng->txt("gdtr_metabar_info"))
552 ->text("mt_element_id", $lng->txt("gdtr_element_id"), "", $mt_element_id)
553 ->group((string) StepType::Tab->value, $lng->txt("gdtr_tabs"), $lng->txt("gdtr_tabs_info"))
554 ->text("tab_element_id", $lng->txt("gdtr_element_id"), "", $tab_element_id)
555 ->group((string) StepType::Form->value, $lng->txt("gdtr_form"), $lng->txt("gdtr_form_info"))
556 ->group((string) StepType::Table->value, $lng->txt("gdtr_table"), $lng->txt("gdtr_table_info"))
557 ->group((string) StepType::Toolbar->value, $lng->txt("gdtr_toolbar"), $lng->txt("gdtr_toolbar_info"))
558 ->group((string) StepType::PrimaryButton->value, $lng->txt("gdtr_primary_button"), $lng->txt("gdtr_primary_button_info"))
559 ->end();
560 }
561
562 public function saveStep(): void
563 {
564 if (!$this->edit) {
565 return;
566 }
567 $ctrl = $this->gui->ctrl();
568 $mt = $this->gui->ui()->mainTemplate();
569 $oder_nr = 0;
570 if (($step_id = $this->gui->standardRequest()->getStepId()) > 0) {
571 $step = $this->step_manager->getById($step_id);
572 $oder_nr = $step->getOrderNr();
573 }
574 $form = $this->getStepForm();
575 if ($form->isValid()) {
576 $element_id = match ((int) $form->getData("type")) {
577 StepType::Mainbar->value => $form->getData("mb_element_id"),
578 StepType::Metabar->value => $form->getData("mt_element_id"),
579 StepType::Tab->value => $form->getData("tab_element_id"),
580 default => ''
581 };
582 $step = $this->data->step(
583 $step_id,
584 $this->gui->standardRequest()->getTourId(),
585 $oder_nr,
586 StepType::from((int) $form->getData("type")),
587 $element_id
588 );
589 if ($step_id > 0) {
590 $this->step_manager->update($step);
591 $ctrl->redirectByClass(self::class, "listSteps");
592 } else {
593 $new_id = $this->step_manager->create($step);
594 $ctrl->setParameterByClass(self::class, "step_id", $new_id);
595 $ctrl->redirectByClass(ilGuidedTourPageGUI::class, "edit");
596 }
597 } else {
598 $mt->setContent($form->render());
599 }
600 }
601
602 public function editStep(int $step_id): void
603 {
604 $mt = $this->gui->mainTemplate();
605 $lng = $this->domain->lng();
606 $this->setSingleStepHeader();
607 $mt->setOnScreenMessage("info", $lng->txt("gdtr_edit_step_info"));
608 $ctrl = $this->gui->ctrl();
609 $ctrl->setParameterByClass(self::class, "step_id", $step_id);
610 $step = $this->step_manager->getById($step_id);
611 $form = $this->getStepForm($step);
612 $mt->setContent($form->render());
613 }
614
615 public function editPage(int $step_id): void
616 {
617 if (!$this->edit) {
618 return;
619 }
620 $ctrl = $this->gui->ctrl();
621 $ctrl->setParameterByClass(self::class, "step_id", $step_id);
622 $ctrl->redirectByClass(ilGuidedTourPageGUI::class, "edit");
623 }
624
625 protected function setSubTabs(string $active): void
626 {
627 $tabs = $this->gui->tabs();
628 $lng = $this->domain->lng();
629 $ctrl = $this->gui->ctrl();
630 $tabs->addSubTab(
631 "tours",
632 $lng->txt("gdtr_tours"),
633 $ctrl->getLinkTargetByClass(self::class, "listTours")
634 );
635 $tabs->addSubTab(
636 "id_settings",
637 $lng->txt("gdtr_id_settings"),
638 $ctrl->getLinkTargetByClass(self::class, "idSettings")
639 );
640 $tabs->activateSubTab($active);
641 }
642
643 protected function idSettings(): void
644 {
645 $this->setSubTabs("id_settings");
646 $mt = $this->gui->ui()->mainTemplate();
647 $mt->setContent($this->getIdForm()->render());
648 }
649
650 protected function getIdForm(): FormAdapterGUI
651 {
652 $lng = $this->domain->lng();
653 $id_pres = $this->domain->idPresentation();
654 $form = $this
655 ->gui
656 ->form([self::class], "saveIdSettings")
657 ->section("sec", $lng->txt("gdtr_id_settings"))
658 ->text(
659 "users",
660 $lng->txt("gdtr_id_pres_users"),
661 $lng->txt("gdtr_id_pres_users_info"),
662 $id_pres->getIdPresentationUsers()
663 );
664 if (!$this->edit) {
665 $form = $form->disabled();
666 }
667 return $form;
668 }
669
670 protected function saveIdSettings(): void
671 {
672 $mt = $this->gui->ui()->mainTemplate();
673 $lng = $this->domain->lng();
674 $ctrl = $this->gui->ctrl();
675 $form = $this->getIdForm();
676 if ($this->edit) {
677 $id_pres = $this->domain->idPresentation();
678 $id_pres->saveIdPresentationUsers($form->getData("users"));
679 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
680 }
681 $ctrl->redirectByClass(self::class, "idSettings");
682 }
683
684 protected function saveOrder(): void
685 {
686 if (!$this->edit) {
687 return;
688 }
689 $ctrl = $this->gui->ctrl();
690 $mt = $this->gui->ui()->mainTemplate();
691 $lng = $this->domain->lng();
692 $ctrl->saveParameterByClass(self::class, "tour_id");
693
694 $table = $this->getStepTable();
695 $data = $table->getData();
696 if (is_array($data)) {
697 $this->step_manager->saveOrder(
698 $this->gui->standardRequest()->getTourId(),
699 $data
700 );
701 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
702 }
703 $ctrl->redirectByClass(self::class, "listSteps");
704 }
705
706 public function confirmStepDeletion(int $step_id): void
707 {
708 $lng = $this->domain->lng();
709 $ctrl = $this->gui->ctrl();
710 $table = $this->getStepTable();
711 $step = $this->step_manager->getById($step_id);
712 $ctrl->setParameterByClass(self::class, "step_id", $step_id);
713 $title = $this->step_manager->getStepName($step->getType());
714 if ($step->getElementId() !== "") {
715 $title .= " (" . $step->getElementId() . ")";
716 }
717 $table->renderDeletionConfirmation(
718 $lng->txt("gdtr_delete_step"),
719 $lng->txt("gdtr_delete_step_mess"),
720 "deleteStep",
721 [
722 $step_id => $title
723 ]
724 );
725 }
726
727 public function deleteStep(): void
728 {
729 if (!$this->edit) {
730 return;
731 }
732 $ctrl = $this->gui->ctrl();
733 $mt = $this->gui->ui()->mainTemplate();
734 $lng = $this->domain->lng();
735 $tour_id = $this->gui->standardRequest()->getTourId();
736 $step_id = $this->gui->standardRequest()->getStepId();
737
738 $this->step_manager->delete($tour_id, $step_id);
739 $mt->setOnScreenMessage("success", $lng->txt("gdtr_deleted_step"), true);
740 $ctrl->redirectByClass(self::class, "listSteps");
741 }
742
743 protected function importTourForm(): void
744 {
745 $mt = $this->gui->ui()->mainTemplate();
746 $mt->setContent($this->getImportForm()->render());
747 }
748
749 protected function getImportForm(): FormAdapterGUI
750 {
751 $lng = $this->domain->lng();
752 return $this->gui->form([self::class], "importTour")
753 ->section("sec", $lng->txt("gdtr_import_tour"))
754 ->file(
755 "import",
756 $lng->txt("import_file"),
757 $this->handleImportUpload(...),
758 "id",
759 "",
760 1,
761 ["application/zip"]
762 );
763 }
764
765 protected function handleImportUpload(
766 FileUpload $upload,
767 UploadResult $result
769 $new_id = 0;
770 if ($this->edit) {
771 $new_id = $this->importTourFile($result->getName(), $result->getPath());
772 }
773 return new BasicHandlerResult(
774 '',
775 \ILIAS\FileUpload\Handler\HandlerResult::STATUS_OK,
776 (string) $new_id,
777 ''
778 );
779 }
780
781
782 protected function importTourFile(
783 string $filename,
784 string $path
785 ): int {
786 $new_id = 0;
787 if (!$this->edit) {
788 return $new_id;
789 }
790 $fname = explode("_", $filename);
791 if ($fname[4] == "gdtr") {
792 $imp = new ilImport();
793 $new_id = $imp->importObject(
794 null,
795 $path,
796 $filename,
797 "gdtr",
798 "",
799 true
800 );
801 }
802 return $new_id;
803 }
804
805 protected function importTour(): void
806 {
807 $ctrl = $this->gui->ctrl();
808 $ctrl->redirectByClass(self::class, "listTours");
809 }
810}
$filename
Definition: buildRTE.php:78
Export User Interface Class.
@ilCtrl_Calls ilGuidedTourAdminGUI: ilGuidedTourPageGUI, ilExportGUI, ilRepoStandardUploadHandlerGUI
ILIAS Help GuidedTour Step StepManager $step_manager
__construct(protected \ILIAS\Help\GuidedTour\InternalDataService $data, protected \ILIAS\Help\GuidedTour\InternalDomainService $domain, protected \ILIAS\Help\GuidedTour\InternalGUIService $gui, protected bool $edit=false)
importTourFile(string $filename, string $path)
ILIAS Help GuidedTour UserFinished UserFinishedManager $finish_manager
ILIAS Help GuidedTour Tour TourManager $tm
handleImportUpload(FileUpload $upload, UploadResult $result)
@ilCtrl_Calls ilGuidedTourPageGUI: ilPageEditorGUI, ilEditClipboardGUI, ilMDEditorGUI @ilCtrl_Calls i...
Import class.
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
$path
Definition: ltiservices.php:30
addStdTitleAndDescription(int $obj_id, string $type)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:26
getLanguage()