ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjContentPageGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 
44 {
46  protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
47  protected \ILIAS\Style\Content\GUIService $content_style_gui;
49  private Container $dic;
50  private bool $infoScreenEnabled = false;
52  private ilHelpGUI $help;
53  private \ILIAS\DI\UIServices $uiServices;
54  private bool $in_page_editor_style_context = false;
55 
56  public function __construct(int $a_id = 0, int $a_id_type = self::REPOSITORY_NODE_ID, int $a_parent_node_id = 0)
57  {
58  global $DIC;
59 
60  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
61 
62  $this->dic = $DIC;
63  $this->http = $this->dic->http();
64  $this->settings = $this->dic->settings();
65  $this->navHistory = $this->dic['ilNavigationHistory'];
66  $this->help = $DIC['ilHelp'];
67  $this->uiServices = $DIC->ui();
68 
69  $this->lng->loadLanguageModule('copa');
70  $this->lng->loadLanguageModule('style');
71  $this->lng->loadLanguageModule('content');
72  $this->lng->loadLanguageModule('rep');
73 
74  if ($this->object instanceof ilObjContentPage) {
75  $this->infoScreenEnabled = (bool) ilContainer::_lookupContainerSetting(
76  $this->object->getId(),
78  '1'
79  );
80  }
81 
82  $this->pageMetricsService = new PageMetricsService(
83  new PageMetricsRepositoryImp($DIC->database()),
84  $DIC->refinery()
85  );
86  $cs = $DIC->contentStyle();
87  $this->content_style_gui = $cs->gui();
88  if (is_object($this->object)) {
89  $this->content_style_domain = $cs->domain()->styleForRefId($this->object->getRefId());
90  }
91 
92  $this->in_page_editor_style_context = $this->http->wrapper()->query()->has(
93  self::HTTP_PARAM_PAGE_EDITOR_STYLE_CONTEXT
94  );
95  $this->ctrl->saveParameterByClass(ilObjectContentStyleSettingsGUI::class, self::HTTP_PARAM_PAGE_EDITOR_STYLE_CONTEXT);
96  }
97 
98  public static function _goto(string $target): void
99  {
100  global $DIC;
101  $main_tpl = $DIC->ui()->mainTemplate();
102 
103  $targetAttributes = explode('_', $target);
104  $refId = (int) $targetAttributes[0];
105 
106  if ($refId <= 0) {
107  $DIC['ilErr']->raiseError($DIC->language()->txt('msg_no_perm_read'), $DIC['ilErr']->FATAL);
108  }
109 
110  if ($DIC->access()->checkAccess('read', '', $refId)) {
111  $DIC->ctrl()->setTargetScript('ilias.php');
112  $DIC->ctrl()->setParameterByClass(self::class, 'ref_id', $refId);
113  $DIC->ctrl()->redirectByClass([
114  ilRepositoryGUI::class,
115  self::class,
116  ], self::UI_CMD_VIEW);
117  } elseif ($DIC->access()->checkAccess('visible', '', $refId)) {
119  } elseif ($DIC->access()->checkAccess('read', '', ROOT_FOLDER_ID)) {
120  $main_tpl->setOnScreenMessage('info', sprintf(
121  $DIC->language()->txt('msg_no_perm_read_item'),
123  ), true);
124 
125  $DIC->ctrl()->setTargetScript('ilias.php');
126  $DIC->ctrl()->setParameterByClass(ilRepositoryGUI::class, 'ref_id', ROOT_FOLDER_ID);
127  $DIC->ctrl()->redirectByClass(ilRepositoryGUI::class);
128  }
129 
130  $DIC['ilErr']->raiseError($DIC->language()->txt('msg_no_perm_read'), $DIC['ilErr']->FATAL);
131  }
132 
133  public function getType(): string
134  {
135  return self::OBJ_TYPE;
136  }
137 
138  protected function setTabs(): void
139  {
140  if ($this->in_page_editor_style_context) {
141  return;
142  }
143 
144  $this->help->setScreenIdComponent($this->object->getType());
145 
146  if ($this->checkPermissionBool('read')) {
147  $this->tabs_gui->addTab(
148  self::UI_TAB_ID_CONTENT,
149  $this->lng->txt('content'),
150  $this->ctrl->getLinkTarget($this, self::UI_CMD_VIEW)
151  );
152  }
153 
154  if ($this->infoScreenEnabled && ($this->checkPermissionBool('visible') || $this->checkPermissionBool('read'))) {
155  $this->tabs_gui->addTab(
156  self::UI_TAB_ID_INFO,
157  $this->lng->txt('info_short'),
158  $this->ctrl->getLinkTargetByClass(ilInfoScreenGUI::class, 'showSummary')
159  );
160  }
161 
162  if ($this->checkPermissionBool('write')) {
163  $this->tabs_gui->addTab(
164  self::UI_TAB_ID_SETTINGS,
165  $this->lng->txt('settings'),
166  $this->ctrl->getLinkTarget($this, self::UI_CMD_EDIT)
167  );
168  }
169 
170  if (ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
171  $this->tabs_gui->addTab(
172  self::UI_TAB_ID_LP,
173  $this->lng->txt('learning_progress'),
174  $this->ctrl->getLinkTargetByClass(ilLearningProgressGUI::class)
175  );
176  }
177 
178  if ($this->checkPermissionBool('write')) {
179  $this->tabs_gui->addTab(
180  self::UI_TAB_ID_EXPORT,
181  $this->lng->txt('export'),
182  $this->ctrl->getLinkTargetByClass(ilExportGUI::class)
183  );
184  }
185 
186  if ($this->checkPermissionBool('edit_permission')) {
187  $this->tabs_gui->addTab(
188  self::UI_TAB_ID_PERMISSIONS,
189  $this->lng->txt('perm_settings'),
190  $this->ctrl->getLinkTargetByClass(ilPermissionGUI::class, 'perm')
191  );
192  }
193  }
194 
195  public function executeCommand(): void
196  {
197  $nextClass = $this->ctrl->getNextClass($this);
198  $cmd = $this->ctrl->getCmd(self::UI_CMD_VIEW);
199 
200  $this->addToNavigationHistory();
201 
202  if (
203  !$this->in_page_editor_style_context &&
204  strtolower($nextClass) !== strtolower(ilObjectContentStyleSettingsGUI::class) &&
205  (strtolower($cmd) !== strtolower(self::UI_CMD_EDIT) || strtolower($nextClass) !== strtolower(ilContentPagePageGUI::class))
206  ) {
207  $this->renderHeaderActions();
208  }
209 
210  switch (strtolower($nextClass)) {
211  case strtolower(ilObjectTranslationGUI::class):
212  $this->checkPermission('write');
213 
214  $this->prepareOutput();
215  $this->tabs_gui->activateTab(self::UI_TAB_ID_SETTINGS);
216  $this->setSettingsSubTabs(self::UI_TAB_ID_I18N);
217 
218  $transgui = new ilObjectTranslationGUI($this);
219  $this->ctrl->forwardCommand($transgui);
220  break;
221 
222  case strtolower(ilObjectContentStyleSettingsGUI::class):
223  $this->checkPermission('write');
224  $this->prepareOutput();
225  $this->setLocator();
226  if (!$this->in_page_editor_style_context) {
227  $this->tabs_gui->activateTab(self::UI_TAB_ID_SETTINGS);
228  $this->setSettingsSubTabs(self::UI_TAB_ID_STYLE);
229  }
230  $settings_gui = $this->content_style_gui
231  ->objectSettingsGUIForRefId(
232  null,
233  $this->object->getRefId()
234  );
235  $this->ctrl->forwardCommand($settings_gui);
236  break;
237 
238  case strtolower(ilContentPagePageGUI::class):
239  $isMediaRequest = in_array(strtolower($cmd), array_map('strtolower', [
240  self::UI_CMD_COPAGE_DOWNLOAD_FILE,
241  self::UI_CMD_COPAGE_DISPLAY_FULLSCREEN,
242  self::UI_CMD_COPAGE_DISPLAY_MEDIA,
243  self::UI_CMD_COPAGE_DOWNLOAD_PARAGRAPH,
244  ]), true);
245  if ($isMediaRequest) {
246  if (!$this->checkPermissionBool('read')) {
247  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
248  }
249  } elseif (!$this->checkPermissionBool('write') || $this->user->isAnonymous()) {
250  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
251  }
252 
253  $this->prepareOutput();
254 
255  $this->content_style_gui->addCss($this->tpl, $this->object->getRefId());
256  $this->tpl->setCurrentBlock('SyntaxStyle');
257  $this->tpl->setVariable('LOCATION_SYNTAX_STYLESHEET', ilObjStyleSheet::getSyntaxStylePath());
258  $this->tpl->parseCurrentBlock();
259 
261  $obj = $this->object;
262  $forwarder = new ilContentPagePageCommandForwarder(
263  $this->http,
264  $this->ctrl,
265  $this->tabs_gui,
266  $this->lng,
267  $obj,
268  $this->user,
269  $this->refinery,
270  $this->content_style_domain
271  );
272  $forwarder->setIsMediaRequest($isMediaRequest);
273 
274  $forwarder->addUpdateListener(function (PageUpdatedEvent $event): void {
275  $this->pageMetricsService->store(
277  $this->object->getId(),
278  $event->page()->getLanguage()
279  )
280  );
281  });
282 
283  $pageContent = $forwarder->forward();
284  if ($pageContent !== '') {
285  $this->tpl->setContent($pageContent);
286  }
287  break;
288 
289  case strtolower(ilInfoScreenGUI::class):
290  if (!$this->infoScreenEnabled) {
291  return;
292  }
293  $this->prepareOutput();
294 
295  $this->infoScreenForward();
296  break;
297 
298  case strtolower(ilCommonActionDispatcherGUI::class):
299  $this->prepareOutput();
301  break;
302 
303  case strtolower(ilPermissionGUI::class):
304  $this->checkPermission('edit_permission');
305 
306  $this->prepareOutput();
307  $this->tabs_gui->activateTab(self::UI_TAB_ID_PERMISSIONS);
308 
309  $this->ctrl->forwardCommand(new ilPermissionGUI($this));
310  break;
311 
312  case strtolower(ilLearningProgressGUI::class):
313  if (!ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
314  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
315  }
316 
317  $this->prepareOutput();
318  $this->tabs_gui->activateTab(self::UI_TAB_ID_LP);
319 
320  $usr_id = 0;
321  if ($this->http->wrapper()->query()->has('user_id')) {
322  $usr_id = $this->http->wrapper()->query()->retrieve(
323  'user_id',
324  $this->refinery->kindlyTo()->int()
325  );
326  }
327 
328  $this->ctrl->forwardCommand(new ilLearningProgressGUI(
330  $this->object->getRefId(),
331  $usr_id === 0 ? $this->user->getId() : $usr_id
332  ));
333  break;
334 
335  case strtolower(ilExportGUI::class):
336  $this->checkPermission('write');
337 
338  $this->prepareOutput();
339  $this->tabs_gui->activateTab(self::UI_TAB_ID_EXPORT);
340 
341  $gui = new ilExportGUI($this);
342  $gui->addFormat('xml');
343  $this->ctrl->forwardCommand($gui);
344  break;
345 
346  case strtolower(ilObjectCopyGUI::class):
347  $this->tpl->loadStandardTemplate();
348 
349  $gui = new ilObjectCopyGUI($this);
350  $gui->setType(self::OBJ_TYPE);
351 
352  $this->ctrl->forwardCommand($gui);
353  break;
354 
355  default:
356  $settingsCommands = array_map('strtolower', [self::UI_CMD_EDIT, self::UI_CMD_UPDATE]);
357  switch (true) {
358  case in_array(strtolower($cmd), $settingsCommands, true):
359  $this->setSettingsSubTabs(self::UI_TAB_ID_SETTINGS);
360  break;
361  }
362 
363  if (in_array(strtolower($cmd), array_map('strtolower', ['addToDesk', 'removeFromDesk']), true)) {
364  $this->ctrl->setCmd($cmd . 'Object');
365  }
366 
367  parent::executeCommand();
368  }
369  }
370 
371  public function addToNavigationHistory(): void
372  {
373  if (!$this->getCreationMode() && $this->checkPermissionBool('read')) {
374  $this->navHistory->addItem(
375  $this->object->getRefId(),
376  ilLink::_getLink($this->object->getRefId(), $this->object->getType()),
377  $this->object->getType()
378  );
379  }
380  }
381 
382  public function renderHeaderActions(): void
383  {
384  if (!$this->getCreationMode() && $this->checkPermissionBool('read')) {
385  $this->addHeaderAction();
386  }
387  }
388 
389  public function infoScreenForward(): void
390  {
391  if (!$this->infoScreenEnabled) {
392  return;
393  }
394 
395  if (!$this->checkPermissionBool('visible') && !$this->checkPermissionBool('read')) {
396  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
397  }
398 
399  $this->tabs_gui->activateTab(self::UI_TAB_ID_INFO);
400 
401  $info = new ilInfoScreenGUI($this);
402  $info->enableLearningProgress();
403  $info->enablePrivateNotes();
404  $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
405 
406  $this->ctrl->forwardCommand($info);
407  }
408 
409  protected function setSettingsSubTabs(string $activeTab): void
410  {
411  if ($this->checkPermissionBool('write')) {
412  $this->tabs_gui->addSubTab(
413  self::UI_TAB_ID_SETTINGS,
414  $this->lng->txt('settings'),
415  $this->ctrl->getLinkTarget($this, self::UI_CMD_EDIT)
416  );
417 
418  $this->tabs_gui->addSubTab(
419  self::UI_TAB_ID_STYLE,
420  $this->lng->txt('cont_style'),
421  $this->ctrl->getLinkTargetByClass("ilobjectcontentstylesettingsgui", "")
422  );
423 
424  $this->tabs_gui->addSubTab(
425  self::UI_TAB_ID_I18N,
426  $this->lng->txt('obj_multilinguality'),
427  $this->ctrl->getLinkTargetByClass(ilObjectTranslationGUI::class)
428  );
429 
430  $this->tabs_gui->activateSubTab($activeTab);
431  }
432  }
433 
434  protected function addLocatorItems(): void
435  {
436  if ($this->object instanceof ilObject) {
437  $this->locator->addItem(
438  $this->object->getTitle(),
439  $this->ctrl->getLinkTarget($this, self::UI_CMD_VIEW),
440  '',
441  $this->object->getRefId()
442  );
443  }
444  }
445 
446  public function infoScreen(): void
447  {
448  $this->ctrl->setCmd('showSummary');
449  $this->ctrl->setCmdClass(ilInfoScreenGUI::class);
450 
451  $this->infoScreenForward();
452  }
453 
454  public function view(): void
455  {
456  $this->checkPermission('read');
457 
458  $this->populateContentToolbar();
459 
460  $this->tabs_gui->activateTab(self::UI_TAB_ID_CONTENT);
461 
462  $this->tpl->setPermanentLink($this->object->getType(), $this->object->getRefId(), '', '_top');
463 
464  $this->tpl->setContent($this->getContent());
465  }
466 
467  protected function populateContentToolbar(): void
468  {
469  if (!$this->user->isAnonymous() && $this->checkPermissionBool('write')) {
470  $this->lng->loadLanguageModule('cntr');
471  $this->toolbar->addComponent(
472  $this->uiServices->factory()->button()->primary(
473  $this->lng->txt('cntr_text_media_editor'),
474  $this->ctrl->getLinkTargetByClass(ilContentPagePageGUI::class, 'edit')
475  )
476  );
477  }
478  }
479 
485  public function getContent(string $ctrlLink = ''): string
486  {
487  if ($this->checkPermissionBool('read')) {
488  $this->object->trackProgress($this->user->getId());
489 
490  $this->initStyleSheets();
491 
492  $forwarder = new ilContentPagePageCommandForwarder(
493  $this->http,
494  $this->ctrl,
495  $this->tabs_gui,
496  $this->lng,
497  $this->object,
498  $this->user,
499  $this->refinery,
500  $this->content_style_domain
501  );
503 
504  return $forwarder->forward($ctrlLink);
505  }
506 
507  return '';
508  }
509 
510  protected function initStyleSheets(): void
511  {
512  $this->content_style_gui->addCss($this->tpl, $this->object->getRefId());
513  $this->tpl->setCurrentBlock('SyntaxStyle');
514  $this->tpl->setVariable('LOCATION_SYNTAX_STYLESHEET', ilObjStyleSheet::getSyntaxStylePath());
515  $this->tpl->parseCurrentBlock();
516  }
517 
518  protected function afterSave(ilObject $new_object): void
519  {
520  $new_object->getObjectTranslation()->addLanguage(
521  $this->lng->getDefaultLanguage(),
522  $new_object->getTitle(),
523  $new_object->getDescription(),
524  true,
525  true
526  );
527  $new_object->getObjectTranslation()->save();
528 
529  $this->tpl->setOnScreenMessage('success', $this->lng->txt('object_added'), true);
530  $this->ctrl->redirect($this, 'edit');
531  }
532 
533  protected function setTitleAndDescription(): void
534  {
535  parent::setTitleAndDescription();
536 
537  $icon = ilObject::_getIcon($this->object->getId(), 'big', $this->object->getType());
538  $this->tpl->setTitleIcon($icon, $this->lng->txt('obj_' . $this->object->getType()));
539  }
540 
541  protected function initEditCustomForm(ilPropertyFormGUI $a_form): void
542  {
543  $this->addAvailabilitySection($a_form);
544 
545  $presentationHeader = new ilFormSectionHeaderGUI();
546  $presentationHeader->setTitle($this->lng->txt('settings_presentation_header'));
547  $a_form->addItem($presentationHeader);
548 
549  $this->object_service->commonSettings()->legacyForm($a_form, $this->object)->addIcon();
550  $this->object_service->commonSettings()->legacyForm($a_form, $this->object)->addTileImage();
551 
552  $sh = new ilFormSectionHeaderGUI();
553  $sh->setTitle($this->lng->txt('obj_features'));
554  $a_form->addItem($sh);
555 
557  $this->object->getId(),
558  $a_form,
559  [
561  ]
562  );
563 
564  if ($this->getCreationMode() !== true && count($this->object->getObjectTranslation()->getLanguages()) > 1) {
565  $languages = ilMDLanguageItem::_getLanguages();
566  $a_form->getItemByPostVar('title')
567  ->setInfo(
568  implode(
569  ': ',
570  [
571  $this->lng->txt('language'),
572  $languages[$this->object->getObjectTranslation()->getDefaultLanguage()]
573  ]
574  )
575  );
576  }
577  }
578 
579  private function addAvailabilitySection(ilPropertyFormGUI $form): void
580  {
581  $section = new ilFormSectionHeaderGUI();
582  $section->setTitle($this->lng->txt('rep_activation_availability'));
583  $form->addItem($section);
584 
585  $online = new ilCheckboxInputGUI($this->lng->txt('rep_activation_online'), 'activation_online');
586  $online->setInfo($this->lng->txt('copa_activation_online_info'));
587  $form->addItem($online);
588  }
589 
590  protected function getEditFormCustomValues(array &$a_values): void
591  {
592  $a_values['activation_online'] = $this->object->getOfflineStatus() === false;
594 
595  if (count($this->object->getObjectTranslation()->getLanguages()) > 1) {
596  $a_values['title'] = $this->object->getObjectTranslation()->getDefaultTitle();
597  $a_values['desc'] = $this->object->getObjectTranslation()->getDefaultDescription();
598  }
599  }
600 
601  protected function updateCustom(ilPropertyFormGUI $form): void
602  {
603  $this->object->setOfflineStatus(!(bool) $form->getInput('activation_online'));
604  $this->object->update();
605 
607  $this->object->getId(),
608  $form,
609  [
611  ]
612  );
613  $this->object_service->commonSettings()->legacyForm($form, $this->object)->saveIcon();
614  $this->object_service->commonSettings()->legacyForm($form, $this->object)->saveTileImage();
615  }
616 
617  public function editStyleProperties(): void
618  {
619  $this->content_style_gui->redirectToObjectSettings();
620  }
621 }
setLocator()
set Locator
checkPermission(string $perm, string $cmd="", string $type="", int $ref_id=null)
Interface GlobalHttpState.
ILIAS DI UIServices $uiServices
Class ilInfoScreenGUI.
getContent(string $ctrlLink='')
executeCommand()
execute command
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
ilNavigationHistory $navHistory
New implementation of ilObjectGUI.
GUI class for the workflow of copying objects.
getItemByPostVar(string $a_post_var)
const ROOT_FOLDER_ID
Definition: constants.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateCustom(ilPropertyFormGUI $form)
Help GUI class.
static _gotoRepositoryNode(int $ref_id, string $cmd="")
This class represents a checkbox property in a property form.
$refId
Definition: xapitoken.php:58
prepareOutput(bool $show_sub_objects=true)
PageMetricsService $pageMetricsService
Class ilObjContentPageGUI ilObjContentPageGUI: ilRepositoryGUI ilObjContentPageGUI: ilAdministratio...
static updateServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
static checkAccess(int $a_ref_id, bool $a_allow_only_read=true)
check access to learning progress
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
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.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
static _lookupTitle(int $obj_id)
getEditFormCustomValues(array &$a_values)
ILIAS Style Content GUIService $content_style_gui
const PRESENTATION_MODE_PRESENTATION
presentation mode for requesting
static initServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
Navigation History of Repository Items.
ILIAS Style Content Object ObjectFacade $content_style_domain
afterSave(ilObject $new_object)
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
addAvailabilitySection(ilPropertyFormGUI $form)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static _goto(string $target)
addHeaderAction()
Add header action menu.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setSettingsSubTabs(string $activeTab)
initEditCustomForm(ilPropertyFormGUI $a_form)
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...