ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ExportOptionBase.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Export\HTML;
22 
23 use ilCtrl;
24 use ilExport;
25 use ilFileDelivery;
26 use ilFileUtils;
30 use ILIAS\Export\ExportHandler\Consumer\ExportOption\BasicHandler as ilExportHandlerConsumerBasicExportOption;
31 use ILIAS\Export\ExportHandler\I\Consumer\Context\HandlerInterface as ilExportHandlerConsumerContextInterface;
32 use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\CollectionInterface as ilExportHandlerConsumerFileIdentifierCollectionInterface;
33 use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\HandlerInterface as ilExportHandlerConsumerFileIdentifierInterface;
34 use ILIAS\Export\ExportHandler\I\Info\File\CollectionInterface as ilExportHandlerFileInfoCollectionInterface;
35 use ilObject;
36 use SplFileInfo;
37 
38 abstract class ExportOptionBase extends ilExportHandlerConsumerBasicExportOption
39 {
40  protected \ilExportHTMLStakeholder $stakeholder;
42  protected ilCtrl $ctrl;
44 
45  public function init(Container $DIC): void
46  {
47  $this->ctrl = $DIC->ctrl();
48  $this->data_factory = new ilDataFactory();
49  $this->repo = $DIC->export()->internal()->repo()->html()->exportFile();
50  $this->stakeholder = new \ilExportHTMLStakeholder();
51  }
52 
53  public function onDeleteFiles(
54  ilExportHandlerConsumerContextInterface $context,
55  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
56  ): void {
57  foreach ($file_identifiers as $file_identifier) {
58  $rid = $file_identifier->getIdentifier();
59  $this->repo->delete(
60  $context->exportObject()->getId(),
61  $rid
62  );
63  }
64  }
65 
66  public function onDownloadFiles(
67  ilExportHandlerConsumerContextInterface $context,
68  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
69  ): void {
70  foreach ($file_identifiers as $file_identifier) {
71  $rid = $file_identifier->getIdentifier();
72  $this->repo->deliverFile($rid);
73  }
74  }
75 
76  public function onDownloadWithLink(
77  ReferenceId $reference_id,
78  ilExportHandlerConsumerFileIdentifierInterface $file_identifier
79  ): void {
80  $rid = $file_identifier->getIdentifier();
81  $this->repo->deliverFile($rid);
82  exit;
83  }
84 
85  public function getFileSelection(
86  ilExportHandlerConsumerContextInterface $context,
87  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
88  ): ilExportHandlerFileInfoCollectionInterface {
89  $collection_builder = $context->fileCollectionBuilder();
90  $file_identifiers_array = $file_identifiers->toStringArray();
91  foreach ($this->getFiles($context) as $file) {
92  if (in_array($file->getFileIdentifier(), $file_identifiers_array)) {
93  $collection_builder = $collection_builder->withFileInfo($file);
94  }
95  }
96  return $collection_builder->collection();
97  }
98 
99  public function getFiles(
100  ilExportHandlerConsumerContextInterface $context
101  ): ilExportHandlerFileInfoCollectionInterface {
102  $collection_builder = $context->fileCollectionBuilder();
103  $object_id = $this->data_factory->objId($context->exportObject()->getId());
104  foreach ($this->repo->getAllOfObjectId($context->exportObject()->getId()) as $file) {
105  $collection_builder = $collection_builder->withResourceIdentifier(
106  $this->repo->getResourceIdForIdString($file->getRid()),
107  $object_id,
108  $this
109  );
110  }
111  return $collection_builder->collection();
112  }
113 }
$context
Definition: webdav.php:31
getFileSelection(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
getFiles(ilExportHandlerConsumerContextInterface $context)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26
onDownloadWithLink(ReferenceId $reference_id, ilExportHandlerConsumerFileIdentifierInterface $file_identifier)
onDeleteFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
onDownloadFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
exit