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