ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilWOPIEmbeddedApplicationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
27 
32 {
33  public const CMD_EDIT = 'edit';
34  public const CMD_VIEW = 'view';
35  public const CMD_RETURN = 'return';
36  public const P_RETURN_TO = 'return_to';
44  private ilTabsGUI $tabs;
56  private \ILIAS\UI\Renderer $ui_renderer;
64  private Factory $refinery;
72  private ilLanguage $lng;
73 
74  public function __construct(
75  private EmbeddedApplication $application,
76  ) {
77  global $DIC;
78  $this->main_tpl = $DIC->ui()->mainTemplate();
79  $this->tabs = $DIC->tabs();
80  $this->global_screen = $DIC->globalScreen();
81  $this->global_screen->layout()->meta()->addJs('./assets/js/wopi.min.js');
82  $this->global_screen->layout()->meta()->addOnloadCode('il.WOPI.init();');
83  $this->renderer = new Renderer($this->application);
84  $this->ui_renderer = $DIC->ui()->renderer();
85  $this->http = $DIC->http()->wrapper()->query();
86  $this->refinery = $DIC->refinery();
87  $this->ctrl = $DIC->ctrl();
88  $this->lng = $DIC->language();
89  $this->lng->loadLanguageModule('wopi');
90  }
91 
92  public function executeCommand(): void
93  {
94  if (!$this->application->isInline()) {
95  $this->tabs->clearTargets();
96  }
97  $this->global_screen->tool()->context()->current()->addAdditionalData(
98  EmbeddedApplicationGSProvider::EMBEDDED_APPLICATION,
99  $this->application
100  );
101  $a_value = bin2hex((string) $this->application->getBackTarget());
102  $this->ctrl->setParameter($this, self::P_RETURN_TO, $a_value);
103 
104  match ($this->ctrl->getCmd()) {
105  default => $this->edit(),
106  self::CMD_EDIT => $this->edit(),
107  self::CMD_VIEW => $this->view(),
108  self::CMD_RETURN => $this->return(),
109  };
110  }
111 
112  private function view(): void
113  {
114  $this->main_tpl->setContent(
115  $this->ui_renderer->render($this->renderer->getComponent())
116  );
117  }
118 
119  private function edit(): void
120  {
121  $this->main_tpl->setContent(
122  $this->ui_renderer->render($this->renderer->getComponent())
123  );
124  }
125 
126  private function return(): void
127  {
128  $return_to = $this->http->has(self::P_RETURN_TO)
129  ? hex2bin((string) $this->http->retrieve(self::P_RETURN_TO, $this->refinery->kindlyTo()->string()))
130  : null;
131 
132  if ($return_to === null) {
133  $return_to = (string) $this->application->getBackTarget();
134  }
135 
136  $this->main_tpl->setOnScreenMessage(
137  'info',
138  $this->lng->txt('close_wopi_editor_info'),
139  true
140  );
141 
142  $this->ctrl->redirectToURL($return_to);
143  }
144 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private EmbeddedApplication $application,)
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...