ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BasicLegacyHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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 BasicLegacyHandler extends ilExportHandlerConsumerBasicExportOption
39{
40 protected ilCtrl $ctrl;
41 protected ilDataFactory $data_factory;
42
43 public function init(Container $DIC): void
44 {
45 $this->ctrl = $DIC->ctrl();
46 $this->data_factory = new ilDataFactory();
47 }
48
49 public function onDeleteFiles(
50 ilExportHandlerConsumerContextInterface $context,
51 ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
52 ): void {
53 foreach ($file_identifiers as $file_identifier) {
54 $file = explode(":", $file_identifier->getIdentifier());
55 $file[1] = basename($file[1]);
57 $context->exportObject()->getId(),
58 str_replace("..", "", $file[0]),
59 $context->exportObject()->getType()
60 );
61 $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]);
62 $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4);
63 if (is_file($exp_file)) {
64 unlink($exp_file);
65 }
66 if (
67 is_dir($exp_dir) and
68 count(scandir($exp_dir)) === 2
69 ) {
70 ilFileUtils::delDir($exp_dir);
71 }
72 }
73 }
74
75 public function onDownloadFiles(
76 ilExportHandlerConsumerContextInterface $context,
77 ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
78 ): void {
79 foreach ($file_identifiers as $file_identifier) {
80 $file = explode(":", trim($file_identifier->getIdentifier()));
82 $context->exportObject()->getId(),
83 str_replace("..", "", $file[0]),
84 $context->exportObject()->getType()
85 );
86 $file[1] = basename($file[1]);
88 $export_dir . "/" . $file[1],
89 $file[1]
90 );
91 }
92 }
93
94 public function onDownloadWithLink(
95 ReferenceId $reference_id,
96 ilExportHandlerConsumerFileIdentifierInterface $file_identifier
97 ): void {
98 $object_id = $reference_id->toObjectId()->toInt();
99 $type = ilObject::_lookupType($object_id);
100 $file = explode(":", trim($file_identifier->getIdentifier()));
101 $export_dir = ilExport::_getExportDirectory(
102 $object_id,
103 str_replace("..", "", $file[0]),
104 $type
105 );
106 $file[1] = basename($file[1]);
108 $export_dir . "/" . $file[1],
109 $file[1]
110 );
111 }
112
113 public function getFileSelection(
114 ilExportHandlerConsumerContextInterface $context,
115 ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
116 ): ilExportHandlerFileInfoCollectionInterface {
117 $collection_builder = $context->fileCollectionBuilder();
118 $file_identifiers_array = $file_identifiers->toStringArray();
119 foreach ($this->getFiles($context) as $file) {
120 if (in_array($file->getFileIdentifier(), $file_identifiers_array)) {
121 $collection_builder = $collection_builder->withFileInfo($file);
122 }
123 }
124 return $collection_builder->collection();
125 }
126
127 public function getFiles(
128 ilExportHandlerConsumerContextInterface $context
129 ): ilExportHandlerFileInfoCollectionInterface {
130 $collection_builder = $context->fileCollectionBuilder();
132 $context->exportObject()->getId(),
133 $this->getExportType(),
134 $context->exportObject()->getType()
135 );
136 $file_infos = ilExport::_getExportFiles(
137 $context->exportObject()->getId(),
138 [$this->getExportType()],
139 $context->exportObject()->getType()
140 );
141 $object_id = $this->data_factory->objId($context->exportObject()->getId());
142 foreach ($file_infos as $file_name => $file_info) {
143 $collection_builder = $collection_builder->withSPLFileInfo(
144 new SplFileInfo($dir . DIRECTORY_SEPARATOR . $file_info["file"]),
145 $object_id,
146 $this
147 );
148 }
149 return $collection_builder->collection();
150 }
151}
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
onDownloadWithLink(ReferenceId $reference_id, ilExportHandlerConsumerFileIdentifierInterface $file_identifier)
onDownloadFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
getFileSelection(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
onDeleteFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
getFiles(ilExportHandlerConsumerContextInterface $context)
Class ilCtrl provides processing control methods.
static _getExportFiles(int $a_obj_id, $a_export_types="", string $a_obj_type="")
@depricated
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
@depricated Get export directory for an repository object
Class ilFileDelivery.
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
Class ilFileUtils.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
global $DIC
Definition: shib_login.php:26
$context
Definition: webdav.php:31