ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilObjLinkResourceGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
33 {
34  protected const int VIEW_MODE_VIEW = 1;
35  protected const int VIEW_MODE_MANAGE = 2;
36  protected const int VIEW_MODE_SORT = 3;
37 
38  protected const int LINK_MOD_CREATE = 1;
39  protected const int LINK_MOD_EDIT = 2;
40  protected const int LINK_MOD_ADD = 3;
41  protected const int LINK_MOD_SET_LIST = 4;
42  protected const int LINK_MOD_ASYNC = 6;
43 
44  private int $view_mode = self::VIEW_MODE_VIEW;
45 
50 
51  public function __construct(
52  int $id = 0,
53  int $id_type = self::REPOSITORY_NODE_ID,
54  int $parent_node_id = 0
55  ) {
57  global $DIC;
58 
59  parent::__construct($id, $id_type, $parent_node_id);
60 
61  $this->lng->loadLanguageModule("webr");
62  $this->settings = $DIC->settings();
63  $DIC->resourceStorage();
64  }
65 
66  protected function getWebLinkRepo(): ilWebLinkRepository
67  {
68  return new ilWebLinkDatabaseRepository($this->object->getId());
69  }
70 
71  public function getType(): string
72  {
73  return "webr";
74  }
75 
79  protected function initViewMode(?int $new_view_mode = null): void
80  {
81  if ($new_view_mode !== null) {
82  ilSession::set('webr_view_mode', $new_view_mode);
83  }
84  if (ilSession::has('webr_view_mode')) {
85  $this->view_mode = (int) ilSession::get('webr_view_mode');
86  }
87  }
88 
89  public function executeCommand(): void
90  {
91  $this->initViewMode();
92 
93  $base_class = $this->http->wrapper()->query()->retrieve(
94  'baseClass',
95  $this->refinery->kindlyTo()->string()
96  );
97  if ($base_class === ilLinkResourceHandlerGUI::class) {
98  $this->__prepareOutput();
99  }
100  $next_class = $this->ctrl->getNextClass($this);
101  $cmd = $this->ctrl->getCmd();
102  switch ($next_class) {
103  case "ilinfoscreengui":
104  $this->prepareOutput();
105  $this->infoScreenForward(); // forwards command
106  break;
107 
108  case 'ilobjectmetadatagui':
109  $this->checkPermission('write'); // #18563
110  $this->prepareOutput();
111  $this->tabs_gui->activateTab('id_meta_data');
112  $md_gui = new ilObjectMetaDataGUI($this->object);
113  $this->ctrl->forwardCommand($md_gui);
114  break;
115 
116  case 'ilpermissiongui':
117  $this->prepareOutput();
118  $this->tabs_gui->activateTab('id_permissions');
119  $perm_gui = new ilPermissionGUI($this);
120  $this->ctrl->forwardCommand($perm_gui);
121  break;
122 
123  case 'ilobjectcopygui':
124  $this->prepareOutput();
125  $cp = new ilObjectCopyGUI($this);
126  $cp->setType('webr');
127  $this->ctrl->forwardCommand($cp);
128  break;
129 
130  case 'ilexportgui':
131  $this->prepareOutput();
132  $this->tabs_gui->setTabActive('export');
133  $exp = new ilExportGUI($this);
134  $this->ctrl->forwardCommand($exp);
135  break;
136 
137  case "ilcommonactiondispatchergui":
138  $this->prepareOutput();
140  $this->ctrl->forwardCommand($gui);
141  break;
142 
143  case "ilpropertyformgui":
144  $mode = $this->ctrl->isAsynch() ?
145  self::LINK_MOD_ASYNC : self::LINK_MOD_EDIT;
146  $this->initFormLink($mode);
147  $this->ctrl->forwardCommand($this->form);
148  break;
149 
150  case "ilinternallinkgui":
151  $this->lng->loadLanguageModule("content");
152  $link_gui = new ilInternalLinkGUI("RepositoryItem", 0);
153  $link_gui->filterLinkType("PageObject");
154  $link_gui->filterLinkType("GlossaryItem");
155  $link_gui->filterLinkType("RepositoryItem");
156  $link_gui->setFilterWhiteList(true);
157  $this->ctrl->forwardCommand($link_gui);
158  break;
159 
160  default:
161  if ($this->getIdType() === ilObject2GUI::WORKSPACE_OBJECT_ID) {
162  parent::executeCommand();
163  break;
164  }
165  if (!$cmd) {
166  $cmd = 'view';
167  }
168  $this->prepareOutput();
169  $this->$cmd();
170  }
171 
172  if (!$this->getCreationMode()) {
173  $this->addHeaderAction();
174  }
175  }
176 
177  protected function initCreateForm(string $new_type): ilPropertyFormGUI
178  {
179  $this->initFormLink(self::LINK_MOD_CREATE);
180  return $this->form;
181  }
182 
183  public function save(): void
184  {
185  $this->initFormLink(self::LINK_MOD_CREATE);
186  $valid = $this->form->checkInput();
187  if (
188  $this->checkLinkInput(self::LINK_MOD_CREATE, $valid, 0) &&
189  $this->form->getInput('tar_mode_type') === 'single'
190  ) {
191  $this->saveObject();
192  } elseif ($valid && $this->form->getInput('tar_mode_type') == 'list') {
193  $this->initList(self::LINK_MOD_CREATE);
194  $this->saveObject();
195  } else {
196  // Data incomplete or invalid
197  $this->tpl->setOnScreenMessage(
198  'failure',
199  $this->lng->txt('err_check_input')
200  );
201  $this->form->setValuesByPost();
202  $this->tpl->setContent($this->form->getHTML());
203  }
204  }
205 
206  public function saveObject(): void
207  {
208  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
209  if (!$this->checkPermissionBool("create", "", $this->requested_new_type)) {
210  $this->error->raiseError($this->lng->txt("no_create_permission"), $this->error->MESSAGE);
211  }
212 
213  $this->lng->loadLanguageModule($this->requested_new_type);
214  $this->ctrl->setParameter($this, "new_type", $this->requested_new_type);
215 
216  $this->form = $this->initCreateForm($this->requested_new_type);
217  if ($this->form->checkInput()) {
218  $this->ctrl->setParameter($this, "new_type", "");
219 
220  $class_name = "ilObj" . $this->obj_definition->getClassName($this->requested_new_type);
221  $newObj = new $class_name();
222  $newObj->setType($this->requested_new_type);
223  $newObj->setTitle($this->form->getInput("title"));
224  $newObj->setDescription($this->form->getInput("desc"));
225  $newObj->processAutoRating();
226  $newObj->create();
227 
228  $this->putObjectInTree($newObj);
229 
230  if ($this->form->getInput('didactic_template')) {
231  $dtpl = $this->getDidacticTemplateVar("dtpl");
232  // Object calls initCreateForm again in getDidacticTemplateVar
233  $this->form->checkInput();
234  $newObj->applyDidacticTemplate($dtpl);
235  }
236 
237  $this->afterSave($newObj);
238  }
239 
240  $this->form->setValuesByPost();
241  $this->tpl->setContent($this->form->getHTML());
242  }
243 
244  protected function afterSave(ilObject $new_object): void
245  {
246  $new_web_link_repo = new ilWebLinkDatabaseRepository($new_object->getId());
247 
248  if ($this->form->getInput('tar_mode_type') === 'single') {
249  // Save link
250  $new_web_link_repo->createItem($this->draft_item);
251  $this->tpl->setOnScreenMessage(
252  'success',
253  $this->lng->txt('webr_link_added')
254  );
255  }
256 
257  if ($this->form->getInput('tar_mode_type') === 'list') {
258  // Save list
259  $new_web_link_repo->createList($this->draft_list);
260  $this->tpl->setOnScreenMessage(
261  'success',
262  $this->lng->txt('webr_list_added')
263  );
264  }
265 
266  // personal workspace
267  if ($this->id_type == self::WORKSPACE_NODE_ID) {
268  $this->ctrl->redirect($this, "editLinks");
269  } // repository
270  else {
272  "ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=" .
273  $new_object->getRefId() . "&cmd=switchViewMode&switch_mode=2"
274  );
275  }
276  }
277 
278  protected function settings(): void
279  {
280  $this->checkPermission('write');
281  $this->tabs_gui->activateTab('id_settings');
282 
283  $form = $this->initFormSettings();
284  $this->tpl->setContent($this->ui_renderer->render($form));
285  }
286 
287  protected function saveSettings(): void
288  {
289  $this->checkPermission('write');
290  $this->tabs_gui->activateTab('id_settings');
291 
292  $form = $this->initFormSettings()->withRequest($this->http->request());
293  if (!($data = $form->getData())) {
294  $this->tpl->setOnScreenMessage(
295  'failure',
296  $this->lng->txt('err_check_input')
297  );
298  $this->tpl->setContent($this->ui_renderer->render($form));
299  }
300 
301  $obj_props = $this->object->getObjectProperties();
302 
304  $title_and_description = $data['general']['title_and_description'] ?? null;
305  if ($title_and_description !== null && $this->getWebLinkRepo()->doesListExist()) {
306  $obj_props->storePropertyTitleAndDescription($title_and_description);
307 
308  // update list
309  $draft_list = new ilWebLinkDraftList(
310  $title_and_description->getTitle(),
311  $title_and_description->getLongDescription()
312  );
313  $this->getWebLinkRepo()->updateList(
314  $this->getWebLinkRepo()->getList(),
315  $draft_list
316  );
317  }
318  $obj_props->storePropertyIsOnline($data['activation']['is_online']);
319  $obj_props->storePropertyTileImage($data['presentation']['tile_image']);
320  $ordering = $data['presentation']['sor'] ?? null;
321  if ($ordering !== null && $this->getWebLinkRepo()->doesListExist()) {
322  $sort = new ilContainerSortingSettings($this->object->getId());
323  $sort->setSortMode((int) $ordering);
324  $sort->update();
325  }
326 
327  $this->ctrl->redirect($this, 'settings');
328  }
329 
330  protected function initFormSettings(): StandardForm
331  {
332  $inputs = [];
333  $obj_props = $this->object->getObjectProperties();
334  $field_factory = $this->ui_factory->input()->field();
335 
336  if ($this->getWebLinkRepo()->doesListExist()) {
337  $title_and_description = $obj_props->getPropertyTitleAndDescription()->toForm(
338  $this->lng,
339  $field_factory,
340  $this->refinery
341  );
342  $inputs['general'] = $field_factory->section(
343  ['title_and_description' => $title_and_description],
344  $this->lng->txt('webr_edit_settings')
345  );
346  }
347 
348  // activation
349  $this->lng->loadLanguageModule('rep');
350  $is_online = $obj_props->getPropertyIsOnline()->toForm(
351  $this->lng,
352  $field_factory,
353  $this->refinery
354  );
355  $inputs['activation'] = $field_factory->section(
356  ['is_online' => $is_online],
357  $this->lng->txt('rep_activation_availability')
358  );
359 
360  $presentation_inputs = [];
361 
362  // tile image
363  $tile_input = $obj_props->getPropertyTileImage()->toForm(
364  $this->lng,
365  $field_factory,
366  $this->refinery
367  );
368  $presentation_inputs['tile_image'] = $tile_input;
369 
370  // Sorting
371  if ($this->getWebLinkRepo()->doesListExist()) {
372  $current_mode = (string) ilContainerSortingSettings::_lookupSortMode($this->object->getId());
373  $order_input = $field_factory->radio($this->lng->txt('webr_sorting'))
374  ->withOption(
375  (string) ilContainer::SORT_TITLE,
376  $this->lng->txt('webr_sorting')
377  )
378  ->withOption(
379  (string) ilContainer::SORT_MANUAL,
380  $this->lng->txt('webr_sort_manual')
381  )
382  ->withValue($current_mode)
383  ->withRequired(true);
384  $presentation_inputs['sor'] = $order_input;
385  }
386 
387  $inputs['presentation'] = $field_factory->section(
388  $presentation_inputs,
389  $this->lng->txt('obj_presentation')
390  );
391 
392  $form = $this->ui_factory->input()->container()->form()->standard(
393  $this->ctrl->getFormAction($this, 'saveSettings'),
394  $inputs
395  );
396  return $form;
397  }
398 
399  public function editLink(): void
400  {
401  $this->checkPermission('write');
402  $this->activateTabs('content', 'id_content_view');
403 
404  $link_id = 0;
405  if ($this->http->wrapper()->query()->has('link_id')) {
406  $link_id = $this->http->wrapper()->query()->retrieve(
407  'link_id',
408  $this->refinery->kindlyTo()->int()
409  );
410  }
411  if (!$link_id) {
412  $this->tpl->setOnScreenMessage(
413  'failure',
414  $this->lng->txt('select_one'),
415  true
416  );
417  $this->ctrl->redirect($this, 'view');
418  }
419  $form = $this->initFormLink(self::LINK_MOD_EDIT);
420  $this->setValuesFromLink($link_id);
421  $this->tpl->setContent($form->getHTML());
422  }
423 
424  public function updateLink(): void
425  {
426  $form = $this->initFormLink(self::LINK_MOD_EDIT);
427  $valid = $form->checkInput();
428  $link_id = 0;
429  if ($this->http->wrapper()->query()->has('link_id')) {
430  $link_id = $this->http->wrapper()->query()->retrieve(
431  'link_id',
432  $this->refinery->kindlyTo()->int()
433  );
434  }
435  if ($this->checkLinkInput(
436  self::LINK_MOD_EDIT,
437  $valid,
438  $link_id
439  )) {
440  $item = $this->getWebLinkRepo()->getItemByLinkId($link_id);
441  foreach ($item->getParameters() as $parameter) {
442  $this->draft_item->addParameter($parameter);
443  }
444 
445  if (
446  $this->settings->get('links_dynamic') &&
447  $this->draft_parameter !== null
448  ) {
449  $this->draft_item->addParameter($this->draft_parameter);
450  }
451  $this->getWebLinkRepo()->updateItem($item, $this->draft_item);
452 
453  if (!$this->getWebLinkRepo()->doesListExist()) {
454  $this->object->setTitle($form->getInput('title'));
455  $this->object->setDescription($form->getInput('desc'));
456  $this->object->update();
457  }
458  $this->tpl->setOnScreenMessage(
459  'success',
460  $this->lng->txt('settings_saved'),
461  true
462  );
463  $this->ctrl->redirect($this, 'view');
464  }
465  $this->tpl->setOnScreenMessage(
466  'failure',
467  $this->lng->txt('err_check_input')
468  );
469  $form->setValuesByPost();
470  $this->tpl->setContent($form->getHTML());
471  }
472 
477  {
478  global $DIC;
479 
480  $f = $DIC->ui()->factory();
481  $r = $DIC->ui()->renderer();
482 
483  // check if form was already set
484  if ($this->form == null) {
485  $this->initFormLink(self::LINK_MOD_SET_LIST);
486  }
487 
488  $form_id = 'form_' . $this->form->getId();
489 
490  $submit = $f->button()->primary($this->lng->txt('save'), '#')
491  ->withOnLoadCode(
492  function ($id) use ($form_id) {
493  return "$('#{$id}').click(function() { $('#{$form_id}').submit(); return false; });";
494  }
495  );
496  $info = $f->messageBox()->info($this->lng->txt('webr_new_list_info'));
497 
498  $modal = $f->modal()->roundtrip(
499  $this->lng->txt('webr_new_list'),
500  $f->legacy()->content($r->render($info) . $this->form->getHTML())
501  )
502  ->withActionButtons([$submit]);
503 
504  $submit = '';
505  if ($this->http->wrapper()->post()->has('sbmt')) {
506  $submit = $this->http->wrapper()->post()->retrieve(
507  'sbmt',
508  $this->refinery->kindlyTo()->string()
509  );
510  }
511  // modal triggers its show signal on load if form validation failed
512  if ($submit === 'submit') {
513  $modal = $modal->withOnLoad($modal->getShowSignal());
514  }
515  return $modal;
516  }
517 
518  public function saveLinkList(): void
519  {
520  $this->checkPermission('write');
521  $form = $this->initFormLink(self::LINK_MOD_SET_LIST);
522  $valid = $form->checkInput();
523  if ($valid) {
524  $this->object->setTitle($form->getInput('lti'));
525  $this->object->setDescription($form->getInput('tde'));
526  $this->object->update();
527 
528  $this->initList(self::LINK_MOD_SET_LIST);
529  $this->getWebLinkRepo()->createList($this->draft_list);
530  $this->tpl->setOnScreenMessage(
531  'success',
532  $this->lng->txt('webr_list_set'),
533  true
534  );
535  $this->ctrl->redirect($this, 'view');
536  }
537  $this->tpl->setOnScreenMessage(
538  'failure',
539  $this->lng->txt('err_check_input'),
540  true
541  );
542  $form->setValuesByPost();
543  $this->view();
544  }
545 
546  public function addLink(): void
547  {
548  $this->checkPermission('write');
549  $this->activateTabs('content', 'id_content_view');
550 
551  $form = $this->initFormLink(self::LINK_MOD_ADD);
552  $this->tpl->setContent($form->getHTML());
553  }
554 
555  public function saveAddLink(): void
556  {
557  $this->checkPermission('write');
558 
559  $form = $this->initFormLink(self::LINK_MOD_ADD);
560  $valid = $form->checkInput();
561  if ($this->checkLinkInput(
562  self::LINK_MOD_ADD,
563  $valid,
564  0
565  )
566  ) {
567  if (
568  $this->settings->get('links_dynamic') &&
569  $this->draft_parameter !== null
570  ) {
571  $this->draft_item->addParameter($this->draft_parameter);
572  }
573  $this->getWebLinkRepo()->createItem($this->draft_item);
574 
575  $this->tpl->setOnScreenMessage(
576  'success',
577  $this->lng->txt('webr_link_added'),
578  true
579  );
580  $this->ctrl->redirect($this, 'view');
581  }
582  $this->tpl->setOnScreenMessage(
583  'failure',
584  $this->lng->txt('err_check_input')
585  );
586  $this->form->setValuesByPost();
587  $this->activateTabs('content', 'id_content_view');
588  $this->tpl->setContent($form->getHTML());
589  }
590 
591  protected function deleteParameter(): void
592  {
593  $this->checkPermission('write');
594 
595  $link_id = $this->http->wrapper()->query()->retrieve(
596  'link_id',
597  $this->refinery->kindlyTo()->int()
598  );
599  $this->ctrl->setParameter($this, 'link_id', $link_id);
600 
601  $param_id = $this->http->wrapper()->query()->retrieve(
602  'param_id',
603  $this->refinery->kindlyTo()->int()
604  );
605 
606  if (!$param_id) {
607  $this->tpl->setOnScreenMessage(
608  'failure',
609  $this->lng->txt('select_one'),
610  true
611  );
612  $this->ctrl->redirect($this, 'view');
613  }
614 
615  $this->getWebLinkRepo()->deleteParameterByLinkIdAndParamId($link_id, $param_id);
616 
617  $this->tpl->setOnScreenMessage(
618  'success',
619  $this->lng->txt(
620  'links_parameter_deleted'
621  ),
622  true
623  );
624  $this->ctrl->redirect($this, 'editLinks');
625  }
626 
627  protected function deleteParameterForm(): void
628  {
629  $this->checkPermission('write');
630 
631  $link_id = $this->http->wrapper()->query()->retrieve(
632  'link_id',
633  $this->refinery->kindlyTo()->int()
634  );
635 
636  $param_id = $this->http->wrapper()->query()->retrieve(
637  'param_id',
638  $this->refinery->kindlyTo()->int()
639  );
640  if (!$param_id) {
641  $this->tpl->setOnScreenMessage(
642  'failure',
643  $this->lng->txt('select_one'),
644  true
645  );
646  $this->ctrl->redirect($this, 'view');
647  }
648 
649  $this->getWebLinkRepo()->deleteParameterByLinkIdAndParamId($link_id, $param_id);
650 
651  $this->tpl->setOnScreenMessage(
652  'success',
653  $this->lng->txt(
654  'links_parameter_deleted'
655  ),
656  true
657  );
658  $this->ctrl->redirect($this, 'view');
659  }
660 
661  protected function updateLinks(): void
662  {
663  $this->checkPermission('write');
664  $this->activateTabs('content', '');
665 
666  $ids = [];
667  if ($this->http->wrapper()->post()->has('ids')) {
668  $ids = $this->http->wrapper()->post()->retrieve(
669  'ids',
670  $this->refinery->kindlyTo()->dictOf(
671  $this->refinery->kindlyTo()->int()
672  )
673  );
674  }
675 
676  if ($ids === []) {
677  $this->tpl->setOnScreenMessage(
678  'failure',
679  $this->lng->txt('select_one'),
680  true
681  );
682  $this->ctrl->redirect($this, 'view');
683  }
684 
685  $link_post = (array) ($this->http->request()->getParsedBody(
686  )['links'] ?? []);
687 
688  // Validate
689  $invalid = [];
690  foreach ($ids as $link_id) {
691  $data = $link_post[$link_id];
692 
693  if (
694  $this->http->wrapper()->post()->has(
695  'tar_' . $link_id . '_ajax_type'
696  ) &&
697  $this->http->wrapper()->post()->has(
698  'tar_' . $link_id . '_ajax_id'
699  )
700  ) {
701  $data['tar'] =
702  $this->http->wrapper()->post()->retrieve(
703  'tar_' . $link_id . '_ajax_type',
704  $this->refinery->kindlyTo()->string()
705  ) . '|' .
706  $this->http->wrapper()->post()->retrieve(
707  'tar_' . $link_id . '_ajax_id',
708  $this->refinery->kindlyTo()->string()
709  );
710  }
711  if (!strlen($data['title'] ?? '')) {
712  $invalid[] = $link_id;
713  continue;
714  }
715  if (!strlen($data['tar'] ?? '')) {
716  $invalid[] = $link_id;
717  continue;
718  }
719  if (($data['nam'] ?? false) && !($data['val'] ?? false)) {
720  $invalid[] = $link_id;
721  continue;
722  }
723  if (!($data['nam'] ?? false) && ($data['val'] ?? false)) {
724  $invalid[] = $link_id;
725  }
726  }
727 
728  if ($invalid !== []) {
729  $this->tpl->setOnScreenMessage(
730  'failure',
731  $this->lng->txt('err_check_input')
732  );
733  $this->tpl->addBlockFile(
734  'ADM_CONTENT',
735  'adm_content',
736  'tpl.webr_manage.html',
737  'components/ILIAS/WebResource'
738  );
739  $table = new ilWebResourceEditableLinkTableGUI($this, 'view');
740  $table->setInvalidLinks($invalid);
741  $table->parseSelectedLinks($ids);
742  $table->updateFromPost();
743  $this->tpl->setVariable('TABLE_LINKS', $table->getHTML());
744  return;
745  }
746 
747  // Save Settings
748  foreach ($ids as $link_id) {
749  $data = $link_post[$link_id];
750 
751  if (
752  $this->http->wrapper()->post()->has(
753  'tar_' . $link_id . '_ajax_type'
754  ) &&
755  $this->http->wrapper()->post()->has(
756  'tar_' . $link_id . '_ajax_id'
757  )
758  ) {
759  $data['tar'] =
760  $this->http->wrapper()->post()->retrieve(
761  'tar_' . $link_id . '_ajax_type',
762  $this->refinery->kindlyTo()->string()
763  ) . '|' .
764  $this->http->wrapper()->post()->retrieve(
765  'tar_' . $link_id . '_ajax_id',
766  $this->refinery->kindlyTo()->string()
767  );
768  }
769 
770  $item = $this->getWebLinkRepo()->getItemByLinkId($link_id);
771  $draft = new ilWebLinkDraftItem(
773  ilUtil::stripSlashes($data['title'] ?? ''),
774  ilUtil::stripSlashes($data['desc'] ?? ''),
775  str_replace('"', '', ilUtil::stripSlashes($data['tar'] ?? '')),
776  (bool) ($data['act'] ?? false),
777  $item->getParameters()
778  );
779 
780  if (strlen($data['nam'] ?? '') && $data['val'] ?? '') {
782  (int) ($data['val'] ?? 0),
783  ilUtil::stripSlashes($data['nam'] ?? '')
784  );
785  $draft->addParameter($param);
786  }
787 
788  $this->getWebLinkRepo()->updateItem($item, $draft);
789 
790  if (!$this->getWebLinkRepo()->doesListExist()) {
791  $this->object->setTitle(ilUtil::stripSlashes($data['title'] ?? ''));
792  $this->object->setDescription(
793  ilUtil::stripSlashes($data['desc'] ?? '')
794  );
795  $this->object->update();
796  }
797  }
798  $this->tpl->setOnScreenMessage(
799  'success',
800  $this->lng->txt('settings_saved'),
801  true
802  );
803  $this->ctrl->redirect($this, 'view');
804  }
805 
806  protected function setValuesFromLink(int $a_link_id): void
807  {
808  $item = $this->getWebLinkRepo()->getItemByLinkId($a_link_id);
809  $this->form->setValuesByArray(
810  array(
811  'title' => $item->getTitle(),
812  'tar' => $item->getTarget(),
813  'desc' => $item->getDescription(),
814  'act' => (int) $item->isActive()
815  )
816  );
817  }
818 
819  protected function initList(int $a_mode): void
820  {
821  if ($a_mode == self::LINK_MOD_CREATE) {
822  $this->draft_list = new ilWebLinkDraftList(
823  $this->form->getInput('title'),
824  $this->form->getInput('desc')
825  );
826  }
827 
828  if ($a_mode == self::LINK_MOD_SET_LIST) {
829  $this->draft_list = new ilWebLinkDraftList(
830  $this->form->getInput('lti'),
831  $this->form->getInput('tde')
832  );
833  }
834  }
835 
836  protected function checkLinkInput(
837  int $a_mode,
838  bool $a_valid,
839  ?int $a_link_id = null
840  ): bool {
841  $valid = $a_valid;
842 
843  $link_input = $this->form->getInput('tar');
844  $active = false;
845 
846  if ($a_mode == self::LINK_MOD_CREATE) {
847  $active = true;
848  } else {
849  $active = (bool) $this->form->getInput('act');
850  }
851 
852  $this->draft_item = new ilWebLinkDraftItem(
853  ilLinkInputGUI::isInternalLink($link_input),
854  $this->form->getInput('title'),
855  $this->form->getInput('desc'),
856  str_replace('"', '', $link_input),
857  $active,
858  []
859  );
860 
861  if (!$this->settings->get('links_dynamic')) {
862  return $valid;
863  }
864 
865  $this->draft_parameter = new ilWebLinkDraftParameter(
866  (int) $this->form->getInput('val'),
867  $this->form->getInput('nam')
868  );
869 
870  $error = $this->draft_parameter->validate();
871  if (!$error) {
872  return $valid;
873  }
874 
875  $this->draft_parameter = null;
876 
877  switch ($error) {
879  $this->form->getItemByPostVar('nam')->setAlert(
880  $this->lng->txt('links_no_name_given')
881  );
882  return false;
883 
885  $this->form->getItemByPostVar('val')->setAlert(
886  $this->lng->txt('links_no_value_given')
887  );
888  return false;
889 
890  default:
891  // Nothing entered => no error
892  return $valid;
893  }
894  }
895 
896  protected function initFormLink(int $a_mode): ilPropertyFormGUI
897  {
898  $this->tabs_gui->activateTab("id_content");
899 
900  $this->form = new ilPropertyFormGUI();
901  switch ($a_mode) {
902  case self::LINK_MOD_CREATE:
903  // Header
904  $this->ctrl->setParameter($this, 'new_type', 'webr');
905  $this->form->setTitle($this->lng->txt('webr_new_link'));
906  $this->form->setTableWidth('600px');
907 
908  // Buttons
909  $this->form->addCommandButton(
910  'save',
911  $this->lng->txt('webr_add')
912  );
913  $this->form->addCommandButton(
914  'cancel',
915  $this->lng->txt('cancel')
916  );
917  break;
918 
919  case self::LINK_MOD_ADD:
920  // Header
921  $this->form->setTitle($this->lng->txt('webr_new_link'));
922 
923  // Buttons
924  $this->form->addCommandButton(
925  'saveAddLink',
926  $this->lng->txt('webr_add')
927  );
928  $this->form->addCommandButton(
929  'view',
930  $this->lng->txt('cancel')
931  );
932  break;
933 
934  case self::LINK_MOD_EDIT:
935  // Header
936  $this->ctrl->setParameter(
937  $this,
938  'link_id',
939  // TODO PHP8 Review: Remove/Replace SuperGlobals
940  (int) $_REQUEST['link_id']
941  );
942  $this->form->setTitle($this->lng->txt('webr_edit'));
943 
944  // Buttons
945  $this->form->addCommandButton(
946  'updateLink',
947  $this->lng->txt('save')
948  );
949  $this->form->addCommandButton(
950  'view',
951  $this->lng->txt('cancel')
952  );
953  break;
954 
955  /*
956  * The async call for displaying the object explorer for
957  * internal links goes through ilPropertyFormGUI to get
958  * to the right ilLinkInputGUI, so we only add that field
959  * to the form here.
960  */
961  case self::LINK_MOD_ASYNC:
962  $this->addLinkInputToForm($a_mode);
963  return $this->form;
964  }
965 
966  if ($a_mode == self::LINK_MOD_SET_LIST) {
967  $this->form->setValuesByPost();
968  $this->form->setFormAction(
969  $this->ctrl->getFormAction($this, 'saveLinkList')
970  );
971  $this->form->setId(uniqid('form'));
972 
973  // List Title
974  $title = new ilTextInputGUI(
975  $this->lng->txt('webr_list_title'),
976  'lti'
977  );
978  $title->setRequired(true);
979  $title->setSize(40);
980  $title->setMaxLength(127);
981  $this->form->addItem($title);
982 
983  // List Description
984  $desc = new ilTextAreaInputGUI(
985  $this->lng->txt('webr_list_desc'),
986  'tde'
987  );
988  $desc->setRows(3);
989  $desc->setCols(40);
990  $this->form->addItem($desc);
991 
992  $item = new ilHiddenInputGUI('sbmt');
993  $item->setValue('submit');
994  $this->form->addItem($item);
995  } else {
996  $this->form->setFormAction($this->ctrl->getFormAction($this));
997 
998  $this->addLinkInputToForm($a_mode);
999 
1000  // Title
1001  $tit = new ilTextInputGUI(
1002  $this->lng->txt('webr_link_title'),
1003  'title'
1004  );
1005  $tit->setRequired(true);
1006  $tit->setSize(40);
1007  $tit->setMaxLength(127);
1008  $this->form->addItem($tit);
1009 
1010  // Description
1011  $des = new ilTextAreaInputGUI(
1012  $this->lng->txt('description'),
1013  'desc'
1014  );
1015  $des->setRows(3);
1016  $des->setCols(40);
1017  $this->form->addItem($des);
1018 
1019  if ($a_mode != self::LINK_MOD_CREATE) {
1020  // Active
1021  $act = new ilCheckboxInputGUI($this->lng->txt('active'), 'act');
1022  $act->setChecked(true);
1023  $act->setValue('1');
1024  $this->form->addItem($act);
1025  }
1026 
1027  if ($this->settings->get('links_dynamic') &&
1028  $a_mode != self::LINK_MOD_CREATE
1029  ) {
1030  $dyn = new ilNonEditableValueGUI(
1031  $this->lng->txt('links_dyn_parameter')
1032  );
1033  $dyn->setInfo($this->lng->txt('links_dynamic_info'));
1034 
1035  if ($this->http->wrapper()->query()->has('link_id')) {
1036  $link_id = $this->http->wrapper()->query()->retrieve(
1037  'link_id',
1038  $this->refinery->kindlyTo()->int()
1039  );
1040  }
1041  if (
1042  isset($link_id) &&
1043  $link_id > 0 &&
1044  ($params = $this->getWebLinkRepo()->getItemByLinkId($link_id)->getParameters()) !== []
1045  ) {
1046  $ex = new ilCustomInputGUI(
1047  $this->lng->txt('links_existing_params'),
1048  'ex'
1049  );
1050  $dyn->addSubItem($ex);
1051 
1052  foreach ($params as $param) {
1053  $p = new ilCustomInputGUI();
1054 
1055  $ptpl = new ilTemplate(
1056  'tpl.link_dyn_param_edit.html',
1057  true,
1058  true,
1059  'components/ILIAS/WebResource'
1060  );
1061  $ptpl->setVariable(
1062  'INFO_TXT',
1063  $param->getInfo()
1064  );
1065  $this->ctrl->setParameter($this, 'param_id', $param->getParamId());
1066  $this->ctrl->setParameter($this, 'link_id', $link_id);
1067  $ptpl->setVariable(
1068  'LINK_DEL',
1069  $this->ctrl->getLinkTarget(
1070  $this,
1071  'deleteParameterForm'
1072  )
1073  );
1074  $ptpl->setVariable(
1075  'LINK_TXT',
1076  $this->lng->txt('delete')
1077  );
1078  $p->setHtml($ptpl->get());
1079  $dyn->addSubItem($p);
1080  }
1081  }
1082 
1083  // Dynyamic name
1084  $nam = new ilTextInputGUI($this->lng->txt('links_name'), 'nam');
1085  $nam->setSize(12);
1086  $nam->setMaxLength(128);
1087  $dyn->addSubItem($nam);
1088 
1089  // Dynamic value
1090  $val = new ilSelectInputGUI(
1091  $this->lng->txt('links_value'),
1092  'val'
1093  );
1094  $options = [];
1095  foreach (ilWebLinkBaseParameter::VALUES as $name => $identifier) {
1096  $options[$identifier] = $this->lng->txt(ilWebLinkBaseParameter::VALUES_TEXT[$identifier]);
1097  }
1098  $val->setOptions($options);
1099  $val->setValue(0);
1100  $dyn->addSubItem($val);
1101 
1102  $this->form->addItem($dyn);
1103  }
1104  }
1105  return $this->form;
1106  }
1107 
1108  protected function addLinkInputToForm(int $mode): void
1109  {
1110  $tar = new ilLinkInputGUI(
1111  $this->lng->txt('type'),
1112  'tar'
1113  ); // lng var
1114  if ($mode == self::LINK_MOD_CREATE) {
1116  }
1117  $tar->setInternalLinkFilterTypes(
1118  [
1119  "PageObject",
1120  "GlossaryItem",
1121  "RepositoryItem",
1122  'WikiPage'
1123  ]
1124  );
1125  $tar->setExternalLinkMaxLength(1000);
1126  $tar->setInternalLinkFilterTypes(
1127  ["PageObject", "GlossaryItem", "RepositoryItem"]
1128  );
1129  $tar->setRequired(true);
1130  $this->form->addItem($tar);
1131  }
1132 
1136  protected function switchViewMode(?int $force_view_mode = null): void
1137  {
1138  $new_view_mode = $this->view_mode;
1139  if ($force_view_mode !== null) {
1140  $new_view_mode = $force_view_mode;
1141  } elseif ($this->http->wrapper()->query()->has('switch_mode')) {
1142  $new_view_mode = $this->http->wrapper()->query()->retrieve(
1143  'switch_mode',
1144  $this->refinery->kindlyTo()->int()
1145  );
1146  }
1147  $this->initViewMode($new_view_mode);
1148  $this->view();
1149  }
1150 
1154  protected function editLinks(): void
1155  {
1156  $this->switchViewMode(self::VIEW_MODE_MANAGE);
1157  }
1158 
1159  public function view(): void
1160  {
1161  $this->tabs_gui->activateTab("id_content");
1162  $this->checkPermission('read');
1163 
1164  $base_class = $this->http->wrapper()->query()->retrieve(
1165  'baseClass',
1166  $this->refinery->kindlyTo()->string()
1167  );
1168  if (strcasecmp($base_class, ilAdministrationGUI::class) === 0) {
1169  parent::view();
1170  return;
1171  } else {
1172  switch ($this->view_mode) {
1173  case self::VIEW_MODE_MANAGE:
1174  $this->manage();
1175  break;
1176 
1177  case self::VIEW_MODE_SORT:
1178  // #14638
1180  $this->object->getId()
1181  ) == ilContainer::SORT_MANUAL) {
1182  $this->sort();
1183  break;
1184  }
1185  $this->showLinks();
1186  break;
1187 
1188  default:
1189  $this->showLinks();
1190  break;
1191  }
1192  }
1193  $this->tpl->setPermanentLink(
1194  $this->object->getType(),
1195  $this->object->getRefId()
1196  );
1197  }
1198 
1199  protected function manage(): void
1200  {
1201  $this->checkPermission('write');
1202  $this->activateTabs('content', 'id_content_manage');
1203 
1204  $this->tpl->addBlockFile(
1205  'ADM_CONTENT',
1206  'adm_content',
1207  'tpl.webr_manage.html',
1208  'components/ILIAS/WebResource'
1209  );
1210  $this->showToolbar('ACTION_BUTTONS');
1211 
1212  $table = new ilWebResourceEditableLinkTableGUI($this, 'view');
1213  $table->parse();
1214 
1216 
1217  $this->tpl->addJavaScript("assets/js/intLink.js");
1218  $this->tpl->addJavascript("assets/js/Form.js");
1219 
1220  $this->tpl->setVariable('TABLE_LINKS', $table->getHTML() . $js);
1221  }
1222 
1223  protected function showLinks(): void
1224  {
1225  $this->checkPermission('read');
1226  $this->activateTabs('content', 'id_content_view');
1227 
1228  $table = new ilWebResourceLinkTableGUI($this, 'showLinks');
1229  $table->parse();
1230 
1231  $this->tpl->addBlockFile(
1232  'ADM_CONTENT',
1233  'adm_content',
1234  'tpl.webr_view.html',
1235  'components/ILIAS/WebResource'
1236  );
1237  $this->showToolbar('ACTION_BUTTONS');
1238  $this->tpl->setVariable('LINK_TABLE', $table->getHTML());
1239  }
1240 
1241  protected function sort(): void
1242  {
1243  $this->checkPermission('write');
1244  $this->activateTabs('content', 'id_content_ordering');
1245 
1246  $table = new ilWebResourceLinkTableGUI($this, 'sort', true);
1247  $table->parse();
1248 
1249  $this->tpl->addBlockFile(
1250  'ADM_CONTENT',
1251  'adm_content',
1252  'tpl.webr_view.html',
1253  'components/ILIAS/WebResource'
1254  );
1255  $this->showToolbar('ACTION_BUTTONS');
1256  $this->tpl->setVariable('LINK_TABLE', $table->getHTML());
1257  }
1258 
1259  protected function saveSorting(): void
1260  {
1261  $this->checkPermission('write');
1262  $sort = ilContainerSorting::_getInstance($this->object->getId());
1263 
1264  $position = [];
1265  if ($this->http->wrapper()->post()->has('position')) {
1266  $position = $this->http->wrapper()->post()->retrieve(
1267  'position',
1268  $this->refinery->kindlyTo()->dictOf(
1269  $this->refinery->kindlyTo()->string()
1270  )
1271  );
1272  }
1273  $sort->savePost($position);
1274  $this->tpl->setOnScreenMessage(
1275  'success',
1276  $this->lng->txt('settings_saved'),
1277  true
1278  );
1279  $this->view();
1280  }
1281 
1282  protected function showToolbar(string $a_tpl_var): void
1283  {
1284  global $DIC;
1285 
1286  $tool = new ilToolbarGUI();
1287  $tool->setFormAction($this->ctrl->getFormAction($this));
1288 
1289  $f = $DIC->ui()->factory();
1290  $r = $DIC->ui()->renderer();
1291 
1292  if (
1293  $this->getWebLinkRepo()->doesListExist() &&
1294  $this->checkPermissionBool('write')
1295  ) {
1296  $tool->addButton(
1297  $this->lng->txt('webr_add'),
1298  $this->ctrl->getLinkTarget($this, 'addLink')
1299  );
1300  } elseif ($this->checkPermissionBool('write')) {
1301  $modal = $this->getLinkToListModal();
1302  $button = $f->button()->standard(
1303  $this->lng->txt('webr_set_to_list'),
1304  '#'
1305  )
1306  ->withOnClick($modal->getShowSignal());
1307 
1308  $this->tpl->setVariable("MODAL", $r->render([$modal]));
1309 
1310  $tool->addComponent($button);
1311  }
1312 
1313  $download_button = $f->button()->standard(
1314  $this->lng->txt('export_html'),
1315  $this->ctrl->getLinkTarget($this, 'exportHTML')
1316  );
1317  $tool->addComponent($download_button);
1318  $this->tpl->setVariable($a_tpl_var, $tool->getHTML());
1319  }
1320 
1321  protected function confirmDeleteLink(): void
1322  {
1323  $this->checkPermission('write');
1324  $this->activateTabs('content', 'id_content_view');
1325 
1326  $link_ids = [];
1327  if ($this->http->wrapper()->query()->has('link_id')) {
1328  $link_ids = (array) $this->http->wrapper()->query()->retrieve(
1329  'link_id',
1330  $this->refinery->kindlyTo()->int()
1331  );
1332  } elseif ($this->http->wrapper()->post()->has('link_ids')) {
1333  $link_ids = $this->http->wrapper()->post()->retrieve(
1334  'link_ids',
1335  $this->refinery->kindlyTo()->dictOf(
1336  $this->refinery->kindlyTo()->int()
1337  )
1338  );
1339  }
1340  if ($link_ids === []) {
1341  $this->tpl->setOnScreenMessage(
1342  'failure',
1343  $this->lng->txt('select_one')
1344  );
1345  $this->view();
1346  return;
1347  }
1348 
1349  $confirm = new ilConfirmationGUI();
1350  $confirm->setFormAction($this->ctrl->getFormAction($this, 'view'));
1351  $confirm->setHeaderText($this->lng->txt('webr_sure_delete_items'));
1352  $confirm->setConfirm($this->lng->txt('delete'), 'deleteLinks');
1353  $confirm->setCancel($this->lng->txt('cancel'), 'view');
1354 
1355  $items = $this->getWebLinkRepo()->getAllItemsAsContainer()->getItems();
1356 
1357  foreach ($items as $item) {
1358  if (!in_array($item->getLinkId(), $link_ids)) {
1359  continue;
1360  }
1361  $confirm->addItem(
1362  'link_ids[]',
1363  (string) $item->getLinkId(),
1364  $item->getTitle()
1365  );
1366  }
1367  $this->tpl->setContent($confirm->getHTML());
1368  }
1369 
1370  protected function deleteLinks(): void
1371  {
1372  $this->checkPermission('write');
1373 
1374  $link_ids = [];
1375  if ($this->http->wrapper()->post()->has('link_ids')) {
1376  $link_ids = $this->http->wrapper()->post()->retrieve(
1377  'link_ids',
1378  $this->refinery->kindlyTo()->dictOf(
1379  $this->refinery->kindlyTo()->int()
1380  )
1381  );
1382  }
1383 
1384  foreach ($link_ids as $link_id) {
1385  $this->getWebLinkRepo()->deleteItemByLinkID($link_id);
1386  }
1387 
1388  $this->tpl->setOnScreenMessage(
1389  'success',
1390  $this->lng->txt('webr_deleted_items'),
1391  true
1392  );
1393  $this->ctrl->redirect($this, 'view');
1394  }
1395 
1396  protected function deactivateLink(): void
1397  {
1398  $this->checkPermission('write');
1399 
1400  $link_id = 0;
1401  if ($this->http->wrapper()->query()->has('link_id')) {
1402  $link_id = $this->http->wrapper()->query()->retrieve(
1403  'link_id',
1404  $this->refinery->kindlyTo()->int()
1405  );
1406  }
1407  if (!$link_id) {
1408  $this->tpl->setOnScreenMessage(
1409  'failure',
1410  $this->lng->txt('select_one'),
1411  true
1412  );
1413  $this->ctrl->redirect($this, 'view');
1414  }
1415 
1416  $item = $this->getWebLinkRepo()->getItemByLinkId($link_id);
1417  $draft = new ilWebLinkDraftItem(
1418  $item->isInternal(),
1419  $item->getTitle(),
1420  $item->getDescription(),
1421  $item->getTarget(),
1422  false,
1423  $item->getParameters()
1424  );
1425 
1426  $this->tpl->setOnScreenMessage(
1427  'success',
1428  $this->lng->txt('webr_inactive_success'),
1429  true
1430  );
1431  $this->ctrl->redirect($this, 'view');
1432  }
1433 
1439  public function infoScreen(): void
1440  {
1441  $this->ctrl->redirectByClass(
1442  [self::class, ilInfoScreenGUI::class],
1443  'showSummary'
1444  );
1445  }
1446 
1450  public function infoScreenForward(): void
1451  {
1452  if (!$this->checkPermissionBool('visible')) {
1453  $this->checkPermission('read');
1454  }
1455  $this->tabs_gui->activateTab('id_info');
1456 
1457  $info = new ilInfoScreenGUI($this);
1458 
1459  $info->enablePrivateNotes();
1460 
1461  // standard meta data
1462  $info->addMetaDataSections(
1463  $this->object->getId(),
1464  0,
1465  $this->object->getType()
1466  );
1467 
1468  // forward the command
1469  $this->ctrl->forwardCommand($info);
1470  }
1471 
1475  protected function activateTabs(
1476  string $a_active_tab,
1477  string $a_active_subtab = ''
1478  ): void {
1479  switch ($a_active_tab) {
1480  case 'content':
1481  if ($this->checkPermissionBool('write')) {
1482  $this->lng->loadLanguageModule('cntr');
1483 
1484  $this->ctrl->setParameter(
1485  $this,
1486  'switch_mode',
1487  self::VIEW_MODE_VIEW
1488  );
1489  $this->tabs_gui->addSubTab(
1490  'id_content_view',
1491  $this->lng->txt('view'),
1492  $this->ctrl->getLinkTarget($this, 'switchViewMode')
1493  );
1494  $this->ctrl->setParameter(
1495  $this,
1496  'switch_mode',
1497  self::VIEW_MODE_MANAGE
1498  );
1499  $this->tabs_gui->addSubTab(
1500  'id_content_manage',
1501  $this->lng->txt('cntr_manage'),
1502  $this->ctrl->getLinkTarget($this, 'switchViewMode')
1503  );
1504  if (!$this->getWebLinkRepo()->doesOnlyOneItemExist() and
1506  $this->object->getId()
1507  ) == ilContainer::SORT_MANUAL) {
1508  $this->ctrl->setParameter(
1509  $this,
1510  'switch_mode',
1511  self::VIEW_MODE_SORT
1512  );
1513  $this->tabs_gui->addSubTab(
1514  'id_content_ordering',
1515  $this->lng->txt('cntr_ordering'),
1516  $this->ctrl->getLinkTarget($this, 'switchViewMode')
1517  );
1518  }
1519 
1520  $this->ctrl->clearParameters($this);
1521  $this->tabs_gui->activateSubTab($a_active_subtab);
1522  }
1523  }
1524 
1525  $this->tabs_gui->activateTab('id_content');
1526  }
1527 
1528  protected function setTabs(): void
1529  {
1530  global $DIC;
1531 
1532  $ilHelp = $DIC['ilHelp'];
1533  $ilHelp->setScreenIdComponent("webr");
1534 
1535  if ($this->checkPermissionBool('read')) {
1536  $this->tabs_gui->addTab(
1537  "id_content",
1538  $this->lng->txt("content"),
1539  $this->ctrl->getLinkTarget($this, "view")
1540  );
1541  }
1542 
1543  if (
1544  $this->checkPermissionBool('visible') ||
1545  $this->checkPermissionBool('read')
1546  ) {
1547  $this->tabs_gui->addTab(
1548  "id_info",
1549  $this->lng->txt("info_short"),
1550  $this->ctrl->getLinkTarget($this, "infoScreen")
1551  );
1552  }
1553 
1554  if ($this->checkPermissionBool('write') and !$this->getCreationMode()) {
1555  $this->tabs_gui->addTab(
1556  "id_settings",
1557  $this->lng->txt("settings"),
1558  $this->ctrl->getLinkTarget($this, "settings")
1559  );
1560  }
1561 
1562  if ($this->checkPermissionBool('write')) {
1563  $mdgui = new ilObjectMetaDataGUI($this->object);
1564  $mdtab = $mdgui->getTab();
1565  if ($mdtab) {
1566  $this->tabs_gui->addTab(
1567  "id_meta_data",
1568  $this->lng->txt("meta_data"),
1569  $mdtab
1570  );
1571  }
1572  }
1573 
1574  if ($this->checkPermissionBool('write')) {
1575  $this->tabs_gui->addTab(
1576  'export',
1577  $this->lng->txt('export'),
1578  $this->ctrl->getLinkTargetByClass('ilexportgui', '')
1579  );
1580  }
1581 
1582  // will add permission tab if needed
1583  parent::setTabs();
1584  }
1585 
1586  private function __prepareOutput(): void
1587  {
1588  $this->tpl->setLocator();
1589  }
1590 
1594  protected function addLocatorItems(): void
1595  {
1596  global $DIC;
1597 
1598  $ilLocator = $DIC['ilLocator'];
1599  if (is_object($this->object)) {
1600  $ilLocator->addItem(
1601  $this->object->getTitle(),
1602  $this->ctrl->getLinkTarget($this),
1603  "",
1604  $this->object->getRefId(),
1605  "webr"
1606  );
1607  }
1608  }
1609 
1610  public function callDirectLink(): void
1611  {
1612  $obj_id = $this->object->getId();
1613 
1614  if ($this->getWebLinkRepo()->doesOnlyOneItemExist(true)) {
1616 
1617  $this->redirectToLink(
1618  $this->ref_id,
1619  $obj_id,
1620  $item->getResolvedLink((bool) $this->settings->get('links_dynamic'))
1621  );
1622  }
1623  }
1624 
1625  public function callLink(): void
1626  {
1627  if ($this->http->wrapper()->query()->has('link_id')) {
1628  $link_id = $this->http->wrapper()->query()->retrieve(
1629  'link_id',
1630  $this->refinery->kindlyTo()->int()
1631  );
1632 
1633  $item = $this->getWebLinkRepo()->getItemByLinkId($link_id);
1634 
1635  $this->redirectToLink(
1636  $this->ref_id,
1637  $this->object->getId(),
1638  $item->getResolvedLink((bool) $this->settings->get('links_dynamic'))
1639  );
1640  }
1641  }
1642 
1643  protected function redirectToLink(
1644  int $a_ref_id,
1645  int $a_obj_id,
1646  string $a_url
1647  ): void {
1648  if ($a_url) {
1650  "webr",
1651  $a_ref_id,
1652  $a_obj_id,
1653  $this->user->getId()
1654  );
1655  ilUtil::redirect($a_url);
1656  }
1657  }
1658 
1659  public function exportHTML(): void
1660  {
1661  $tpl = new ilTemplate(
1662  "tpl.export_html.html",
1663  true,
1664  true,
1665  "components/ILIAS/WebResource"
1666  );
1667 
1668  $items = $this->getWebLinkRepo()->getAllItemsAsContainer(true)
1669  ->getItems();
1670  foreach ($items as $item) {
1671  $tpl->setCurrentBlock("link_bl");
1672  $tpl->setVariable("LINK_URL", $item->getResolvedLink(false));
1673  $tpl->setVariable("LINK_TITLE", $item->getTitle());
1674  $tpl->setVariable("LINK_DESC", $item->getDescription() ?? '');
1675  $tpl->setVariable("LINK_CREATE", $item->getCreateDate()
1676  ->format('Y-m-d H-i-s'));
1677  $tpl->setVariable("LINK_UPDATE", $item->getLastUpdate()
1678  ->format('Y-m-d H-i-s'));
1680  }
1681 
1682  $tpl->setVariable("CREATE_DATE", $this->object->getCreateDate());
1683  $tpl->setVariable("LAST_UPDATE", $this->object->getLastUpdateDate());
1684  $tpl->setVariable("TXT_TITLE", $this->object->getTitle());
1685  $tpl->setVariable("TXT_DESC", $this->object->getLongDescription());
1686 
1687  $tpl->setVariable(
1688  "INST_ID",
1689  ($this->settings->get('short_inst_name') != "")
1690  ? $this->settings->get('short_inst_name')
1691  : "ILIAS"
1692  );
1693 
1694  ilUtil::deliverData($tpl->get(), "bookmarks.html");
1695  }
1696 
1697  public static function _goto(string $a_target, $a_additional = null): void
1698  {
1699  global $DIC;
1700 
1701  $main_tpl = $DIC->ui()->mainTemplate();
1702  $ilAccess = $DIC->access();
1703  $lng = $DIC->language();
1704  $ctrl = $DIC->ctrl();
1705  $ilErr = $DIC['ilErr'];
1706 
1707  if ($a_additional && substr($a_additional, -3) == "wsp") {
1708  $ctrl->setTargetScript('ilias.php');
1710  ilSharedResourceGUI::class,
1711  'wsp_id',
1712  $a_target
1713  );
1715  [
1716  ilSharedResourceGUI::class
1717  ],
1718  'edit'
1719  );
1720  return;
1721  }
1722 
1723  // Will be replaced in future releases by ilAccess::checkAccess()
1724  if ($ilAccess->checkAccess("read", "", (int) $a_target)) {
1726  "ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=" . $a_target
1727  );
1728  } elseif ($ilAccess->checkAccess("visible", "", (int) $a_target)) {
1730  "ilias.php?baseClass=ilLinkResourceHandlerGUI&ref_id=" . $a_target . "&cmd=infoScreen"
1731  );
1732  } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
1733  $main_tpl->setOnScreenMessage(
1734  'failure',
1735  sprintf(
1736  $lng->txt("msg_no_perm_read_item"),
1739  (int) $a_target
1740  )
1741  )
1742  ),
1743  true
1744  );
1746  }
1747 
1748  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1749  }
1750 }
static get(string $a_var)
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
ilWebLinkDraftParameter $draft_parameter
infoScreen()
instead of redirecting here, links to the info screen should directly lead to the right place...
Class ilObjectMetaDataGUI.
static _goto(string $a_target, $a_additional=null)
Draft class for creating and updating a parameter attached to Web Link items.
static getInitHTML(string $a_url)
Get initialisation HTML to use internal link editing.
TableGUI class for search results.
setAllowedLinkTypes(string $a_val)
Set allowed link types (LIST, BOTH, INT, EXT)
ilErrorHandling $error
This class represents a selection list property in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
New implementation of ilObjectGUI.
GUI class for the workflow of copying objects.
const ROOT_FOLDER_ID
Definition: constants.php:32
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$valid
getLinkToListModal()
Get form to transform a single weblink to a weblink list.
createItem(ilWebLinkDraftItem $item)
Creates a new item, complete with parameters.
getDidacticTemplateVar(string $type)
Get didactic template setting from creation screen.
const array VALUES_TEXT
Keys of the language variables to the possible values, e.g.
Class ilObjLinkResourceGUI.
activateTabs(string $a_active_tab, string $a_active_subtab='')
Activate tab and subtabs.
setParameterByClass(string $a_class, string $a_parameter, $a_value)
prepareOutput(bool $show_sub_objects=true)
Internal link selector.
infoScreenForward()
show information screen
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
setVariable(string $variable, $value='')
Sets the given variable to the given value.
redirectToLink(int $a_ref_id, int $a_obj_id, string $a_url)
checkLinkInput(int $a_mode, bool $a_valid, ?int $a_link_id=null)
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-...
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
$ilErr
Definition: raiseError.php:33
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This class represents a hidden form property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
afterSave(ilObject $new_object)
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)
editLinks()
Start with manage mode.
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
$param
Definition: xapitoken.php:46
static _recordReadEvent(string $a_type, int $a_ref_id, int $obj_id, int $usr_id, bool $isCatchupWriteEvents=true, $a_ext_rc=null, $a_ext_time=null)
__construct(int $id=0, int $id_type=self::REPOSITORY_NODE_ID, int $parent_node_id=0)
global $DIC
Definition: shib_login.php:26
ilGlobalTemplateInterface $tpl
putObjectInTree(ilObject $obj, ?int $parent_node_id=null)
Add object to tree at given position.
static has($a_var)
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
static redirect(string $a_script)
switchViewMode(?int $force_view_mode=null)
Switch between "View" "Manage" and "Sort".
form( $class_path, string $cmd, string $submit_caption="")
Draft class for creating or updating a Web Link list.
setTargetScript(string $a_target_script)
static isInternalLink(string $a_value)
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
static _getInstance(int $a_obj_id)
Draft class for creating and updating a Web Link item.
$info
Definition: entry_point.php:21
const string LINKS_ERR_NO_NAME
TODO: This can be removed when validate is.
addHeaderAction()
Add header action menu.
static set(string $a_var, $a_val)
Set a value.
static _getFirstLink(int $a_webr_id)
Get first link item Check before with _isSingular() if there is more or less than one...
This class represents a external and/or internal link in a property form.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
initViewMode(?int $new_view_mode=null)
$r