ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDataCollectionExportOptionsXLSX.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Export\ExportHandler\I\Consumer\Context\HandlerInterface as ilExportHandlerConsumerContextInterface;
23use ILIAS\Export\ExportHandler\I\Info\File\CollectionInterface as ilExportHandlerFileInfoCollectionInterface;
24use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\CollectionInterface as ilExportHandlerConsumerFileIdentifierCollectionInterface;
27
28class ilDataCollectionExportOptionsXLSX extends ilBasicLegacyExportOption
29{
30 protected ilLanguage $lng;
32
33 public function init(Container $DIC): void
34 {
35 $this->lng = $DIC->language();
36 $this->tpl = $DIC->ui()->mainTemplate();
38 }
39
40 public function getExportType(): string
41 {
42 return 'xlsx';
43 }
44
45 public function getExportOptionId(): string
46 {
47 return 'dcl_exp_option_xlsx';
48 }
49
50 public function getSupportedRepositoryObjectTypes(): array
51 {
52 return ['dcl'];
53 }
54
55 public function getLabel(): string
56 {
57 return $this->lng->txt('dcl_xls_async_export');
58 }
59
60 public function getFiles(
61 ilExportHandlerConsumerContextInterface $context
62 ): ilExportHandlerFileInfoCollectionInterface {
63 $collection_builder = $context->fileCollectionBuilder();
65 $context->exportObject()->getId(),
66 $this->getExportType(),
67 $context->exportObject()->getType()
68 );
69 $file_infos = $this->getExportFiles($dir);
70 $object_id = new ObjectId($context->exportObject()->getId());
71 foreach ($file_infos as $file_name => $file_info) {
72 $collection_builder = $collection_builder->withSPLFileInfo(
73 new SplFileInfo($dir . DIRECTORY_SEPARATOR . $file_info["file"]),
74 $object_id,
75 $this
76 );
77 }
78 return $collection_builder->collection();
79 }
80
81 public function onExportOptionSelected(
82 ilExportHandlerConsumerContextInterface $context
83 ): void {
84 if (!$this->checkForExportableFields($context) || !$this->checkForAsyncEnabled($context)) {
85 return;
86 }
87 $this->ctrl->redirectByClass(ilObjDataCollectionGUI::class, "handleExportAsync");
88 }
89
90 public function onDeleteFiles(
91 ilExportHandlerConsumerContextInterface $context,
92 ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
93 ): void {
94 foreach ($file_identifiers as $file_identifier) {
95 $file = explode(":", $file_identifier->getIdentifier());
96 $file[1] = basename($file[1]);
98 $context->exportObject()->getId(),
99 str_replace("..", "", $file[0]),
100 $context->exportObject()->getType()
101 );
102 $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]);
103 $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 5);
104 if (is_file($exp_file)) {
105 unlink($exp_file);
106 }
107 if (
108 is_dir($exp_dir) and
109 count(scandir($exp_dir)) === 2
110 ) {
111 ilFileUtils::delDir($exp_dir);
112 }
113 }
114 }
115
116 protected function getExportFiles(
117 string $directory
118 ): array {
119 $file = [];
120 try {
121 $h_dir = dir($directory);
122 while ($entry = $h_dir->read()) {
123 if (
124 $entry !== "." &&
125 $entry !== ".." &&
126 substr($entry, -5) === "." . $this->getExportType()
127 ) {
128 $ts = substr($entry, 0, strpos($entry, "__"));
129 $file[$entry . $this->getExportType()] = [
130 "type" => $this->getExportType(),
131 "file" => $entry,
132 "size" => (int) filesize($directory . "/" . $entry),
133 "timestamp" => (int) $ts
134 ];
135 }
136 }
137 } catch (Exception $e) {
138 }
139 return $file;
140 }
141
142 protected function checkForExportableFields(
143 ilExportHandlerConsumerContextInterface $context
144 ): bool {
145 $obj = $context->exportObject();
146
147 foreach ($obj->getTables() as $tbl) {
149 foreach ($tbl->getFields() as $field) {
150 if ($field->getExportable()) {
151 return true;
152 }
153 }
154 }
155
156 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_no_export_data_available'), true);
157 $this->ctrl->redirect($context->exportGUIObject(), "listExportFiles");
158
159 return false;
160 }
161
162 protected function checkForAsyncEnabled(
163 ilExportHandlerConsumerContextInterface $context
164 ): bool {
165 global $DIC;
166 if ($DIC->settings()->get('soap_user_administration', '0') === '1') {
167 return true;
168 }
169
170 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_no_export_async_config'), true);
171 $this->ctrl->redirect($context->exportGUIObject(), "listExportFiles");
172
173 return false;
174 }
175}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
language()
Get interface to the i18n service.
Definition: Container.php:95
checkForAsyncEnabled(ilExportHandlerConsumerContextInterface $context)
getFiles(ilExportHandlerConsumerContextInterface $context)
onDeleteFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
onExportOptionSelected(ilExportHandlerConsumerContextInterface $context)
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
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
language handling
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$context
Definition: webdav.php:31