ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjFileGUI.php
Go to the documentation of this file.
1<?php
2
23use Psr\Http\Message\ServerRequestInterface;
43
55{
59
60 public const UPLOAD_MAX_FILES = 100;
61 public const PARAM_FILES = 'files';
62 public const PARAM_TITLE = 'title';
63 public const PARAM_DESCRIPTION = 'description';
64 public const PARAM_COPYRIGHT_ID = "copyright_id";
65
66 public const PARAM_UPLOAD_ORIGIN = 'origin';
67 public const UPLOAD_ORIGIN_STANDARD = 'standard';
68 public const UPLOAD_ORIGIN_DROPZONE = 'dropzone';
69
70 public const CMD_EDIT = Capabilities::EDIT_SETTINGS->value;
71 public const CMD_VERSIONS = Capabilities::MANAGE_VERSIONS->value;
72 public const CMD_UPLOAD_FILES = "uploadFiles";
73
74 public const CMD_SEND_FILE = Capabilities::DOWNLOAD->value;
76
80 public ?ilObject $object = null;
82 protected UIServices $ui;
85 protected Services $storage;
86 protected ?ilLogger $log = null;
88 protected \ILIAS\Refinery\Factory $refinery;
92 protected \ILIAS\UI\Component\Input\Factory $inputs;
94 protected ServerRequestInterface $request;
97 protected LOMServices $lom_services;
98
102 public function __construct(int $a_id = 0, int $a_id_type = self::REPOSITORY_NODE_ID, int $a_parent_node_id = 0)
103 {
104 global $DIC;
105 $this->refinery = $DIC->refinery();
106 $this->file_service_settings = $DIC->fileServiceSettings();
107 $this->user = $DIC->user();
108 $this->lng = $DIC->language();
110 $this->ui = $DIC->ui();
111 $this->storage = $DIC->resourceStorage();
112 $this->upload_handler = new ilObjFileUploadHandlerGUI();
113 $this->stakeholder = new ilObjFileStakeholder();
114 $this->general_settings = new General();
115 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
116 $this->obj_service = $DIC->object();
117 $this->lng->loadLanguageModule(ilObjFile::OBJECT_TYPE);
118 $this->icon_repo = new IconDatabaseRepository();
119 $this->inputs = $DIC->ui()->factory()->input();
120 $this->renderer = $DIC->ui()->renderer();
121 $this->request = $DIC->http()->request();
122 $this->data_factory = new Factory();
123 $this->action_repo = new ActionDBRepository($DIC->database());
124 $this->lom_services = $DIC->learningObjectMetadata();
125
126 $capability_builder = new CapabilityBuilder(
128 $this->access,
129 $this->ctrl,
130 $this->action_repo,
131 $DIC->http(),
132 $DIC['static_url.uri_builder']
133 );
134
135 $capability_context = new Context(
136 $this->object_id,
137 $this->ref_id,
138 ($a_id_type === self::WORKSPACE_NODE_ID) ? Context::CONTEXT_WORKSPACE : Context::CONTEXT_REPO
139 );
140
141 $this->capabilities = $capability_builder->get($capability_context);
142 }
143
144 protected function updateLearningProgress(): void
145 {
146 if ($this->object->getLPMode() === ilLPObjSettings::LP_MODE_CONTENT_VISITED) {
148 $this->object->getId(),
149 $this->user->getId(),
150 null,
151 false,
152 true
153 );
154 }
155 }
156
157 public function getType(): string
158 {
160 }
161
162 public function getParentId(): int
163 {
164 return $this->parent_id;
165 }
166
167 #[\Override]
168 public function executeCommand(): void
169 {
170 global $DIC;
171 $ilNavigationHistory = $DIC['ilNavigationHistory'];
172 $ilUser = $DIC['ilUser'];
173 $ilTabs = $DIC['ilTabs'];
174 $ilErr = $DIC['ilErr'];
175
176 $next_class = $this->ctrl->getNextClass($this);
177 $cmd = $this->ctrl->getCmd();
178
179 if (
180 !$this->getCreationMode()
181 && (
182 $this->id_type === self::REPOSITORY_NODE_ID
183 && $this->capabilities->get(Capabilities::DOWNLOAD)->isUnlocked()
184 )) {
185 // add entry to navigation history
186 $ilNavigationHistory->addItem(
187 $this->node_id,
188 (string) $this->capabilities->get(Capabilities::INFO_PAGE)->getUri(),
190 );
191 }
192
193 $this->prepareOutput();
194
195 $info = (new ilObjFileInfoRepository())->getByObjectId($this->obj_id);
196
197 $suffix = $info->getSuffix();
198 $path_file_icon = $this->icon_repo->getIconFilePathBySuffix($suffix);
199 $this->tpl->setTitleIcon($path_file_icon);
200
201 switch ($next_class) {
202 case strtolower(ilInfoScreenGUI::class):
203 $this->infoScreenForward(); // forwards command
204 break;
205
206 case 'ilobjectmetadatagui':
207 if (!$this->capabilities->get(Capabilities::EDIT_SETTINGS)->isUnlocked()) {
208 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->WARNING);
209 }
210
211 $ilTabs->activateTab("id_meta");
212
213 $md_gui = new ilObjectMetaDataGUI($this->object, null, null, $this->call_by_reference);
214
215 // todo: make this work
216 // $md_gui->addMDObserver($this->object,'MDUpdateListener','Technical');
217
218 $this->ctrl->forwardCommand($md_gui);
219 break;
220
221 // repository permissions
222 case 'ilpermissiongui':
223 $ilTabs->activateTab("id_permissions");
224 $perm_gui = new ilPermissionGUI($this);
225 $this->ctrl->forwardCommand($perm_gui);
226 break;
227
228 case "ilexportgui":
229 $ilTabs->activateTab("export");
230 $exp_gui = new ilExportGUI($this);
231 $exp_gui->addFormat();
232 $this->ctrl->forwardCommand($exp_gui);
233 break;
234
235 case 'ilobjectcopygui':
236 $cp = new ilObjectCopyGUI($this);
237 $cp->setType(ilObjFile::OBJECT_TYPE);
238 $this->ctrl->forwardCommand($cp);
239 break;
240
241 // personal workspace permissions
242 case "ilworkspaceaccessgui":
243 $ilTabs->activateTab("id_permissions");
244 $wspacc = new ilWorkspaceAccessGUI($this->node_id, $this->getAccessHandler());
245 $this->ctrl->forwardCommand($wspacc);
246 break;
247
248 case "ilcommonactiondispatchergui":
250 $this->ctrl->forwardCommand($gui);
251 break;
252
253 case "illearningprogressgui":
254 $ilTabs->activateTab('learning_progress');
255 $user_id = $this->request_wrapper->has('user_id')
256 ? $this->request_wrapper->retrieve('user_id', $this->refinery->kindlyTo()->int())
257 : $ilUser->getId();
258 $new_gui = new ilLearningProgressGUI(
260 $this->object->getRefId(),
262 );
263 $this->ctrl->forwardCommand($new_gui);
264 $this->tabs_gui->setTabActive('learning_progress');
265 break;
266 case strtolower(ilFileVersionsGUI::class):
267 $this->tabs_gui->activateTab("id_versions");
268
269 if (!$this->capabilities->get(Capabilities::MANAGE_VERSIONS)->isUnlocked()) {
270 $this->error->raiseError($this->lng->txt("permission_denied"), $this->error->MESSAGE);
271 }
273 $obj = $this->object;
274 $this->ctrl->forwardCommand(new ilFileVersionsGUI($obj));
275 break;
276 case strtolower(ilObjFileUploadHandlerGUI::class):
277 $this->ctrl->forwardCommand(new ilObjFileUploadHandlerGUI());
278 break;
279 case strtolower(ilWOPIEmbeddedApplicationGUI::class):
280 $capability = match($cmd) {
281 ilWOPIEmbeddedApplicationGUI::CMD_VIEW => $this->capabilities->get(Capabilities::VIEW_EXTERNAL),
282 ilWOPIEmbeddedApplicationGUI::CMD_EDIT => $this->capabilities->get(Capabilities::EDIT_EXTERNAL),
283 ilWOPIEmbeddedApplicationGUI::CMD_RETURN => $this->capabilities->get(Capabilities::INFO_PAGE),
284 default => null
285 };
286
287 if ($capability === null || !$capability->isUnlocked()) {
288 $this->error->raiseError($this->lng->txt("permission_denied"), $this->error->MESSAGE);
289 return;
290 }
291 $action = match ($capability->getCapability()) {
292 Capabilities::VIEW_EXTERNAL => $this->action_repo->getViewActionForSuffix($suffix),
293 Capabilities::EDIT_EXTERNAL => $this->action_repo->getEditActionForSuffix($suffix),
294 default => null
295 };
296
297 $this->tabs_gui->activateTab('content');
298 $this->updateLearningProgress();
299
300 if ($this->id_type === Context::CONTEXT_WORKSPACE) {
302 $this->node_id,
303 $this->object->getId()
304 );
305 } else {
306 $goto_link = ilLink::_getLink($this->object->getRefId());
307 }
308
309 $embeded_application = new EmbeddedApplication(
310 $this->storage->manage()->find($this->object->getResourceId()),
311 $action,
312 $this->stakeholder,
313 new URI($goto_link),
314 $capability->getCapability() === Capabilities::VIEW_EXTERNAL,
315 $this->lng->getLangKey()
316 );
317
318 $this->ctrl->forwardCommand(
320 $embeded_application
321 )
322 );
323 break;
324
325 case strtolower(ilFileCommonSettingsGUI::class):
326 $this->initSettingsTab();
327 $this->tabs_gui->activateSubTab("service_settings");
328 $this->ctrl->forwardCommand(
330 $this->object,
331 $this->ctrl,
332 $this->tpl,
333 $this->lng,
334 $this->object_service
335 )
336 );
337 break;
338
339 default:
340 // in personal workspace use object2gui
341 if ($this->id_type === self::WORKSPACE_NODE_ID) {
342 $this->addHeaderAction();
343 $ilTabs->clearTargets();
344
345 if (empty($cmd) || $cmd === 'render') {
346 $cmd = Capabilities::INFO_PAGE->value;
347 $this->$cmd();
348 } else {
349 parent::executeCommand();
350 }
351 break; // otherwise subtabs are duplicated
352 }
353
354 if (empty($cmd) || $cmd === 'render') {
355 $cmd = Capabilities::INFO_PAGE->value;
356 }
357
358 $this->$cmd();
359 break;
360 }
361
362 $this->addHeaderAction();
363 }
364
365
366 protected function addUIFormToAccordion(
367 ilAccordionGUI $accordion,
368 Standard $form,
369 int $form_type
370 ): void {
371 // abort if form-type is unknown
372 if (!in_array($form_type, [self::CFORM_NEW, self::CFORM_CLONE, self::CFORM_IMPORT], true)) {
373 return;
374 }
375
376 $inputs = $form->getInputs();
377 // use label of first input as title, because UI Component forms don't support form-titles yet
378 $title = ($inputs === []) ?
379 '' : $inputs[array_key_first($inputs)]->getLabel();
380
381 $tpl = new ilTemplate("tpl.creation_acc_head.html", true, true, "components/ILIAS/ILIASObject");
382 $tpl->setVariable("TITLE", $this->lng->txt("option") . " " . $form_type . ": " . $title);
383
384 $accordion->addItem($tpl->get(), $this->ui->renderer()->render($form));
385 }
386
387 protected function addLegacyFormToAccordion(
388 ilAccordionGUI $accordion,
389 ilPropertyFormGUI $form,
390 int $form_type
391 ): void {
392 // abort if form-type is unknown
393 if (!in_array($form_type, [self::CFORM_NEW, self::CFORM_CLONE, self::CFORM_IMPORT], true)) {
394 return;
395 }
396 $title = $form->getTitle();
397 $form->setTitle(''); // see https://mantis.ilias.de/view.php?id=37786
398
399 $tpl = new ilTemplate("tpl.creation_acc_head.html", true, true, "components/ILIAS/ILIASObject");
400 $tpl->setVariable("TITLE", $this->lng->txt("option") . " " . $form_type . ": " . $title);
401
402 $accordion->addItem($tpl->get(), $form->getHTML());
403 }
404
408 #[\Override]
409 protected function initCreateForm(string $new_type): Standard
410 {
411 return $this->initUploadForm();
412 }
413
414 #[\Override]
415 protected function getCreationFormTitle(): string
416 {
417 return $this->lng->txt('upload_files');
418 }
419
420 public function initUploadForm(): Standard
421 {
422 $this->getLanguage()->loadLanguageModule('file');
423 $inputs = [];
424
425 $this->ctrl->setParameterByClass(self::class, 'new_type', $this->getType());
426 $this->ctrl->setParameterByClass(
427 self::class,
428 self::PARAM_UPLOAD_ORIGIN,
429 self::UPLOAD_ORIGIN_STANDARD
430 );
431
432
433 $inputs[self::PARAM_FILES] = $this->ui->factory()->input()->field()->file(
434 $this->upload_handler,
435 $this->lng->txt('upload_files'),
436 null,
437 $this->ui->factory()->input()->field()->group([
438 self::PARAM_TITLE => $this->ui->factory()->input()->field()->text(
439 $this->lng->txt('title')
440 )->withAdditionalTransformation(
441 $this->getEmptyStringToNullTransformation()
442 ),
443 self::PARAM_DESCRIPTION => $this->ui->factory()->input()->field()->textarea(
444 $this->lng->txt('description')
445 )->withAdditionalTransformation(
446 $this->getEmptyStringToNullTransformation()
447 ),
448 ])
449 )->withMaxFiles(
450 self::UPLOAD_MAX_FILES
451 )->withRequired(true);
452
453 if ($this->lom_services->copyrightHelper()->isCopyrightSelectionActive()) {
454 $inputs[self::PARAM_COPYRIGHT_ID] = $this->getCopyrightSelectionInput('set_license_for_all_files');
455 }
456
457 return $this->ui->factory()->input()->container()->form()->standard(
458 $this->ctrl->getFormActionByClass(self::class, self::CMD_UPLOAD_FILES),
459 $inputs
460 )->withSubmitLabel($this->lng->txt('upload_files'));
461 }
462
466 protected function uploadFiles(): void
467 {
468 $origin = ($this->request_wrapper->has(self::PARAM_UPLOAD_ORIGIN)) ?
469 $this->request_wrapper->retrieve(
470 self::PARAM_UPLOAD_ORIGIN,
471 $this->refinery->kindlyTo()->string()
472 ) : self::UPLOAD_ORIGIN_STANDARD;
473
474 if (self::UPLOAD_ORIGIN_DROPZONE === $origin) {
475 $dropzone = new ilObjFileUploadDropzone($this->parent_id);
476 $dropzone = $dropzone->getDropzone()->withRequest($this->request);
477 $data = $dropzone->getData();
478 } else {
479 $form = $this->initUploadForm()->withRequest($this->request);
480 $data = $form->getData();
481 }
482 $files = $data[self::PARAM_FILES] ?? $data[0] ?? null;
483
484 if (empty($files)) {
485 $form = $this->initUploadForm()->withRequest($this->request);
486 $this->tpl->setContent($this->getCreationFormsHTML($form));
487 return;
488 }
489
490 $processor = new ilObjFileProcessor(
491 $this->stakeholder,
492 $this,
493 $this->storage,
494 $this->file_service_settings
495 );
496
497 $errors = false;
498 foreach ($files as $file_data) {
499 $rid = $this->storage->manage()->find($file_data[0]);
500 if (null !== $rid) {
501 try {
502 $processor->process(
503 $rid,
504 $file_data[1][self::PARAM_TITLE] ?? null,
505 $file_data[1][self::PARAM_DESCRIPTION] ?? null,
506 $data[self::PARAM_COPYRIGHT_ID] ?? null
507 );
508 } catch (Throwable $t) {
509 $errors = true;
510 if (null !== $this->log) {
511 $this->log->error($t->getMessage() . ": " . $t->getTraceAsString());
512 }
513 }
514 }
515 }
516
517 if ($errors) {
518 $this->ui->mainTemplate()->setOnScreenMessage(
519 'failure',
520 $this->lng->txt('could_not_create_file_objs'),
521 true
522 );
523 }
524
525 if ($processor->getInvalidFileNames() !== []) {
526 $this->ui->mainTemplate()->setOnScreenMessage(
527 'info',
528 sprintf(
529 $this->lng->txt('file_upload_info_file_with_critical_extension'),
530 implode(', ', $processor->getInvalidFileNames())
531 ),
532 true
533 );
534 }
535
536 $link = match ($this->id_type) {
537 self::WORKSPACE_NODE_ID => $this->ctrl->getLinkTargetByClass(ilObjWorkspaceRootFolderGUI::class),
538 default => ilLink::_getLink($this->requested_ref_id),
539 };
540
541 $this->ctrl->redirectToURL($link);
542 }
543
544 #[\Override]
545 public function putObjectInTree(ilObject $obj, ?int $parent_node_id = null): void
546 {
547 // this is needed to support multi fileuploads in personal and shared resources
548 $backup_node_id = $this->node_id;
549 parent::putObjectInTree($obj, $parent_node_id);
550 $this->node_id = $backup_node_id;
551 }
552
556 #[\Override]
557 public function update(): void
558 {
559 $data = [];
560 $form = $this->initPropertiesForm();
561 $form = $form->withRequest($this->request);
562 $inputs = $form->getData();
563
567 $title_and_description = $inputs['file_info']['title_and_description'];
568
569 $title = $title_and_description->getTitle();
570 // bugfix mantis 26045:
571 $filename = $this->object->getFileName();
572 if (trim((string) $title) === '') {
573 $title = $filename;
574 }
575 $title = $this->object->appendSuffixToTitle($title, $filename);
576
577 $this->object->handleChangedObjectTitle($title);
578
579 $description = $title_and_description->getLongDescription();
580 $this->object->setDescription($description);
581
582 $updated_title_and_description = new TitleAndDescription($title, $description);
583 $this->object->getObjectProperties()->storePropertyTitleAndDescription($updated_title_and_description);
584
585 $this->object->setImportantInfo($inputs['file_info']['important_info']);
586 $this->object->setRating($inputs['obj_features']['rating'] ?? false);
587 $this->object->setOnclickMode((int) $inputs['file_info']['on_click_action']);
588 $this->object->update();
589
590 $this->object->getObjectProperties()->storePropertyIsOnline($inputs['availability']['online_status']);
591
592 if (($inputs['presentation']['tile_image'] ?? null) !== null) {
593 $this->object->getObjectProperties()->storePropertyTileImage($inputs['presentation']['tile_image']);
594 }
595
596 // BEGIN ChangeEvent: Record update event.
597 if (!empty($data["name"])) {
598 global $DIC;
599 $ilUser = $DIC['ilUser'];
600 ilChangeEvent::_recordWriteEvent($this->object->getId(), $ilUser->getId(), 'update');
601 ilChangeEvent::_catchupWriteEvents($this->object->getId(), $ilUser->getId());
602 }
603 // END ChangeEvent: Record update event.
604
605 // Update ecs export settings
606 // $ecs = new ilECSFileSettings($this->object);
607 // $ecs->handleSettingsUpdate(); TODO: reintroduce usage of ECS file settings once they have been made compatible with the new ui components
608
609 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
610 $this->ctrl->redirectByClass(self::class, self::CMD_EDIT);
611 }
612
613 #[\Override]
614 public function edit(): void
615 {
616 global $DIC;
617 $ilErr = $DIC['ilErr'];
618
619 if (!$this->capabilities->get(Capabilities::EDIT_SETTINGS)->isUnlocked()) {
620 $ilErr->raiseError($this->lng->txt("msg_no_perm_write"));
621 }
622
623 $this->initSettingsTab();
624
625 $form = $this->initPropertiesForm();
626
627 // $ecs = new ilECSFileSettings($this->object);
628 // $ecs->addSettingsToForm($form, ilObjFile::OBJECT_TYPE); TODO: reintroduce usage of ECS file settings once they have been made compatible with the new ui components
629
630 $this->tpl->setContent($this->renderer->render($form));
631 }
632
633 protected function initPropertiesForm(): Standard
634 {
635 $title_and_description = $this->object->getObjectProperties()->getPropertyTitleAndDescription()->toForm(
636 $this->lng,
637 $this->ui->factory()->input()->field(),
638 $this->refinery
639 );
640
641 $important_info = $this->inputs->field()->markdown(
643 $this->lng->txt('important_info'),
644 $this->lng->txt('important_info_byline')
645 )->withValue(
646 $this->object->getImportantInfo() ?? ""
647 );
648
649 $on_click_action = $this->inputs->field()->radio(
650 $this->lng->txt('on_click_action')
651 )->withOption(
653 $this->lng->txt('file_action_download'),
654 $this->lng->txt('file_action_download_info'),
655 )->withOption(
657 $this->lng->txt('file_action_show'),
658 $this->lng->txt('file_action_show_info'),
659 )->withValue(
660 (string) $this->object->getOnClickMode()
661 );
662
663 $input_groups = array_filter([
664 "title_and_description" => $title_and_description,
665 "important_info" => $important_info,
666 "on_click_action" => $on_click_action
667 ], static fn(FormInput $input): bool => null !== $input);
668
669 $file_info_section = $this->inputs->field()->section(
670 $input_groups,
671 $this->lng->txt('file_info')
672 );
673
674 $online_status = $this->object->getObjectProperties()->getPropertyIsOnline()->toForm(
675 $this->lng,
676 $this->ui->factory()->input()->field(),
677 $this->refinery
678 );
679 $availability_section = $this->inputs->field()->section(
680 ["online_status" => $online_status],
681 $this->lng->txt('rep_activation_availability')
682 );
683
684 $presentation_section = null;
685 if ($this->id_type === self::REPOSITORY_NODE_ID) {
686 $tile_image = $this->object->getObjectProperties()->getPropertyTileImage()->toForm(
687 $this->lng,
688 $this->ui->factory()->input()->field(),
689 $this->refinery
690 );
691 $presentation_section = $this->inputs->field()->section(
692 ["tile_image" => $tile_image],
693 $this->lng->txt('settings_presentation_header')
694 );
695 }
696
697 $additional_features_section = null;
698 if ($this->id_type === self::REPOSITORY_NODE_ID) {
699 $this->lng->loadLanguageModule('rating');
700
701 $enable_rating = $this->inputs->field()->checkbox(
702 $this->lng->txt('rating_activate_rating'),
703 $this->lng->txt('rating_activate_rating_info')
704 )->withValue(
705 $this->object->hasRating()
706 );
707 $additional_features_section = $this->inputs->field()->section(
708 ["rating" => $enable_rating],
709 $this->lng->txt('obj_features')
710 );
711 }
712
713 $inputs = array_filter([
714 "file_info" => $file_info_section,
715 "availability" => $availability_section,
716 "presentation" => $presentation_section,
717 "obj_features" => $additional_features_section
718 ], static fn(?Section $input): bool => null !== $input);
719
720 return $this->inputs->container()->form()->standard(
721 $this->ctrl->getLinkTargetByClass(self::class, 'update'),
722 $inputs
723 );
724 }
725
726 public function sendFile(): bool
727 {
728 $hist_entry_id = $this->request_wrapper->has('hist_id')
729 ? $this->request_wrapper->retrieve('hist_id', $this->refinery->kindlyTo()->int())
730 : null;
731 try {
732 if (ANONYMOUS_USER_ID === $this->user->getId() && $this->request_wrapper->has('transaction')) {
733 $this->object->sendFile($hist_entry_id);
734 }
735
736 if ($this->capabilities->get(Capabilities::DOWNLOAD)->isUnlocked()) {
737 // Record read event and catchup with write events
739 $this->object->getType(),
740 $this->object->getRefId(),
741 $this->object->getId(),
742 $this->user->getId()
743 );
744 $this->updateLearningProgress();
745
746 $this->object->sendFile($hist_entry_id);
747 } else {
748 $this->error->raiseError($this->lng->txt("permission_denied"), $this->error->MESSAGE);
749 }
750 } catch (FileNotFoundException $e) {
751 $this->error->raiseError($e->getMessage(), $this->error->MESSAGE);
752 }
753
754 return true;
755 }
756
760 public function showSummary(): void
761 {
762 $this->ctrl->redirectToURL(
763 (string) $this->capabilities->get(Capabilities::INFO_PAGE)->getUri()
764 );
765 }
766 public function showSummaryForced(): void
767 {
768 $this->ctrl->redirectToURL(
769 (string) $this->capabilities->get(Capabilities::FORCED_INFO_PAGE)->getUri()
770 );
771 }
772
773 public function versions(): void
774 {
775 $this->ctrl->redirectToURL(
776 (string) $this->capabilities->get(Capabilities::MANAGE_VERSIONS)->getUri()
777 );
778 }
779
780 public function unzipCurrentRevision(): void
781 {
782 $this->ctrl->redirectToURL(
783 (string) $this->capabilities->get(Capabilities::UNZIP)->getUri()
784 );
785 }
786
787 protected function editExternal(): void
788 {
789 $this->ctrl->redirectToURL(
790 (string) $this->capabilities->get(Capabilities::EDIT_EXTERNAL)->getUri()
791 );
792 }
793 protected function viewExternal(): void
794 {
795 $this->ctrl->redirectToURL(
796 (string) $this->capabilities->get(Capabilities::VIEW_EXTERNAL)->getUri()
797 );
798 }
799
803 public function infoScreenForward(): void
804 {
805 $this->tabs_gui->activateTab("id_info");
806
807 if (!$this->capabilities->get(Capabilities::INFO_PAGE)->isUnlocked()) {
808 $GLOBALS['DIC']['ilErr']->raiseError(
809 $this->lng->txt("msg_no_perm_read"),
810 2
811 ); // TODO remove magic number and old ilErr call
812 }
813
814 // add set completed button, if LP mode is active
815 if ($this->object->getLPMode() === ilLPObjSettings::LP_MODE_MANUAL) {
816 if (ilLPStatus::_hasUserCompleted($this->object->getId(), $this->user->getId())) {
817 $label = $this->lng->txt('file_btn_lp_toggle_state_completed');
818 } else {
819 $label = $this->lng->txt('file_btn_lp_toggle_state_not_completed');
820 }
821 $this->toolbar->addComponent(
822 $this->ui->factory()->button()->standard(
823 $label,
824 $this->ctrl->getLinkTarget($this, 'toggleLearningProgress')
825 )
826 );
827 }
828
829 // Add WOPI editor Button
830 if ($this->capabilities->get(Capabilities::EDIT_EXTERNAL)->isUnlocked()) {
831 $external_editor = $this->ui->factory()
832 ->button()
833 ->standard(
834 $this->lng->txt('open_external_editor'),
835 $this->ctrl->getLinkTargetByClass(
836 \ilWOPIEmbeddedApplicationGUI::class,
838 )
839 );
840 $this->toolbar->addComponent($external_editor);
841 }
842
843 $info = $this->buildInfoScreen(false);
844 $this->ctrl->forwardCommand($info);
845 }
846
847 protected function toggleLearningProgress(): void
848 {
850 $this->user->getId(),
851 $this->obj_id,
852 $this->ref_id,
853 'file'
854 );
855
856 $lp_marks = new ilLPMarks($this->obj_id, $this->user->getId());
857 $lp_marks->setCompleted(!ilLPStatus::_hasUserCompleted($this->object->getId(), $this->user->getId()));
858 $lp_marks->update();
859
860 ilLPStatusWrapper::_updateStatus($this->obj_id, $this->user->getId());
861
862 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
863 $this->ctrl->redirect($this, Capabilities::INFO_PAGE->value);
864 }
865
866 public function buildInfoScreen(bool $kiosk_mode): ilInfoScreenGUI
867 {
868 $info = new ilInfoScreenGUI($this);
869
870 if (!$kiosk_mode) { // in kiosk mode we don't want to show the following sections
871 $info->enablePrivateNotes();
872
873 if ($this->capabilities->get(Capabilities::DOWNLOAD)->isUnlocked()) {
874 $info->enableNews();
875 }
876
877 // no news editing for files, just notifications
878 $info->enableNewsEditing(false);
879 if ($this->capabilities->get(Capabilities::MANAGE_VERSIONS)->isUnlocked()) {
880 $news_set = new ilSetting("news");
881 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
882
883 if ($enable_internal_rss) {
884 $info->setBlockProperty("news", "settings", true);
885 $info->setBlockProperty("news", "public_notifications_option", true);
886 }
887 }
888
889 $obj_id = $this->object->getId();
890 $record_gui = new ilAdvancedMDRecordGUI(
892 'file',
893 $obj_id,
894 '',
895 0,
896 $this->call_by_reference
897 );
898 $record_gui->setInfoObject($info);
899 $record_gui->parse();
900 }
901 // show rating is not possible in kiosk mode
902
903 // Important Information
904 $important_info = $this->object->getImportantInfo();
905 if (!empty($important_info)) {
906 $group = new Group(new Factory(), $this->lng);
907 $markdown_to_html = $group->markdown()->toHTML();
908
909 $info->addSection($this->lng->txt("important_info"));
910 $info->addProperty("", $markdown_to_html->transform($important_info));
911 }
912
913 // Download Launcher
914 if ($this->capabilities->get(Capabilities::DOWNLOAD)->isUnlocked()) {
915 // get permanent download link for repository
916 if ($this->id_type === self::REPOSITORY_NODE_ID) {
917 $download_target = ilObjFileAccess::_getPermanentDownloadLink($this->node_id);
918 } else {
919 $download_target = rtrim(ILIAS_HTTP_PATH, '/') . '/' . $this->ctrl->getLinkTarget(
920 $this,
921 self::CMD_SEND_FILE
922 );
923 }
924 $url = $this->data_factory->uri($download_target);
925 $link = $this->data_factory->link($this->lng->txt('file_download'), $url);
926 $download_launcher = $this->ui->factory()->launcher()->inline($link);
927 // create own section for download launcher if there is no important info section
928 if (empty($important_info)) {
929 $info->addSection("");
930 }
931 // add download launcher
932 $info->addProperty("", $this->renderer->render($download_launcher));
933 }
934
935 // standard meta data
936 $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
937
938 // in kiosk mode we don't want to show the following sections
939 // links to resource
940 if (!$kiosk_mode && ($this->access->checkAccess("write", "", $this->ref_id) ||
941 $this->access->checkAccess("edit_permissions", "", $this->ref_id))) {
942 $rs = ilObject::_getAllReferences($this->obj_id);
943 $refs = [];
944 foreach ($rs as $r) {
945 if ($this->tree->isInTree($r)) {
946 $refs[] = $r;
947 }
948 }
949 if (count($refs) > 1) {
950 $links = $sep = "";
951 foreach ($refs as $r) {
952 $cont_loc = new ilLocatorGUI();
953 $cont_loc->addContextItems($r, true);
954 $links .= $sep . $cont_loc->getHTML();
955 $sep = "<br />";
956 }
957
958 $info->addProperty(
959 $this->lng->txt("res_links"),
960 '<div class="small">' . $links . '</div>'
961 );
962 }
963 }
964
965 // File Info
966 $info->addSection($this->lng->txt("file_info"));
967 if ($kiosk_mode) {
968 $file_info_for_users = $this->getFileInfoForUsers();
969 foreach ($file_info_for_users as $file_info_entry_key => $file_info_entry_value) {
970 if ($file_info_entry_value !== null) {
971 $info->addProperty($file_info_entry_key, $file_info_entry_value);
972 }
973 }
974 } else {
975 $file_info = $this->getAllFileInfoForCurrentUser();
976 foreach ($file_info as $file_info_block) {
977 foreach ($file_info_block as $file_info_entry_key => $file_info_entry_value) {
978 if ($file_info_entry_value !== null) {
979 $info->addProperty($file_info_entry_key, $file_info_entry_value);
980 }
981 }
982 }
983 }
984
985 $info->hideFurtherSections(false);
986
987 return $info;
988 }
989
990 // get tabs
991 #[\Override]
992 protected function setTabs(): void
993 {
994 global $DIC;
995 $ilHelp = $DIC['ilHelp'];
996 $ilHelp->setScreenIdComponent(ilObjFile::OBJECT_TYPE);
997
998 $this->ctrl->setParameter($this, "ref_id", $this->node_id);
999
1000 if (($c = $this->capabilities->get(Capabilities::VIEW_EXTERNAL)) && $c->isUnlocked()) {
1001 $this->tabs_gui->addTab(
1002 "content",
1003 $this->lng->txt("content"),
1004 $c->getURI()
1005 );
1006 }
1007
1008 if (($c = $this->capabilities->get(Capabilities::MANAGE_VERSIONS)) && $c->isUnlocked()) {
1009 $this->tabs_gui->addTab(
1010 "id_versions",
1011 $this->lng->txt(self::CMD_VERSIONS),
1012 $this->ctrl->getLinkTargetByClass(ilFileVersionsGUI::class, ilFileVersionsGUI::CMD_DEFAULT)
1013 );
1014 }
1015
1016 if (($c = $this->capabilities->get(Capabilities::INFO_PAGE)) && $c->isUnlocked()) {
1017 $this->tabs_gui->addTab(
1018 "id_info",
1019 $this->lng->txt("info_short"),
1020 $this->ctrl->getLinkTargetByClass(["ilobjfilegui", "ilinfoscreengui"], "showSummary")
1021 );
1022 }
1023
1024 if (($c = $this->capabilities->get(Capabilities::EDIT_SETTINGS)) && $c->isUnlocked()) {
1025 $this->tabs_gui->addTab(
1026 "settings",
1027 $this->lng->txt("settings"),
1028 $this->ctrl->getLinkTarget($this, self::CMD_EDIT)
1029 );
1030 }
1031
1032 if (ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
1033 $this->tabs_gui->addTab(
1034 'learning_progress',
1035 $this->lng->txt('learning_progress'),
1036 $this->ctrl->getLinkTargetByClass([self::class, 'illearningprogressgui'], '')
1037 );
1038 }
1039
1040 // meta data
1041 if (($c = $this->capabilities->get(Capabilities::EDIT_SETTINGS)) && $c->isUnlocked()) {
1042 $mdgui = new ilObjectMetaDataGUI($this->object, null, null, $this->call_by_reference);
1043 $mdtab = $mdgui->getTab();
1044 if ($mdtab) {
1045 $this->tabs_gui->addTab(
1046 "id_meta",
1047 $this->lng->txt("meta_data"),
1048 $mdtab
1049 );
1050 }
1051 }
1052
1053 // export
1054 if (($c = $this->capabilities->get(Capabilities::EDIT_SETTINGS)) && $c->isUnlocked()) {
1055 $this->tabs_gui->addTab(
1056 "export",
1057 $this->lng->txt("export"),
1058 $this->ctrl->getLinkTargetByClass("ilexportgui", "")
1059 );
1060 }
1061
1062 // will add permission tab if needed
1063 parent::setTabs();
1064 }
1065
1066 protected function initSettingsTab(): void
1067 {
1068 $this->tabs_gui->activateTab("settings");
1069 // add subtab for common settings
1070 $this->tabs_gui->addSubTab(
1071 'file_settings',
1072 $this->lng->txt('settings'),
1073 $this->ctrl->getLinkTargetByClass(self::class, self::CMD_EDIT)
1074 );
1075 if (in_array('file', ilAdvancedMDRecord::_getActivatedObjTypes(), true)) {
1076 $this->tabs_gui->addSubTab(
1077 'service_settings',
1078 $this->lng->txt('service_settings'),
1079 $this->ctrl->getLinkTargetByClass(ilFileCommonSettingsGUI::class, ilFileCommonSettingsGUI::CMD_EDIT)
1080 );
1081 }
1082
1083 $this->tabs_gui->activateSubTab("file_settings");
1084 }
1085
1086 public static function _goto($a_target, $a_additional = null): void
1087 {
1088 global $DIC;
1089 $main_tpl = $DIC->ui()->mainTemplate();
1090 $ilErr = $DIC['ilErr'];
1091 $lng = $DIC['lng'];
1092 $ilAccess = $DIC['ilAccess'];
1093
1094 if ($a_additional && str_ends_with((string) $a_additional, "wsp")) {
1096 }
1097
1098 // added support for direct download goto links
1099 if ($a_additional && str_ends_with((string) $a_additional, "download")) {
1100 ilObjectGUI::_gotoRepositoryNode($a_target, "sendfile");
1101 }
1102
1103 // static method, no workspace support yet
1104
1105 if ($ilAccess->checkAccess("visible", "", $a_target)
1106 || $ilAccess->checkAccess("read", "", $a_target)) {
1107 ilObjectGUI::_gotoRepositoryNode($a_target, Capabilities::INFO_PAGE->value);
1108 } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
1109 $main_tpl->setOnScreenMessage(
1110 'failure',
1111 sprintf(
1112 $lng->txt("msg_no_perm_read_item"),
1114 ),
1115 true
1116 );
1118 }
1119
1120 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1121 }
1122
1126 protected function addLocatorItems(): void
1127 {
1128 global $DIC;
1129 $ilLocator = $DIC['ilLocator'];
1130
1131 if (is_object($this->object)) {
1132 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
1133 }
1134 }
1135
1136 #[\Override]
1137 protected function initHeaderAction(?string $a_sub_type = null, ?int $a_sub_id = null): ?\ilObjectListGUI
1138 {
1139 $lg = parent::initHeaderAction($a_sub_type, $a_sub_id);
1140 if ($lg instanceof ilObjectListGUI && $this->object->hasRating()) {
1141 $lg->enableRating(
1142 true,
1143 null,
1144 false,
1145 [ilCommonActionDispatcherGUI::class, ilRatingGUI::class]
1146 );
1147 }
1148
1149 return $lg;
1150 }
1151
1152 protected function getCtrl(): \ilCtrl
1153 {
1154 return $this->ctrl;
1155 }
1156
1160 protected function getFileObj(): ilObjFile
1161 {
1162 if (!$this->object instanceof ilObjFile) {
1163 throw new ilFileException("Error: object is not of type ilObjFile or doesn't exist");
1164 }
1165
1166 return $this->object;
1167 }
1168
1170 {
1171 return $this->stakeholder;
1172 }
1173
1174 protected function getGeneralSettings(): General
1175 {
1176 return $this->general_settings;
1177 }
1178
1179 protected function getLanguage(): \ilLanguage
1180 {
1181 return $this->lng;
1182 }
1183
1184 protected function getNodeID(): int
1185 {
1186 return $this->node_id;
1187 }
1188
1189 protected function getRefinery(): \ILIAS\Refinery\Factory
1190 {
1191 return $this->refinery;
1192 }
1193
1194 protected function getUIFactory(): ILIAS\UI\Factory
1195 {
1196 return $this->ui->factory();
1197 }
1198
1199 protected function getUser(): ilObjUser
1200 {
1201 return $this->user;
1202 }
1203}
renderer()
$filename
Definition: buildRTE.php:78
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Indicates that a file is missing or not found.
error(string $a_errmsg)
return true
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getActivatedObjTypes()
get activated obj types
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)
static _catchupWriteEvents(int $obj_id, int $usr_id, ?string $timestamp=null)
Catches up with all write events which occured before the specified timestamp.
static _recordWriteEvent(int $obj_id, int $usr_id, string $action, ?int $parent_obj_id=null)
Records a write event.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
Class ilCtrl provides processing control methods.
Export User Interface Class.
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.
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
static _hasUserCompleted(int $a_obj_id, int $a_user_id)
Lookup user object completion.
language handling
static checkAccess(int $a_ref_id, bool $a_allow_only_read=true)
check access to learning progress
Class ilObjUserTrackingGUI.
static _tracProgress(int $a_user_id, int $a_obj_id, int $a_ref_id, string $a_obj_type='')
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static _getPermanentDownloadLink(int $ref_id)
Gets the permanent download link for the file.
GUI class for file objects.
LOMServices $lom_services
ServerRequestInterface $request
uploadFiles()
MUST be protected, since this is Called from ilObject2GUI when used in Personal Workspace.
ActionDBRepository $action_repo
const UPLOAD_ORIGIN_DROPZONE
initHeaderAction(?string $a_sub_type=null, ?int $a_sub_id=null)
Add header action menu.
addUIFormToAccordion(ilAccordionGUI $accordion, Standard $form, int $form_type)
getType()
Functions that must be overwritten.
putObjectInTree(ilObject $obj, ?int $parent_node_id=null)
Add object to tree at given position.
initCreateForm(string $new_type)
ILIAS UI Component Input Factory $inputs
const UPLOAD_ORIGIN_STANDARD
CapabilityCollection $capabilities
static _goto($a_target, $a_additional=null)
IconDatabaseRepository $icon_repo
ILIAS Refinery Factory $refinery
buildInfoScreen(bool $kiosk_mode)
infoScreenForward()
show information screen
General $general_settings
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
Constructor.
ilObjectService $obj_service
ilFileServicesSettings $file_service_settings
ResourceStakeholder $stakeholder
addLegacyFormToAccordion(ilAccordionGUI $accordion, ilPropertyFormGUI $form, int $form_type)
addLocatorItems()
Functions to be overwritten.
UploadHandler $upload_handler
setTabs()
create tabs (repository/workspace switch)
Class ilObjFileProcessorInterface.
Class ilObjFileStakeholder.
Class ilObjFile.
const CLICK_MODE_DOWNLOAD
const CLICK_MODE_INFOPAGE
const OBJECT_TYPE
User class.
New implementation of ilObjectGUI.
executeCommand()
execute command
ilGlobalTemplateInterface $tpl
prepareOutput(bool $show_sub_objects=true)
GUI class for the workflow of copying objects.
static _gotoSharedWorkspaceNode(int $wsp_id)
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
addHeaderAction()
Add header action menu.
static _gotoRepositoryNode(int $ref_id, string $cmd="")
Class ilObjectMetaDataGUI.
Class ilObject Basic functions for all objects.
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static getGotoLink(int $a_node_id, int $a_obj_id, string $a_additional="")
const ANONYMOUS_USER_ID
Definition: constants.php:27
const ROOT_FOLDER_ID
Definition: constants.php:32
$c
Definition: deliver.php:25
$info
Definition: entry_point.php:21
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This describes a standard form.
Definition: Standard.php:29
This describes section inputs.
Definition: Section.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
$ilErr
Definition: raiseError.php:33
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68
trait ilObjFileCopyrightInput
getLanguage()
trait ilObjFileInfoProvider
trait ilObjFileTransformation
$GLOBALS["DIC"]
Definition: wac.php:54