ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilExportExportOptionXML.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 use ILIAS\Export\ExportHandler\I\Table\RowId\HandlerInterface as ilExportHandlerTableRowIdInterface;
28 use ILIAS\Export\ExportHandler\I\Consumer\Context\HandlerInterface as ilExportHandlerConsumerContextInterface;
29 use ILIAS\Export\ExportHandler\I\FactoryInterface as ilExportHandlerFactoryInterface;
30 use ILIAS\Export\ExportHandler\Factory as ilExportHandlerFactory;
31 use ILIAS\Export\ExportHandler\I\Info\File\CollectionInterface as ilExportHandlerFileInfoCollectionInterface;
32 use ILIAS\Export\ExportHandler\I\Table\RowId\CollectionInterface as ilExportHandlerTableRowIdCollectionInterface;
33 use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\CollectionInterface as ilExportHandlerConsumerFileIdentifierCollectionInterface;
34 use ILIAS\Export\ExportHandler\I\Consumer\File\Identifier\HandlerInterface as ilExportHandlerConsumerFileIdentifierInterface;
35 
36 class ilExportExportOptionXML extends ilBasicExportOption
37 {
38  protected ilExportHandlerFactoryInterface $export_handler;
39  protected ilLanguage $lng;
40  protected ilCtrl $ctrl;
41  protected ilObjUser $user;
43 
44  public function init(Container $DIC): void
45  {
46  $this->export_handler = new ilExportHandlerFactory();
47  $this->lng = $DIC->language();
48  $this->ctrl = $DIC->ctrl();
49  $this->user = $DIC->user();
50  $this->data_factory = new ilDataFactory();
51  }
52 
53  public function getExportType(): string
54  {
55  return "xml";
56  }
57 
58  public function getExportOptionId(): string
59  {
60  return "expxml";
61  }
62 
63  public function getSupportedRepositoryObjectTypes(): array
64  {
65  # The standard xml export is a special case.
66  # It is by default always enabled, independend of the object types returned.
67  # Therefore no object types are returned.
68  # The only exception are the special cases: Test, TestQuestionPool
69  return [];
70  }
71 
72  public function isPublicAccessPossible(): bool
73  {
74  return true;
75  }
76 
77  public function getLabel(): string
78  {
79  return $this->lng->txt("exp_format_dropdown-xml");
80  }
81 
82  public function onExportOptionSelected(
83  ilExportHandlerConsumerContextInterface $context
84  ): void {
85  $this->ctrl->redirect($context->exportGUIObject(), $context->exportGUIObject()::CMD_EXPORT_XML);
86  }
87 
88  public function onDeleteFiles(
89  ilExportHandlerConsumerContextInterface $context,
90  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
91  ): void {
92  $object_id = $this->data_factory->objId($context->exportObject()->getId());
93  $keys = $this->export_handler->repository()->key()->collection();
94  foreach ($file_identifiers as $file_identifier) {
95  $keys = $keys->withElement($this->export_handler->repository()->key()->handler()
96  ->withObjectId($object_id)
97  ->withResourceIdSerialized($file_identifier->getIdentifier()));
98  }
99  $this->export_handler->repository()->handler()->deleteElements(
100  $keys,
101  $this->export_handler->repository()->stakeholder()->handler()->withOwnerId($this->user->getId())
102  );
103  }
104 
105  public function onDownloadFiles(
106  ilExportHandlerConsumerContextInterface $context,
107  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
108  ): void {
109  $object_id = $this->data_factory->objId($context->exportObject()->getId());
110  $keys = $this->export_handler->repository()->key()->collection();
111  foreach ($file_identifiers as $file_identifier) {
112  $keys = $keys->withElement($this->export_handler->repository()->key()->handler()
113  ->withObjectId($object_id)
114  ->withResourceIdSerialized($file_identifier->getIdentifier()));
115  }
116  $elements = $this->export_handler->repository()->handler()->getElements($keys);
117  foreach ($elements as $element) {
118  $element->getIRSS()->download();
119  }
120  }
121 
122  public function onDownloadWithLink(
123  ReferenceId $reference_id,
124  ilExportHandlerConsumerFileIdentifierInterface $file_identifier
125  ): void {
126  $object_id = $reference_id->toObjectId();
127  $keys = $this->export_handler->repository()->key()->collection()
128  ->withElement($this->export_handler->repository()->key()->handler()
129  ->withObjectId($object_id)
130  ->withResourceIdSerialized($file_identifier->getIdentifier()));
131  $elements = $this->export_handler->repository()->handler()->getElements($keys);
132  foreach ($elements as $element) {
133  $element->getIRSS()->download();
134  }
135  }
136 
137  public function getFiles(
138  ilExportHandlerConsumerContextInterface $context
139  ): ilExportHandlerFileInfoCollectionInterface {
140  $object_id = $this->data_factory->objId($context->exportObject()->getId());
141  return $this->buildElements($context, $object_id, [], true);
142  }
143 
144  public function getFileSelection(
145  ilExportHandlerConsumerContextInterface $context,
146  ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers
147  ): ilExportHandlerFileInfoCollectionInterface {
148  $object_id = $this->data_factory->objId($context->exportObject()->getId());
149  return $this->buildElements($context, $object_id, $file_identifiers->toStringArray());
150  }
151 
152  protected function buildElements(
153  ilExportHandlerConsumerContextInterface $context,
154  ObjectId $object_id,
155  array $file_identifiers,
156  bool $all_elements = false
157  ): ilExportHandlerFileInfoCollectionInterface {
158  $keys = $this->export_handler->repository()->key()->collection();
159  if ($all_elements) {
160  $keys = $keys->withElement($this->export_handler->repository()->key()->handler()->withObjectId($object_id));
161  }
162  if (!$all_elements) {
163  foreach ($file_identifiers as $id) {
164  $keys = $keys->withElement($this->export_handler->repository()->key()->handler()
165  ->withObjectId($object_id)
166  ->withResourceIdSerialized($id));
167  }
168  }
169  $elements = $this->export_handler->repository()->handler()->getElements($keys);
170  $object_id = $this->data_factory->objId($context->exportObject()->getId());
171  $collection_builder = $context->fileCollectionBuilder();
172  foreach ($elements as $element) {
173  $collection_builder = $collection_builder->withResourceIdentifier(
174  $element->getIRSSInfo()->getResourceId(),
175  $object_id,
176  $this
177  );
178  }
179  return $collection_builder->collection();
180  }
181 }
getFileSelection(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
user()
Get the current user.
Definition: Container.php:71
$context
Definition: webdav.php:31
onDownloadWithLink(ReferenceId $reference_id, ilExportHandlerConsumerFileIdentifierInterface $file_identifier)
buildElements(ilExportHandlerConsumerContextInterface $context, ObjectId $object_id, array $file_identifiers, bool $all_elements=false)
ilExportHandlerFactoryInterface $export_handler
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
onDownloadFiles(ilExportHandlerConsumerContextInterface $context, ilExportHandlerConsumerFileIdentifierCollectionInterface $file_identifiers)
onDeleteFiles(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
language()
Get interface to the i18n service.
Definition: Container.php:95
onExportOptionSelected(ilExportHandlerConsumerContextInterface $context)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
ctrl()
Get the interface to the control structure.
Definition: Container.php:63