ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWOPIAdministrationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
33
40{
41 public const CMD_DEFAULT = "index";
42 public const CMD_STORE = "store";
43 public const CMD_SHOW = 'show';
46 private Services $http;
51 private ?int $ref_id = null;
56
57 public function __construct()
58 {
59 global $DIC;
60 $this->ctrl = $DIC->ctrl();
61 $this->access = $DIC->access();
62 $this->http = $DIC->http();
63 $this->settings = $DIC->settings();
64 $this->lng = $DIC->language();
65 $this->lng->loadLanguageModule("wopi");
66 $this->maint_tpl = $DIC->ui()->mainTemplate();
67 $this->ref_id = $this->http->wrapper()->query()->has("ref_id")
68 ? (int) $this->http->wrapper()->query()->retrieve(
69 "ref_id",
70 $DIC->refinery()->to()->string()
71 )
72 : null;
73 $this->crawler = new Crawler();
74 $this->action_repo = new ActionDBRepository($DIC->database());
75 $this->app_repo = new AppDBRepository($DIC->database());
76
77 $this->ui_factory = $DIC->ui()->factory();
78 $this->ui_renderer = $DIC->ui()->renderer();
79 }
80
81 public function executeCommand(): void
82 {
83 if (!$this->access->checkAccess("read", "", $this->ref_id)) {
84 $this->maint_tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
85 $this->ctrl->redirectByClass(ilObjExternalToolsSettingsGUI::class);
86 }
87
88 $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT);
89 match ($cmd) {
90 self::CMD_DEFAULT => $this->index(),
91 self::CMD_SHOW => $this->show(),
92 self::CMD_STORE => $this->store(),
93 default => throw new ilException("command not found: " . $cmd),
94 };
95 }
96
97 private function index(): void
98 {
99 $supported_suffixes = $this->getSupportedSuffixes();
100 $info = '';
101 if (!empty($supported_suffixes)) {
102 $listing = $this->ui_factory->panel()->secondary()->legacy(
103 $this->lng->txt("currently_supported"),
104 $this->ui_factory->legacy()->content(
105 $this->ui_renderer->render(
106 $this->ui_factory->listing()->descriptive([
107 $this->lng->txt('action_edit') => implode(", ", $supported_suffixes[ActionTarget::EDIT->value]),
108 $this->lng->txt('action_view') => implode(", ", $supported_suffixes[ActionTarget::VIEW->value]),
109 ])
110 )
111 )
112 );
113 $info = $this->ui_renderer->render($listing);
114 }
115
116 $form = new ilWOPISettingsForm(
117 $this->settings,
118 $this->access->checkAccess("write", "", $this->ref_id)
119 );
120
121 $this->maint_tpl->setContent(
122 $form->getHTML()
123 );
124
125 $this->maint_tpl->setRightContent($info);
126 }
127
128 private function getSupportedSuffixes(): array
129 {
130 $wopi_activated = (bool) $this->settings->get("wopi_activated", '0');
131 if (!$wopi_activated) {
132 return [];
133 }
134 return [
135 ActionTarget::EDIT->value => $this->action_repo->getSupportedSuffixes(ActionTarget::EDIT),
136 ActionTarget::VIEW->value => $this->action_repo->getSupportedSuffixes(ActionTarget::VIEW),
137 ];
138 }
139
140 private function show(): void
141 {
142 $actions = array_map(
143 fn(Action $action): Item => $this->ui_factory->item()->standard($action->getExtension())->withProperties([
144 $this->lng->txt('launcher_url') => (string) $action->getLauncherUrl(),
145 $this->lng->txt('action') => $action->getName()
146 ]),
147 $this->action_repo->getActionsForTargets(ActionTarget::EDIT, ActionTarget::EMBED_EDIT)
148 );
149
150 $this->maint_tpl->setContent(
151 $this->ui_renderer->render(
152 $this->ui_factory->item()->group(
153 $this->lng->txt('actions'),
154 $actions
155 )
156 )
157 );
158 }
159
160 private function store(): void
161 {
162 if (!$this->access->checkAccess("write", "", $this->ref_id)) {
163 $this->maint_tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
164 $this->ctrl->redirect($this, self::CMD_DEFAULT);
165 }
166
167 $form = new ilWOPISettingsForm(
168 $this->settings,
169 $this->access->checkAccess("write", "", $this->ref_id)
170 );
171
172 if ($form->proceed($this->http->request())) {
173 global $DIC;
174
175 $this->maint_tpl->setOnScreenMessage('success', $this->lng->txt("msg_wopi_settings_modified"), true);
176
177 // Crawl
178 $discovery_url = $this->settings->get("wopi_discovery_url");
179 if ($discovery_url === null) {
180 $this->app_repo->clear($this->action_repo);
181 } else {
182 $apps = $this->crawler->crawl(new URI($discovery_url));
183 if ($apps !== null) {
184 $this->app_repo->storeCollection($apps, $this->action_repo);
185 }
186 }
187
188 $this->ctrl->redirect($this, self::CMD_DEFAULT);
189 }
190
191 $this->maint_tpl->setContent($form->getHTML());
192 }
193}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Class Services.
Definition: Services.php:38
Base class for ILIAS Exception handling.
language handling
ILIAS Setting Class.
ilGlobalTemplateInterface $maint_tpl
$info
Definition: entry_point.php:21
Common interface to all items.
Definition: Item.php:32
withProperties(array $properties)
Get a new item with the given properties as key-value pairs.
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
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
ActionTarget
Officialy supported action targets, see https://learn.microsoft.com/en-us/openspecs/office_protocols/...
global $DIC
Definition: shib_login.php:26