ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilContentPagePageCommandForwarder.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
12  const PRESENTATION_MODE_EDITING = 'PRESENTATION_MODE_EDITING';
13 
17  const PRESENTATION_MODE_PRESENTATION = 'PRESENTATION_MODE_PRESENTATION';
18 
22  const PRESENTATION_MODE_EMBEDDED_PRESENTATION = 'PRESENTATION_MODE_EMBEDDED_PRESENTATION';
23 
27  protected $presentationMode = self::PRESENTATION_MODE_EDITING;
28 
32  protected $ctrl;
33 
37  protected $lng;
38 
42  protected $tabs;
43 
47  protected $parentObject;
48 
52  protected $backUrl = '';
53 
62  public function __construct(
63  \Psr\Http\Message\ServerRequestInterface $request,
64  \ilCtrl $ctrl,
68  ) {
69  $this->ctrl = $ctrl;
70  $this->tabs = $tabs;
71  $this->lng = $lng;
72  $this->parentObject = $parentObject;
73 
74  $this->lng->loadLanguageModule('content');
75 
76  $this->backUrl = $request->getQueryParams()['backurl'] ?? '';
77 
78  if (strlen($this->backUrl) > 0) {
79  $this->ctrl->setParameterByClass('ilcontentpagepagegui', 'backurl', rawurlencode($this->backUrl));
80  }
81  }
82 
87  protected function getPageObjectGUI($isEmbedded = false) : \ilContentPagePageGUI
88  {
89  $pageObjectGUI = new \ilContentPagePageGUI($this->parentObject->getId(), 0, $isEmbedded);
90  $pageObjectGUI->setStyleId(
92  $this->parentObject->getStyleSheetId(),
93  $this->parentObject->getType()
94  )
95  );
96 
97  $pageObjectGUI->obj->addUpdateListener($this->parentObject, 'update');
98 
99  return $pageObjectGUI;
100  }
101 
105  protected function ensurePageObjectExists()
106  {
107  if (!\ilContentPagePage::_exists($this->parentObject->getType(), $this->parentObject->getId())) {
108  $pageObject = new \ilContentPagePage();
109  $pageObject->setParentId($this->parentObject->getId());
110  $pageObject->setId($this->parentObject->getId());
111  $pageObject->createFromXML();
112  }
113  }
114 
118  protected function setBackLinkTab()
119  {
120  $backUrl = $this->ctrl->getLinkTargetByClass('ilObjContentPageGUI', self::UI_CMD_VIEW);
121  if (strlen($this->backUrl) > 0) {
122  $backUrlParts = parse_url(\ilUtil::stripSlashes($this->backUrl));
123 
124  $script = basename($backUrlParts['path']);
125 
126  $backUrl = './' . implode('?', [
127  $script, $backUrlParts['query']
128  ]);
129  }
130 
131  $this->tabs->setBackTarget($this->lng->txt('back'), $backUrl);
132  }
133 
138  {
139  $this->tabs->clearTargets();
140 
141  $this->setBackLinkTab();
142 
143  $this->ensurePageObjectExists();
144 
145  $pageObjectGUI = $this->getPageObjectGUI();
146  $pageObjectGUI->setEnabledTabs(true);
147 
148  return $pageObjectGUI;
149  }
150 
155  {
156  $this->ensurePageObjectExists();
157 
158  $pageObjectGUI = $this->getPageObjectGUI();
159  $pageObjectGUI->setEnabledTabs(false);
160 
161  $pageObjectGUI->setStyleId(
163  $this->parentObject->getStyleSheetId(),
164  $this->parentObject->getType()
165  )
166  );
167 
168  return $pageObjectGUI;
169  }
170 
175  {
176  $this->ensurePageObjectExists();
177 
178  $pageObjectGUI = $this->getPageObjectGUI(true);
179  $pageObjectGUI->setEnabledTabs(false);
180 
181  $pageObjectGUI->setStyleId(
183  $this->parentObject->getStyleSheetId(),
184  $this->parentObject->getType()
185  )
186  );
187 
188  return $pageObjectGUI;
189  }
190 
194  public function setPresentationMode(string $presentationMode)
195  {
196  $this->presentationMode = $presentationMode;
197  }
198 
205  public function forward(string $ctrlLink = '') : string
206  {
207  switch ($this->presentationMode) {
208  case self::PRESENTATION_MODE_EDITING:
209 
210  $pageObjectGui = $this->buildEditingPageObjectGUI();
211  return (string) $this->ctrl->forwardCommand($pageObjectGui);
212 
213  case self::PRESENTATION_MODE_PRESENTATION:
214  $pageObjectGUI = $this->buildPresentationPageObjectGUI();
215 
216  if (is_string($ctrlLink) && strlen($ctrlLink) > 0) {
217  $pageObjectGUI->setFileDownloadLink($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DOWNLOAD_FILE);
218  $pageObjectGUI->setFullscreenLink($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DISPLAY_FULLSCREEN);
219  $pageObjectGUI->setSourcecodeDownloadScript($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DOWNLOAD_PARAGRAPH);
220  }
221 
222  return $this->ctrl->getHTML($pageObjectGUI);
223 
224  case self::PRESENTATION_MODE_EMBEDDED_PRESENTATION:
225  $pageObjectGUI = $this->buildEmbeddedPresentationPageObjectGUI();
226 
227  if (is_string($ctrlLink) && strlen($ctrlLink) > 0) {
228  $pageObjectGUI->setFileDownloadLink($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DOWNLOAD_FILE);
229  $pageObjectGUI->setFullscreenLink($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DISPLAY_FULLSCREEN);
230  $pageObjectGUI->setSourcecodeDownloadScript($ctrlLink . '&cmd=' . self::UI_CMD_COPAGE_DOWNLOAD_PARAGRAPH);
231  }
232 
233  return $pageObjectGUI->getHTML();
234 
235  default:
236  throw new \ilException('Unknown presentation mode given');
237  break;
238  }
239  }
240 }
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
Class ilContentPagePageCommandForwarder.
This class provides processing control methods.
Class ilContentPagePageGUI ilContentPagePageGUI: ilPageEditorGUI, ilEditClipboardGUI, ilMDEditorGUI ilContentPagePageGUI: ilPublicUserProfileGUI, ilNoteGUI ilContentPagePageGUI: ilPropertyFormGUI, ilInternalLinkGUI.
Tabs GUI.
foreach($paths as $path) $request
Definition: asyncclient.php:32
Interface ilContentPageObjectConstants.
const PRESENTATION_MODE_EMBEDDED_PRESENTATION
presentation mode for embedded presentation, e.g.
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
__construct(\Psr\Http\Message\ServerRequestInterface $request, \ilCtrl $ctrl, \ilTabsGUI $tabs, \ilLanguage $lng, \ilObjContentPage $parentObject)
ilContentPagePageCommandForwarder constructor.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
const PRESENTATION_MODE_PRESENTATION
presentation mode for requesting
Class ilObjContentPage.
setStyleId($a_styleid)
Set Style Id.
const PRESENTATION_MODE_EDITING
presentation mode for authoring
language handling