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