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