ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ModalGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Mount;
22
26use ilLanguage;
27use InvalidArgumentException;
28
30{
31 private const string MOUNT_INSTRUCTIONS_CONTENT_ID = 'webdav_mount_instructions_content';
32 private static bool $modal_already_rendered = false;
33
35
36 private function __construct(
37 protected Repository $repository,
38 protected Factory $ui_factory,
39 protected Renderer $ui_renderer,
40 protected ilLanguage $lng
41 ) {
42 try {
43 $document = $this->repository->getMountInstructionsByLanguage($this->lng->getUserLanguage());
44 $title = $document->getTitle();
45 } catch (InvalidArgumentException) {
46 $title = $this->lng->txt('webfolder_instructions_titletext');
47 }
48
49 $content_div = '<div id="' . self::MOUNT_INSTRUCTIONS_CONTENT_ID . '"></div>';
50 $page = $this->ui_factory->modal()->lightboxTextPage($content_div, $title);
51 $this->modal = $this->ui_factory->modal()->lightbox($page);
52 }
53
54 private function getRenderedModal(): string
55 {
56 return $this->ui_renderer->render($this->modal);
57 }
58
59 private function getModalShowSignalId(): string
60 {
61 return $this->modal->getShowSignal()->getId();
62 }
63
64 public static function maybeRenderWebDAVModalInGlobalTpl(): void
65 {
66 if (self::$modal_already_rendered) {
67 return;
68 }
69
70 global $DIC;
71 $repository = new RepositoryDB($DIC->database());
72 $instance = new self(
73 $repository,
74 $DIC->ui()->factory(),
75 $DIC->ui()->renderer(),
76 $DIC->language()
77 );
78
79 self::$modal_already_rendered = true;
80 $js_function = '<script>function triggerWebDAVModal(api_url){ $.ajax(api_url).done(function(data){ $(document).trigger("'
81 . $instance->getModalShowSignalId()
82 . '", "{}"); $("#' . self::MOUNT_INSTRUCTIONS_CONTENT_ID . '").html(data);}) }</script>';
83
84 $webdav_modal_html = $instance->getRenderedModal() . $js_function;
85
86 $tpl = $DIC->ui()->mainTemplate();
87 $tpl->setVariable('WEBDAV_MODAL', $webdav_modal_html);
88 }
89}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
static maybeRenderWebDAVModalInGlobalTpl()
Definition: ModalGUI.php:64
static bool $modal_already_rendered
Definition: ModalGUI.php:32
__construct(protected Repository $repository, protected Factory $ui_factory, protected Renderer $ui_renderer, protected ilLanguage $lng)
Definition: ModalGUI.php:36
const string MOUNT_INSTRUCTIONS_CONTENT_ID
Definition: ModalGUI.php:31
language handling
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
modal(string $title="", string $cancel_label="")
global $lng
Definition: privfeed.php:26
global $DIC
Definition: shib_login.php:26