ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilWOPIAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 use ILIAS\Data\URI;
33 
40 {
41  public const CMD_DEFAULT = "index";
42  public const CMD_STORE = "store";
43  public const CMD_SHOW = 'show';
46  private Services $http;
47  private ilLanguage $lng;
50  private Crawler $crawler;
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(
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 }
ilGlobalTemplateInterface $maint_tpl
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
This is how the factory for UI elements looks.
Definition: Factory.php:37
Common interface to all items.
Definition: Item.php:31
global $DIC
Definition: shib_login.php:26
ActionTarget
Officialy supported action targets, see https://learn.microsoft.com/en-us/openspecs/office_protocols/...
$info
Definition: entry_point.php:21