ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilFileVersionsGUI.php
Go to the documentation of this file.
1 <?php
2 
29 use ILIAS\Data\URI;
35 
41 {
43 
44  public const KEY_FILE_RID = 'file_rid';
45  public const KEY_FILE_EXTRACT = 'file_extract';
46  public const KEY_FILE_STRUCTURE = 'file_structure';
47  public const KEY_COPYRIGHT_OPTION = "copyright_option";
48  public const KEY_INHERIT_COPYRIGHT = "inherit_copyright";
49  public const KEY_SELECT_COPYRIGHT = "select_copyright";
50  public const KEY_COPYRIGHT_ID = "copyright_id";
51 
52  public const CMD_DEFAULT = 'index';
53  public const CMD_DELETE_VERSIONS = "deleteVersions";
54  public const CMD_ROLLBACK_VERSION = "rollbackVersion";
55  public const CMD_DOWNLOAD_VERSION = "sendFile";
56  public const HIST_ID = 'hist_id';
57  public const CMD_CANCEL_DELETE = "cancelDeleteFile";
58  public const CMD_CONFIRMED_DELETE_FILE = "confirmDeleteFile";
59  public const CMD_CONFIRMED_DELETE_VERSIONS = 'confirmDeleteVersions';
60  public const CMD_ADD_NEW_VERSION = 'addNewVersion';
61  public const CMD_CREATE_NEW_VERSION = 'saveVersion';
62  public const CMD_ADD_REPLACING_VERSION = 'addReplacingVersion';
63  public const CMD_CREATE_REPLACING_VERSION = 'createReplacingVersion';
64  public const CMD_UNZIP_CURRENT_REVISION = Capabilities::UNZIP->value;
65  public const CMD_PROCESS_UNZIP = 'processUnzip';
66  public const CMD_RENDER_DELETE_SELECTED_VERSIONS_MODAL = 'renderDeleteSelectedVersionsModal';
67  public const CMD_PUBLISH = 'publish';
68  public const CMD_UNPUBLISH = 'unpublish';
69 
71  private \ILIAS\ResourceStorage\Services $storage;
74  protected \ILIAS\DI\UIServices $ui;
76  private \ilWorkspaceAccessHandler $wsp_access;
77  private int $ref_id;
78  protected ilLanguage $lng;
79  private Services $http;
80  private ilTabsGUI $tabs;
81  protected ilCtrl $ctrl;
85  protected ?int $version_id = null;
86  protected ilTree $tree;
87  protected int $parent_id;
88  protected Refinery $refinery;
90 
94  public function __construct(private ilObjFile $file)
95  {
96  global $DIC;
97  $this->ctrl = $DIC->ctrl();
98  $this->tpl = $DIC->ui()->mainTemplate();
99  $this->tabs = $DIC->tabs();
100  $this->http = $DIC->http();
101  $this->lng = $DIC->language();
102  $this->ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $DIC->refinery()->kindlyTo()->int());
103  $this->toolbar = $DIC->toolbar();
104  $this->access = $DIC->access();
105  $this->storage = $DIC->resourceStorage();
106  $this->file_service_settings = $DIC->fileServiceSettings();
107  $this->ui = $DIC->ui();
108  $this->tree = $this->isWorkspaceContext() ? new ilWorkspaceTree($DIC->user()->getId()) : $DIC->repositoryTree();
109  $this->file_component_builder = new ilObjFileComponentBuilder($this->lng, $this->ui);
110  $this->refinery = $DIC->refinery();
111  $this->lom_services = $DIC->learningObjectMetadata();
112 
113  $this->parent_id = $this->tree->getParentId($this->file->getRefId()) ?? $this->getParentIdType();
114  $this->wsp_access = new ilWorkspaceAccessHandler($this->tree);
115  $this->version_id = $this->http->wrapper()->query()->has(self::HIST_ID)
116  ? $this->http->wrapper()->query()->retrieve(self::HIST_ID, $DIC->refinery()->kindlyTo()->int())
117  : null;
118  $this->action_repo = new ActionDBRepository($DIC->database());
119  $this->current_revision = $this->getCurrentFileRevision();
120  }
121 
122 
123 
128  protected function performCommand(): void
129  {
130  match ($this->ctrl->getCmd(self::CMD_DEFAULT)) {
131  self::CMD_DEFAULT => $this->index(),
132  self::CMD_DOWNLOAD_VERSION => $this->downloadVersion(),
133  self::CMD_DELETE_VERSIONS => $this->deleteVersions(),
134  self::CMD_ROLLBACK_VERSION => $this->rollbackVersion(),
135  self::CMD_ADD_NEW_VERSION => $this->addVersion(ilFileVersionFormGUI::MODE_ADD),
136  self::CMD_ADD_REPLACING_VERSION => $this->addVersion(ilFileVersionFormGUI::MODE_REPLACE),
137  self::CMD_CREATE_NEW_VERSION => $this->saveVersion(ilFileVersionFormGUI::MODE_ADD),
138  self::CMD_CREATE_REPLACING_VERSION => $this->saveVersion(ilFileVersionFormGUI::MODE_REPLACE),
139  self::CMD_CONFIRMED_DELETE_VERSIONS => $this->confirmDeleteVersions(),
140  self::CMD_CONFIRMED_DELETE_FILE => $this->confirmDeleteFile(),
141  self::CMD_UNZIP_CURRENT_REVISION => $this->unzipCurrentRevision(),
142  self::CMD_PROCESS_UNZIP => $this->processUnzip(),
143  self::CMD_RENDER_DELETE_SELECTED_VERSIONS_MODAL => $this->renderDeleteSelectedVersionsModal(),
144  self::CMD_PUBLISH => $this->publish(),
145  self::CMD_UNPUBLISH => $this->unpublish()
146  };
147  }
148 
152  protected function setBackTab(): void
153  {
154  $this->tabs->clearTargets();
155  $this->tabs->setBackTarget(
156  $this->lng->txt('back'),
157  $this->ctrl->getLinkTarget($this, self::CMD_DEFAULT)
158  );
159  }
160 
161  public function executeCommand(): void
162  {
163  // bugfix mantis 26007: use new function hasPermission to ensure that the check also works for workspace files
164  if (!$this->hasPermission('write')) {
165  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
166  $this->ctrl->returnToParent($this);
167  }
168  switch ($this->ctrl->getNextClass()) {
169  case strtolower(ilFileVersionsUploadHandlerGUI::class):
170  $this->ctrl->forwardCommand(
172  $this->file
173  )
174  );
175  return;
176  case strtolower(ilWOPIEmbeddedApplicationGUI::class):
177  $action = $this->action_repo->getEditActionForSuffix(
178  $this->current_revision->getInformation()->getSuffix()
179  );
180 
181  $embeded_application = new EmbeddedApplication(
182  $this->current_revision->getIdentification(),
183  $action,
184  new ilObjFileStakeholder(),
185  new URI(rtrim(ILIAS_HTTP_PATH, "/") . "/" . $this->ctrl->getLinkTarget($this, self::CMD_DEFAULT))
186  );
187 
188  $this->ctrl->forwardCommand(
190  $embeded_application
191  )
192  );
193  break;
194  default:
195  $this->performCommand();
196  break;
197  }
198  }
199 
200  private function unzipCurrentRevision(): void
201  {
202  $this->setBackTab();
203  $this->tpl->setContent(
204  $this->ui->renderer()->render(
205  $this->getFileZipOptionsForm()
206  )
207  );
208  }
209 
210  private function publish(): void
211  {
212  $this->file->enableNotification();
213  $this->storage->manage()->publish($this->getIdentification());
214  $this->file->updateObjectFromCurrentRevision();
215  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
216  $this->ctrl->redirect($this, self::CMD_DEFAULT);
217  }
218 
219  private function unpublish(): void
220  {
221  $this->file->enableNotification();
222  if ($this->current_revision->getVersionNumber() === 1) {
223  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_cant_unpublish'), true);
224  $this->ctrl->redirect($this, self::CMD_DEFAULT);
225  }
226 
227  $this->storage->manage()->unpublish($this->getIdentification());
228  $this->file->updateObjectFromCurrentRevision();
229  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
230  $this->ctrl->redirect($this, self::CMD_DEFAULT);
231  }
232 
233  private function processUnzip(): void
234  {
235  $form = $this->getFileZipOptionsForm()->withRequest($this->http->request());
236  $data = $form->getData();
237 
238  if (!empty($data)) {
239  $file_rid = $this->storage->manage()->find($data[self::KEY_FILE_RID]);
240  if (null !== $file_rid) {
241  $copyright_id = $data[self::KEY_COPYRIGHT_OPTION][1][self::KEY_COPYRIGHT_ID] ?? null;
242  $processor = $this->getFileProcessor($data[self::KEY_FILE_STRUCTURE]);
243  $processor->process($file_rid, null, null, $copyright_id);
244 
245  if ($processor->getInvalidFileNames() !== []) {
246  $this->ui->mainTemplate()->setOnScreenMessage(
247  'info',
248  sprintf(
249  $this->lng->txt('file_upload_info_file_with_critical_extension'),
250  implode(', ', $processor->getInvalidFileNames())
251  ),
252  true
253  );
254  }
255 
256  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_unzip_success'), true);
257  $this->ctrl->setParameterByClass(ilRepositoryGUI::class, "ref_id", $this->parent_id);
258  $this->ctrl->redirectByClass(ilRepositoryGUI::class);
259  }
260 
261  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('file_not_found'));
262  }
263 
264  $this->tpl->setContent(
265  $this->ui->renderer()->render(
266  $this->getFileZipOptionsForm()
267  )
268  );
269  }
270 
271  private function index(): void
272  {
273  // Buttons
274  $status = $this->current_revision?->getStatus();
275 
276  $btn_add_version = $this->ui->factory()->button()->standard(
277  $this->lng->txt('file_new_version'),
278  $this->ctrl->getLinkTarget($this, self::CMD_ADD_NEW_VERSION)
279  );
280  if ($status === RevisionStatus::DRAFT) {
281  $btn_add_version = $btn_add_version->withUnavailableAction();
282  }
283  $this->toolbar->addComponent($btn_add_version);
284 
285  $btn_replace_version = $this->ui->factory()->button()->standard(
286  $this->lng->txt('replace_file'),
287  $this->ctrl->getLinkTarget($this, self::CMD_ADD_REPLACING_VERSION)
288  );
289  if ($status === RevisionStatus::DRAFT) {
290  $btn_replace_version = $btn_replace_version->withUnavailableAction();
291  }
292  $this->toolbar->addComponent($btn_replace_version);
293 
294  // only add unzip button if the current revision is a zip.
295  if (null !== $this->current_revision &&
296  in_array($this->current_revision->getInformation()->getMimeType(), [MimeType::APPLICATION__ZIP, MimeType::APPLICATION__X_ZIP_COMPRESSED], true)
297  ) {
298  $btn_unzip = $this->ui->factory()->button()->standard(
299  $this->lng->txt('unzip'),
300  $this->ctrl->getLinkTarget($this, self::CMD_UNZIP_CURRENT_REVISION)
301  );
302  $this->toolbar->addComponent($btn_unzip);
303  }
304 
305  // Editor
306  $suffix = $this->current_revision?->getInformation()?->getSuffix();
307 
308  if ($this->action_repo->hasEditActionForSuffix(
309  $this->current_revision->getInformation()->getSuffix()
310  )) {
311  $external_editor = $this->ui->factory()
312  ->button()
313  ->standard(
314  $this->lng->txt('open_external_editor'),
315  $this->ctrl->getLinkTargetByClass(
316  [self::class, ilWOPIEmbeddedApplicationGUI::class],
318  )
319  );
320  $this->toolbar->addComponent($external_editor);
321  }
322 
323 
324  // Publish
325  if ($status === RevisionStatus::DRAFT) {
326  $this->tpl->setOnScreenMessage('info', $this->lng->txt('file_version_draft_info'));
327 
328  $btn_publish = $this->ui->factory()->button()->standard(
329  $this->lng->txt('file_publish'),
330  $this->ctrl->getLinkTarget($this, self::CMD_PUBLISH)
331  );
332  $this->toolbar->addComponent($btn_publish);
333  }
334 
335  $table = new ilFileVersionsTableGUI($this, self::CMD_DEFAULT);
336  $this->tpl->setContent($table->getHTML());
337  }
338 
339  private function addVersion(int $mode = ilFileVersionFormGUI::MODE_ADD): void
340  {
341  $this->setBackTab();
342 
343  $form = new ilFileVersionFormGUI($this, $mode);
344  $this->tpl->setContent($form->getHTML());
345  }
346 
351  private function saveVersion(int $mode = ilFileVersionFormGUI::MODE_ADD): void
352  {
353  $form = new ilFileVersionFormGUI($this, $mode);
354  if ($form->saveObject()) {
355  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
356  $this->ctrl->redirect($this, self::CMD_DEFAULT);
357  }
358  $this->tpl->setContent($form->getHTML());
359  }
360 
361  private function downloadVersion(): void
362  {
363  try {
364  $this->file->sendFile($this->version_id);
365  } catch (FileNotFoundException) {
366  }
367  }
368 
369  private function rollbackVersion(): void
370  {
371  $version_ids = $this->getVersionIdsFromRequest();
372 
373  // more than one entry selected?
374  if (count($version_ids) !== 1) {
375  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("file_rollback_select_exact_one"), true);
376  $this->ctrl->redirect($this, self::CMD_DEFAULT);
377  }
378 
379  if ($this->current_revision->getStatus() === RevisionStatus::DRAFT) {
380  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("file_rollback_rollback_first"), true);
381  $this->ctrl->redirect($this, self::CMD_DEFAULT);
382  }
383 
384  // rollback the version
385  $version_id = $version_ids[0];
386  if ($version_id === $this->current_revision->getVersionNumber()) {
387  $this->tpl->setOnScreenMessage('info', $this->lng->txt("file_rollback_same_version"), true);
388  $this->ctrl->redirect($this, self::CMD_DEFAULT);
389  }
390 
391  $this->file->rollback($version_id);
392 
393  $this->tpl->setOnScreenMessage('success', sprintf($this->lng->txt("file_rollback_done"), (string) $version_id), true);
394  $this->ctrl->redirect($this, self::CMD_DEFAULT);
395  }
396 
397  private function confirmDeleteVersions(): void
398  {
399  // delete versions after confirmation
400  $versions_to_delete = $this->getVersionIdsFromRequest();
401  if (is_array($versions_to_delete) && $versions_to_delete !== []) {
402  $this->file->deleteVersions($versions_to_delete);
403  $this->tpl->setOnScreenMessage('success', $this->lng->txt("file_versions_deleted"), true);
404  }
405 
406  $this->ctrl->setParameter($this, self::HIST_ID, "");
407  $this->ctrl->redirect($this, self::CMD_DEFAULT);
408  }
409 
410  private function confirmDeleteFile(): void
411  {
412  $parent_id = $this->tree->getParentId($this->ref_id);
413 
414  ilRepUtil::deleteObjects($parent_id, [$this->ref_id]);
415 
416  // redirect to parent object
417  $this->ctrl->setParameterByClass(ilRepositoryGUI::class, "ref_id", $parent_id);
418  $this->ctrl->redirectByClass(ilRepositoryGUI::class);
419  }
420 
421  public function getFile(): ilObjFile
422  {
423  return $this->file;
424  }
425 
426  private function getVersionIdsFromRequest(): array
427  {
428  if ('GET' === $this->http->request()->getMethod() &&
429  $this->http->wrapper()->query()->has(self::HIST_ID)
430  ) {
431  return [
432  $this->http->wrapper()->query()->retrieve(self::HIST_ID, $this->refinery->kindlyTo()->int()),
433  ];
434  }
435 
437  if ($this->http->wrapper()->post()->has('interruptive_items')) {
438  return $this->http->wrapper()->post()->retrieve(
439  'interruptive_items',
440  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
441  );
442  }
443 
444  if ($this->http->wrapper()->post()->has(self::HIST_ID)) {
445  return $this->http->wrapper()->post()->retrieve(
446  self::HIST_ID,
447  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
448  );
449  }
450 
451  return [];
452  }
453 
454  private function getVersionsToKeep(array $version_ids): array
455  {
456  $versions_to_keep = $this->file->getVersions();
457  array_udiff($versions_to_keep, $version_ids, static function ($v1, $v2): bool {
458  if (is_array($v1) || $v1 instanceof ilObjFileVersion) {
459  $v1 = (int) $v1["hist_entry_id"];
460  } elseif (!is_numeric($v1)) {
461  $v1 = (int) $v1;
462  }
463 
464  if (is_array($v2) || $v2 instanceof ilObjFileVersion) {
465  $v2 = (int) $v2["hist_entry_id"];
466  } elseif (!is_numeric($v2)) {
467  $v2 = (int) $v2;
468  }
469 
470  return $v1 === $v2;
471  });
472 
473  return $versions_to_keep;
474  }
475 
481  private function hasPermission(string $a_permission): bool
482  {
483  // determine if the permission check concerns a workspace- or repository-object
484  if ($this->isWorkspaceContext()) {
485  // permission-check concerning a workspace object
486  if ($this->wsp_access->checkAccess($a_permission, "", $this->ref_id)) {
487  return true;
488  }
489  } elseif ($this->access->checkAccess($a_permission, '', $this->ref_id)) {
490  // permission-check concerning a repository object
491  return true;
492  }
493 
494  return false;
495  }
496 
497  protected function renderDeleteSelectedVersionsModal(): void
498  {
499  $delete_selected_versions_modal = $this->getDeleteSelectedVersionsModal();
500 
501  $this->http->saveResponse(
502  $this->http->response()->withBody(
503  \ILIAS\Filesystem\Stream\Streams::ofString(
504  (null !== $delete_selected_versions_modal) ?
505  $this->ui->renderer()->renderAsync([$delete_selected_versions_modal]) :
506  ''
507  )
508  )->withHeader('Content-Type', 'application/json; charset=utf-8')
509  );
510 
511  $this->http->sendResponse();
512  $this->http->close();
513  }
514 
516  {
517  $deletion_version_ids = $this->getVersionIdsFromRequest();
518  $existing_versions = $this->file->getVersions();
519 
520  $non_deletion_versions = array_udiff(
521  $existing_versions,
522  $deletion_version_ids,
523  static function ($a, $b) {
524  if ($a instanceof ilObjFileVersion) {
525  $a = $a->getHistEntryId();
526  }
527  if ($b instanceof ilObjFileVersion) {
528  $b = $b->getHistEntryId();
529  }
530  return $a - $b;
531  }
532  );
533  $this->checkSanityOfDeletionRequest($deletion_version_ids, false);
534 
535  // no version will remain after deletion, so we can delete the whole file
536  if (count($non_deletion_versions) < 1) {
537  return $this->file_component_builder->buildConfirmDeleteAllVersionsModal(
538  $this->ctrl->getFormActionByClass(self::class, self::CMD_CONFIRMED_DELETE_FILE),
539  $this->file
540  );
541  }
542 
543  // confirm the deletion of the selected versions
544  if (count($non_deletion_versions) >= 1) {
545  return $this->file_component_builder->buildConfirmDeleteSpecificVersionsModal(
546  $this->ctrl->getFormActionByClass(self::class, self::CMD_CONFIRMED_DELETE_VERSIONS),
547  $this->file,
548  $deletion_version_ids
549  );
550  }
551  return null;
552  }
553 
554  protected function checkSanityOfDeletionRequest(array $requested_deletion_version, bool $redirect): void
555  {
556  // Check Sanity of request
557  // Cant delete version if current is a DRAFT
558  if (
559  $this->current_revision->getStatus() === RevisionStatus::DRAFT
560  ) {
561  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('publish_before_delete'), $redirect);
562  if ($redirect) {
563  $this->ctrl->redirect($this, self::CMD_DEFAULT);
564  }
565  }
566 
567  // no checkbox has been selected
568  if (count($requested_deletion_version) < 1) {
569  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), $redirect);
570  if ($redirect) {
571  $this->ctrl->redirect($this, self::CMD_DEFAULT);
572  }
573  }
574  }
575 
576  //TODO: Remove this function and replace its calls with calls to "getDeleteSelectedVersionsModal" as soon as the new table gui is introduced.
577  // This function and its deprecated ilConfirmationGUI are only needed because the old ilTable2GUI doesn't support calling modals from its MultiCommands
578  private function deleteVersions(): void
579  {
580  $version_ids = $this->getVersionIdsFromRequest();
581  $existing_versions = $this->file->getVersions();
582  $remaining_versions = array_udiff(
583  $existing_versions,
584  $version_ids,
585  static function ($a, $b) {
586  if ($a instanceof ilObjFileVersion) {
587  $a = $a->getHistEntryId();
588  }
589  if ($b instanceof ilObjFileVersion) {
590  $b = $b->getHistEntryId();
591  }
592  return $a - $b;
593  }
594  );
595 
596  $this->checkSanityOfDeletionRequest($version_ids, true);
597 
598  $conf_gui = new ilConfirmationGUI();
599  $conf_gui->setFormAction($this->ctrl->getFormAction($this, self::CMD_DEFAULT));
600  $conf_gui->setCancel($this->lng->txt("cancel"), self::CMD_DEFAULT);
601 
602  $icon = ilObject::_getIcon($this->file->getId(), "small", $this->file->getType());
603  $alt = $this->lng->txt("icon") . " " . $this->lng->txt("obj_" . $this->file->getType());
604 
605  // only one version left, delete the whole file
606  if (count($remaining_versions) < 1) {
607  // Ask
608  $conf_gui->setHeaderText($this->lng->txt('file_confirm_delete_all_versions'));
609  $conf_gui->setConfirm($this->lng->txt("confirm"), self::CMD_CONFIRMED_DELETE_FILE);
610  $conf_gui->addItem(
611  "id[]",
612  $this->ref_id,
613  $this->file->getTitle(),
614  $icon,
615  $alt
616  );
617  } else {
618  // Ask to delete version
619  $conf_gui->setHeaderText($this->lng->txt('file_confirm_delete_versions'));
620  $conf_gui->setConfirm($this->lng->txt("confirm"), self::CMD_CONFIRMED_DELETE_VERSIONS);
621 
622  foreach ($this->file->getVersions($version_ids) as $version) {
623  $a_text = $version['filename'] ?? $version->getFilename() ?? $this->file->getTitle();
624  $version_string = $version['hist_id'] ?? $version->getVersion();
625  $a_text .= " (v" . $version_string . ")";
626  $conf_gui->addItem(
627  "hist_id[]",
628  $version['hist_entry_id'],
629  $a_text,
630  $icon,
631  $alt
632  );
633  }
634  }
635 
636  $this->tpl->setContent($conf_gui->getHTML());
637  }
638 
639  private function getFileZipOptionsForm(): Form
640  {
641  $inputs = [];
642  $copyright_options = [];
643  $form_action = $this->ctrl->getFormActionByClass(self::class, self::CMD_PROCESS_UNZIP);
644 
645  $inputs[self::KEY_FILE_RID] = $this->ui->factory()->input()->field()->hidden()->withValue(
646  $this->file->getResourceId()
647  );
648  $inputs[self::KEY_FILE_STRUCTURE] = $this->ui->factory()->input()->field()->checkbox(
649  $this->lng->txt('take_over_structure'),
650  $this->lng->txt('take_over_structure_info'),
651  );
652 
653  if (!$this->lom_services->copyrightHelper()->isCopyrightSelectionActive()) {
654  return $this->ui->factory()->input()->container()->form()->standard($form_action, $inputs);
655  }
656 
657  $lom_reader = $this->lom_services->read($this->file->getId(), 0, $this->file->getType());
658  $lom_cp_helper = $this->lom_services->copyrightHelper();
659 
660  if ($lom_cp_helper->hasPresetCopyright($lom_reader)) {
661  $zip_copyright = $lom_cp_helper->readPresetCopyright($lom_reader);
662  $zip_copyright_id = $zip_copyright->identifier();
663  $zip_copyright_title = $zip_copyright->title();
664  } else {
665  $zip_copyright_id = $zip_copyright_title = $lom_cp_helper->readCustomCopyright($lom_reader);
666  }
667  if ($zip_copyright_id !== '') {
668  $copyright_inheritance_input = $this->ui->factory()->input()->field()->hidden()->withValue(
669  $zip_copyright_id
670  );
671  $copyright_options[self::KEY_INHERIT_COPYRIGHT] = $this->ui->factory()->input()->field()->group(
672  [self::KEY_COPYRIGHT_ID => $copyright_inheritance_input],
673  $this->lng->txt("copyright_inherited"),
674  sprintf(
675  $this->lng->txt("copyright_inherited_info"),
676  $zip_copyright_title
677  )
678  );
679  }
680 
681  $copyright_selection_input = $this->getCopyrightSelectionInput('set_license_for_all_files');
682  $copyright_options[self::KEY_SELECT_COPYRIGHT] = $this->ui->factory()->input()->field()->group(
683  [self::KEY_COPYRIGHT_ID => $copyright_selection_input],
684  $this->lng->txt("copyright_custom"),
685  $this->lng->txt("copyright_custom_info")
686  );
687 
688  $inputs[self::KEY_COPYRIGHT_OPTION] = $this->ui->factory()->input()->field()->switchableGroup(
689  $copyright_options,
690  $this->lng->txt("md_copyright")
691  )->withValue(self::KEY_SELECT_COPYRIGHT);
692 
693  return $this->ui->factory()->input()->container()->form()->standard($form_action, $inputs);
694  }
695 
696  private function getFileProcessor(bool $keep_structure): ilObjFileProcessorInterface
697  {
698  $context = $this->getParentIdType();
699 
700  if ($keep_structure) {
702  new ilObjFileStakeholder(),
703  new ilObjFileGUI(
704  $this->file->getId(),
705  $context,
707  ),
708  $this->storage,
709  $this->file_service_settings,
710  $this->tree
711  );
712  }
713 
714  return new ilObjFileUnzipFlatProcessor(
715  new ilObjFileStakeholder(),
716  new ilObjFileGUI(
717  $this->file->getId(),
718  $context,
720  ),
721  $this->storage,
722  $this->file_service_settings,
723  $this->tree
724  );
725  }
726 
727  private function getIdentification(): ?\ILIAS\ResourceStorage\Identification\ResourceIdentification
728  {
729  return $this->storage->manage()->find($this->file->getResourceId());
730  }
731 
732  private function getCurrentFileRevision(): ?Revision
733  {
734  $file_rid = $this->getIdentification();
735  if (null !== $file_rid) {
736  return $this->storage->manage()->getCurrentRevisionIncludingDraft($file_rid);
737  }
738 
739  return null;
740  }
741 
742  private function getParentIdType(): int
743  {
744  return ($this->isWorkspaceContext()) ?
747  }
748 
749  private function isWorkspaceContext(): bool
750  {
751  return $this->http->wrapper()->query()->has('wsp_id');
752  }
753 
754  protected function getUIFactory(): ILIAS\UI\Factory
755  {
756  return $this->ui->factory();
757  }
758 
759  protected function getLanguage(): \ilLanguage
760  {
761  return $this->lng;
762  }
763 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFileStakeholder.
This describes commonalities between all forms.
Definition: Form.php:32
trait ilObjFileCopyrightInput
$context
Definition: webdav.php:31
__construct(private ilObjFile $file)
ilFileVersionsGUI constructor.
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
$version
Definition: plugin.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilObjFileProcessorInterface.
saveVersion(int $mode=ilFileVersionFormGUI::MODE_ADD)
Class ilFileVersionFormGUI.
Interface Observer Contains several chained tasks and infos about them.
static deleteObjects(int $a_cur_ref_id, array $a_ids)
Delete objects.
ILIAS DI UIServices $ui
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS ResourceStorage Services $storage
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
ilWorkspaceAccessHandler $wsp_access
hasPermission(string $a_permission)
bugfix mantis 26007: this function was created to ensure that the access check not only works for rep...
addVersion(int $mode=ilFileVersionFormGUI::MODE_ADD)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilFileVersionsUploadHandlerGUI.
ilObjFileComponentBuilder $file_component_builder
Class ilFileVersionsTableGUI.
Class ilObjFile.
global $DIC
Definition: shib_login.php:25
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34
ActionTarget
Officialy supported action targets, see https://learn.microsoft.com/en-us/openspecs/office_protocols/...
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
getVersionsToKeep(array $version_ids)
GUI class for file objects.
ActionRepository $action_repo
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
ilFileServicesSettings $file_service_settings
Indicates that a file is missing or not found.
getFileProcessor(bool $keep_structure)
Class ilObjFileUnzipRecursiveProcessor.
checkSanityOfDeletionRequest(array $requested_deletion_version, bool $redirect)
Class ilObjFileUnzipFlatProcessor.