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