ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ExportOptionBase.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Export\HTML;
22
23use ilCtrl;
24use ilExport;
26use ilFileUtils;
27use ILIAS\Data\Factory as ilDataFactory;
30use ILIAS\Export\ExportHandler\Consumer\ExportOption\BasicHandler as ilExportHandlerConsumerBasicExportOption;
31use ILIAS\Export\ExportHandler\I\Consumer\Context\HandlerInterface as ilExportHandlerConsumerContextInterface;
32use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\CollectionInterface as ilExportHandlerConsumerFileIdentifierCollectionInterface;
33use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\HandlerInterface as ilExportHandlerConsumerFileIdentifierInterface;
34use ILIAS\Export\ExportHandler\I\Info\File\CollectionInterface as ilExportHandlerFileInfoCollectionInterface;
35use ilObject;
36use SplFileInfo;
37
38abstract class ExportOptionBase extends ilExportHandlerConsumerBasicExportOption
39{
40 protected \ilExportHTMLStakeholder $stakeholder;
42 protected ilCtrl $ctrl;
43 protected ilDataFactory $data_factory;
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}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
ctrl()
Get the interface to the control structure.
Definition: Container.php:63
Builds data types.
Definition: Factory.php:36
getFiles(ilExportHandlerConsumerContextInterface $context)
onDownloadWithLink(ReferenceId $reference_id, ilExportHandlerConsumerFileIdentifierInterface $file_identifier)
getFileSelection(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
onDownloadFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
onDeleteFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
ilExportHTMLStakeholder $stakeholder
Class ilCtrl provides processing control methods.
Class ilFileDelivery.
Class ilFileUtils.
Class ilObject Basic functions for all objects.
exit
global $DIC
Definition: shib_login.php:26
$context
Definition: webdav.php:31