ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilWOPIAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 use ILIAS\Data\URI;
29 
36 {
37  public const CMD_DEFAULT = "index";
38  public const CMD_STORE = "store";
39  public const CMD_SHOW = 'show';
42  private \ILIAS\HTTP\Services $http;
43  private ilLanguage $lng;
46  private Crawler $crawler;
47  private ?int $ref_id = null;
50  private \ILIAS\UI\Factory $ui_factory;
51  private \ILIAS\UI\Renderer $ui_renderer;
52 
53  public function __construct()
54  {
55  global $DIC;
56  $this->ctrl = $DIC->ctrl();
57  $this->access = $DIC->access();
58  $this->http = $DIC->http();
59  $this->settings = $DIC->settings();
60  $this->lng = $DIC->language();
61  $this->lng->loadLanguageModule("wopi");
62  $this->maint_tpl = $DIC->ui()->mainTemplate();
63  $this->ref_id = $this->http->wrapper()->query()->has("ref_id")
64  ? (int) $this->http->wrapper()->query()->retrieve(
65  "ref_id",
66  $DIC->refinery()->to()->string()
67  )
68  : null;
69  $this->crawler = new Crawler();
70  $this->action_repo = new ActionDBRepository($DIC->database());
71  $this->app_repo = new AppDBRepository($DIC->database());
72 
73  $this->ui_factory = $DIC->ui()->factory();
74  $this->ui_renderer = $DIC->ui()->renderer();
75  }
76 
77  public function executeCommand(): void
78  {
79  if (!$this->access->checkAccess("read", "", $this->ref_id)) {
80  $this->maint_tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
81  $this->ctrl->redirectByClass(ilObjExternalToolsSettingsGUI::class);
82  }
83 
84  $cmd = $this->ctrl->getCmd(self::CMD_DEFAULT);
85  match ($cmd) {
86  self::CMD_DEFAULT => $this->index(),
87  self::CMD_SHOW => $this->show(),
88  self::CMD_STORE => $this->store(),
89  default => throw new ilException("command not found: " . $cmd),
90  };
91  }
92 
93  private function index(): void
94  {
95  $supported_suffixes = $this->getSupportedSuffixes();
96  if (!empty($supported_suffixes)) {
97  $this->maint_tpl->setOnScreenMessage(
98  'info',
99  sprintf(
100  $this->lng->txt("currently_supported"),
101  implode(", ", $supported_suffixes)
102  )
103  );
104  }
105 
106  $form = new ilWOPISettingsForm($this->settings);
107 
108  $this->maint_tpl->setContent(
109  $form->getHTML()
110  );
111  }
112 
113  private function getSupportedSuffixes(): array
114  {
115  $wopi_activated = (bool) $this->settings->get("wopi_activated", '0');
116  if (!$wopi_activated) {
117  return [];
118  }
119  return $this->action_repo->getSupportedSuffixes(ActionTarget::EDIT);
120  }
121 
122  private function show(): void
123  {
124  $actions = array_map(
125  function (Action $action) {
126  return $this->ui_factory->item()->standard($action->getExtension())->withProperties([
127  $this->lng->txt('launcher_url') => (string) $action->getLauncherUrl(),
128  $this->lng->txt('action') => $action->getName()
129  ]);
130  },
131  $this->action_repo->getActionsForTargets(ActionTarget::EDIT, ActionTarget::EMBED_EDIT)
132  );
133 
134  $this->maint_tpl->setContent(
135  $this->ui_renderer->render(
136  $this->ui_factory->item()->group(
137  $this->lng->txt('actions'),
138  $actions
139  )
140  )
141  );
142  }
143 
144  private function store(): void
145  {
146  $form = new ilWOPISettingsForm($this->settings);
147 
148  if ($form->proceed($this->http->request())) {
149  global $DIC;
150 
151  $this->maint_tpl->setOnScreenMessage('success', $this->lng->txt("msg_wopi_settings_modified"), true);
152 
153  // Crawl
154  $discovery_url = $this->settings->get("wopi_discovery_url");
155  if ($discovery_url === null) {
156  $this->app_repo->clear($this->action_repo);
157  } else {
158  $apps = $this->crawler->crawl(new URI($discovery_url));
159  if ($apps !== null) {
160  $this->app_repo->storeCollection($apps, $this->action_repo);
161  }
162  }
163 
164  $this->ctrl->redirect($this, self::CMD_DEFAULT);
165  }
166 
167  $this->maint_tpl->setContent($form->getHTML());
168  }
169 }
ilGlobalTemplateInterface $maint_tpl
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:18
ActionTarget
Officialy supported action targets, see https://learn.microsoft.com/en-us/openspecs/office_protocols/...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Crawler.php:21