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