ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilContentPagePageCommandForwarder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\Refinery\Factory as Refinery;
26
28{
32 final public const string PRESENTATION_MODE_EDITING = 'PRESENTATION_MODE_EDITING';
33
37 final public const string PRESENTATION_MODE_PRESENTATION = 'PRESENTATION_MODE_PRESENTATION';
38
42 final public const string PRESENTATION_MODE_EMBEDDED_PRESENTATION = 'PRESENTATION_MODE_EMBEDDED_PRESENTATION';
43 final public const string PRESENTATION_MODE_PREVIEW = 'PRESENTATION_MODE_PREVIEW';
44
46 protected string $backUrl = '';
48 protected array $updateListeners = [];
49 protected bool $isMediaRequest = false;
50
51 public function __construct(
52 protected GlobalHttpState $http,
53 protected ilCtrlInterface $ctrl,
54 protected ilTabsGUI $tabs,
55 protected ilLanguage $lng,
56 protected ilObjContentPage $parentObject,
57 protected Translations $translation,
58 protected ilObjUser $actor,
59 protected Refinery $refinery,
60 protected ObjectFacade $content_style_domain
61 ) {
62 $this->lng->loadLanguageModule('content');
63
64 $this->backUrl = '';
65 if ($this->http->wrapper()->query()->has('backurl')) {
66 $this->backUrl = $this->http->wrapper()->query()->retrieve(
67 'backurl',
68 $this->refinery->kindlyTo()->string()
69 );
70 }
71
72 if ($this->backUrl !== '') {
73 $this->ctrl->setParameterByClass(ilContentPagePageGUI::class, 'backurl', rawurlencode($this->backUrl));
74 }
75 }
76
77 public function setIsMediaRequest(bool $isMediaRequest): void
78 {
79 $this->isMediaRequest = $isMediaRequest;
80 }
81
85 public function onPageUpdate(array $parameters): void
86 {
87 foreach ($this->updateListeners as $listener) {
88 $listener(new PageUpdatedEvent($parameters['page']));
89 }
90 }
91
92 public function addPageTabs(): void
93 {
94 $this->ctrl->setParameterByClass(ilObjectContentStyleSettingsGUI::class, self::HTTP_PARAM_PAGE_EDITOR_STYLE_CONTEXT, '1');
95 $this->tabs->addTarget(
96 'obj_sty',
97 $this->ctrl->getLinkTargetByClass(ilObjectContentStyleSettingsGUI::class),
98 'editStyleProperties',
99 strtolower(ilObjectContentStyleSettingsGUI::class)
100 );
101 $this->ctrl->setParameterByClass(ilObjContentPageGUI::class, self::HTTP_PARAM_PAGE_EDITOR_STYLE_CONTEXT, null);
102 }
103
107 public function updateContentPageOnPageUpdate(array $parameters): void
108 {
109 $this->parentObject->update();
110 }
111
112 public function addUpdateListener(callable $updateListener): void
113 {
114 $this->updateListeners[] = $updateListener;
115 }
116
117 protected function getPageObjectGUI(string $language, bool $isEmbedded = false): ilContentPagePageGUI
118 {
119 $pageObjectGUI = new ilContentPagePageGUI($this->parentObject->getId(), 0, $isEmbedded, $language);
120 $pageObjectGUI->setStyleId(
121 $this->content_style_domain->getEffectiveStyleId()
122 );
123
124 $pageObjectGUI->obj->addUpdateListener($this, 'updateContentPageOnPageUpdate', []);
125
126 return $pageObjectGUI;
127 }
128
129 protected function doesPageExistsForLanguage(string $language): bool
130 {
131 return ilContentPagePage::_exists($this->parentObject->getType(), $this->parentObject->getId(), $language);
132 }
133
134 protected function ensurePageObjectExists(string $language): void
135 {
136 if (!$this->doesPageExistsForLanguage($language)) {
137 $pageObject = new ilContentPagePage();
138 $pageObject->setParentId($this->parentObject->getId());
139 $pageObject->setId($this->parentObject->getId());
140 $pageObject->setLanguage($language);
141 $pageObject->createFromXML();
142 }
143 }
144
145 protected function setBackLinkTab(): void
146 {
147 $backUrl = $this->ctrl->getLinkTargetByClass(ilContentPagePageGUI::class, self::UI_CMD_COPAGE_EDIT);
148 if ($this->backUrl !== '') {
149 $backUrlParts = parse_url(ilUtil::stripSlashes($this->backUrl));
150
151 $script = basename($backUrlParts['path']);
152
153 $backUrl = './' . implode('?', [
154 $script, $backUrlParts['query']
155 ]);
156 }
157
158 $this->tabs->setBackTarget($this->lng->txt('back'), $backUrl);
159 }
160
161 protected function buildEditingPageObjectGUI(string $language): ilContentPagePageGUI
162 {
163 $this->tabs->clearTargets();
164
165 $this->setBackLinkTab();
166
167 $this->ensurePageObjectExists($language);
168
169 $pageObjectGUI = $this->getPageObjectGUI($language);
170 $pageObjectGUI->setEnabledTabs(true);
171
172 $page = $pageObjectGUI->getPageObject();
173 $page->addUpdateListener($this, 'onPageUpdate', ['page' => $page]);
174
175 $pageObjectGUI->setTabHook($this, 'addPageTabs');
176
177 return $pageObjectGUI;
178 }
179
180 protected function buildPresentationPageObjectGUI(string $language): ilContentPagePageGUI
181 {
182 $this->ensurePageObjectExists($language);
183
184 $pageObjectGUI = $this->getPageObjectGUI($language);
185 $pageObjectGUI->setEnabledTabs(false);
186
187 $pageObjectGUI->setStyleId(
188 $this->content_style_domain->getEffectiveStyleId()
189 );
190
191 return $pageObjectGUI;
192 }
193
194 protected function buildPreviewPageObjectGUI(string $language): ilContentPagePageGUI
195 {
196 $this->ensurePageObjectExists($language);
197
198 $pageObjectGUI = $this->getPageObjectGUI($language);
199
200 $pageObjectGUI->setStyleId(
201 $this->content_style_domain->getEffectiveStyleId()
202 );
203
204 $pageObjectGUI->setTabHook($this, 'addPageTabs');
205
206 return $pageObjectGUI;
207 }
208
210 {
211 $this->ensurePageObjectExists($language);
212
213 $pageObjectGUI = $this->getPageObjectGUI($language, true);
214 $pageObjectGUI->setEnabledTabs(false);
215
216 $pageObjectGUI->setStyleId(
217 $this->content_style_domain->getEffectiveStyleId()
218 );
219
220 return $pageObjectGUI;
221 }
222
223 public function setPresentationMode(string $presentationMode): void
224 {
225 $this->presentationMode = $presentationMode;
226 }
227
232 public function forward(string $ctrlLink = ''): string
233 {
234 $language = $this->translation->getEffectiveCOPageLang($this->actor->getCurrentLanguage(), $this->parentObject->getType());
235
236 switch ($this->presentationMode) {
238
239 $pageObjectGui = $this->buildEditingPageObjectGUI($this->isMediaRequest ? $language : '');
240 return (string) $this->ctrl->forwardCommand($pageObjectGui);
241
243 $pageObjectGui = $this->buildPreviewPageObjectGUI($this->isMediaRequest ? $language : '');
244 return $this->ctrl->getHTML($pageObjectGui);
245
247 $pageObjectGUI = $this->buildPresentationPageObjectGUI($language);
248
249 if (is_string($ctrlLink) && $ctrlLink !== '') {
250 $pageObjectGUI->setFileDownloadLink($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DOWNLOAD_FILE);
251 $pageObjectGUI->setFullscreenLink($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DISPLAY_FULLSCREEN);
252 $pageObjectGUI->setSourcecodeDownloadScript($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DOWNLOAD_PARAGRAPH);
253 }
254
255 return $this->ctrl->getHTML($pageObjectGUI);
256
258 $pageObjectGUI = $this->buildEmbeddedPresentationPageObjectGUI($language);
259
260 if (is_string($ctrlLink) && $ctrlLink !== '') {
261 $pageObjectGUI->setFileDownloadLink($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DOWNLOAD_FILE);
262 $pageObjectGUI->setFullscreenLink($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DISPLAY_FULLSCREEN);
263 $pageObjectGUI->setSourcecodeDownloadScript($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DOWNLOAD_PARAGRAPH);
264 }
265
266 return $pageObjectGUI->getHTML();
267
268 default:
269 throw new ilException('Unknown presentation mode given');
270 }
271 }
272}
Builds data types.
Definition: Factory.php:36
Class handles translation mode for an object.
External facade for object content styles.
final const string PRESENTATION_MODE_EDITING
presentation mode for authoring
final const string PRESENTATION_MODE_EMBEDDED_PRESENTATION
presentation mode for embedded presentation, e.g.
__construct(protected GlobalHttpState $http, protected ilCtrlInterface $ctrl, protected ilTabsGUI $tabs, protected ilLanguage $lng, protected ilObjContentPage $parentObject, protected Translations $translation, protected ilObjUser $actor, protected Refinery $refinery, protected ObjectFacade $content_style_domain)
getPageObjectGUI(string $language, bool $isEmbedded=false)
final const string PRESENTATION_MODE_PRESENTATION
presentation mode for requesting
@ilCtrl_Calls ilContentPagePageGUI: ilPageEditorGUI, ilEditClipboardGUI, ilMDEditorGUI @ilCtrl_Calls ...
Base class for ILIAS Exception handling.
language handling
User class.
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$http
Definition: deliver.php:30
Interface GlobalHttpState.
Interface ilContentPageObjectConstants.
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.
global $lng
Definition: privfeed.php:31