ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMediaPoolExportOptionXMLMaster.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 use ILIAS\Export\ExportHandler\I\Consumer\Context\HandlerInterface as ilExportHandlerConsumerContextInterface;
25 use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\CollectionInterface as ilExportHandlerConsumerFileIdentifierCollectionInterface;
26 use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\HandlerInterface as ilExportHandlerConsumerFileIdentifierInterface;
27 use ILIAS\Export\ExportHandler\I\Info\File\CollectionInterface as ilExportHandlerFileInfoCollectionInterface;
29 
30 class ilMediaPoolExportOptionXMLMaster extends ilBasicLegacyExportOption
31 {
32  protected ilLanguage $lng;
33 
34  public function init(Container $DIC): void
35  {
36  $this->lng = $DIC->language();
37  parent::init($DIC);
38  }
39 
40  public function getExportType(): string
41  {
42  return 'xml_master';
43  }
44 
45  public function getExportOptionId(): string
46  {
47  return 'mep_exp_option_xml_master';
48  }
49 
50  public function getSupportedRepositoryObjectTypes(): array
51  {
52  return ['mep'];
53  }
54 
55  public function getLabel(): string
56  {
57  $this->lng->loadLanguageModule('exp');
58  return $this->lng->txt("exp_format_dropdown-xml") . " (" . $this->lng->txt("mep_master_language_only") . ")";
59  }
60 
61  public function onDownloadFiles(
62  ilExportHandlerConsumerContextInterface $context,
63  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
64  ): void {
65  foreach ($file_identifiers as $file_identifier) {
66  $file = explode(":", trim($file_identifier->getIdentifier()));
67  $export_dir = ilExport::_getExportDirectory(
68  $context->exportObject()->getId(),
69  "",
70  $context->exportObject()->getType()
71  );
72  $export_dir = substr($export_dir, 0, strlen($export_dir) - 1);
73  $file[1] = basename($file[1]);
75  $export_dir . "/" . $file[1],
76  $file[1]
77  );
78  }
79  }
80 
81  public function onDownloadWithLink(
82  ReferenceId $reference_id,
83  ilExportHandlerConsumerFileIdentifierInterface $file_identifier
84  ): void {
85  $object_id = $reference_id->toObjectId()->toInt();
86  $type = ilObject::_lookupType($object_id);
87  $file = explode(":", trim($file_identifier->getIdentifier()));
88  $export_dir = ilExport::_getExportDirectory(
89  $object_id,
90  "",
91  $type
92  );
93  $export_dir = substr($export_dir, 0, strlen($export_dir) - 1);
94  $file[1] = basename($file[1]);
96  $export_dir . "/" . $file[1],
97  $file[1]
98  );
99  }
100 
101  public function onDeleteFiles(
102  ilExportHandlerConsumerContextInterface $context,
103  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
104  ): void {
105  foreach ($file_identifiers as $file_identifier) {
106  $file = explode(":", $file_identifier->getIdentifier());
107  $file[1] = basename($file[1]);
108  $export_dir = ilExport::_getExportDirectory(
109  $context->exportObject()->getId(),
110  "",
111  $context->exportObject()->getType()
112  );
113  $export_dir = substr($export_dir, 0, strlen($export_dir) - 1);
114  $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]);
115  $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4);
116  if (is_file($exp_file)) {
117  unlink($exp_file);
118  }
119  if (
120  is_dir($exp_dir) and
121  count(scandir($exp_dir)) === 2
122  ) {
123  ilFileUtils::delDir($exp_dir);
124  }
125  }
126  }
127 
128  public function getFiles(
129  ilExportHandlerConsumerContextInterface $context
130  ): \ILIAS\Export\ExportHandler\I\Info\File\CollectionInterface {
131  $collection_builder = $context->fileCollectionBuilder();
133  $context->exportObject()->getId(),
134  "",
135  $context->exportObject()->getType()
136  );
137  $dir = substr($dir, 0, strlen($dir) - 1);
138  $file_infos = $this->getExportFiles($dir);
139  $object_id = new ObjectId($context->exportObject()->getId());
140  foreach ($file_infos as $file_name => $file_info) {
141  $collection_builder = $collection_builder->withSPLFileInfo(
142  new SplFileInfo($dir . DIRECTORY_SEPARATOR . $file_info["file"]),
143  $object_id,
144  $this
145  );
146  }
147  return $collection_builder->collection();
148  }
149 
150  public function isObjectSupported(
151  ObjectId $object_id
152  ): bool {
153  $ot = ilObjectTranslation::getInstance($object_id->toInt());
154  return $ot->getContentActivated();
155  }
156 
157  public function onExportOptionSelected(
158  ilExportHandlerConsumerContextInterface $context
159  ): void {
160  if ($this->isObjectSupported(new ObjectId($context->exportObject()->getId()))) {
161  $opt = ilUtil::stripSlashes("master");
162  $context->exportObject()->exportXML($opt);
163  }
164  $this->ctrl->redirectByClass(ilExportGUI::class, ilExportGUI::CMD_LIST_EXPORT_FILES);
165  }
166 
167  protected function getExportFiles(
168  string $directory
169  ): array {
170  $file = [];
171  try {
172  $h_dir = dir($directory);
173  while ($entry = $h_dir->read()) {
174  if (
175  $entry !== "." &&
176  $entry !== ".." &&
177  substr($entry, - 4) === ".zip"
178  ) {
179  $ts = substr($entry, 0, strpos($entry, "__"));
180  $file[$entry . $this->getExportType()] = [
181  "type" => $this->getExportType(),
182  "file" => $entry,
183  "size" => (int) filesize($directory . "/" . $entry),
184  "timestamp" => (int) $ts
185  ];
186  }
187  }
188  } catch (Exception $e) {
189 
190  }
191  return $file;
192  }
193 }
$context
Definition: webdav.php:31
onDownloadFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
onDownloadWithLink(ReferenceId $reference_id, ilExportHandlerConsumerFileIdentifierInterface $file_identifier)
Interface Observer Contains several chained tasks and infos about them.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
getFiles(ilExportHandlerConsumerContextInterface $context)
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getInstance(int $obj_id)
global $DIC
Definition: shib_login.php:22
language()
Get interface to the i18n service.
Definition: Container.php:95
onDeleteFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
const CMD_LIST_EXPORT_FILES
static _lookupType(int $id, bool $reference=false)
onExportOptionSelected(ilExportHandlerConsumerContextInterface $context)