ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExportGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Data\Factory as ilDataFactory;
23use ILIAS\DI\UIServices as ilUIServices;
24use ILIAS\Export\ExportHandler\I\Consumer\Context\HandlerInterface as ilExportHandlerConsumerContextInterface;
25use ILIAS\Export\ExportHandler\I\Consumer\ExportOption\CollectionInterface as ilExportHandlerConsumerExportOptionCollectionInterface;
26use ILIAS\Export\ExportHandler\I\Consumer\ExportOption\HandlerInterface as ilExportHandlerConsumerExportOptionInterface;
27use ILIAS\Export\ExportHandler\Factory as ilExportHandler;
28use ILIAS\HTTP\Services as ilHTTPServices;
29use ILIAS\Refinery\Factory as ilRefineryFactory;
31
38{
39 public const CMD_LIST_EXPORT_FILES = "listExportFiles";
40 public const CMD_EXPORT_XML = "createXmlExportFile";
41 protected const CMD_SAVE_ITEM_SELECTION = "saveItemSelection";
42 protected const CMD_EXPORT_OPTION_PREFIX = "exportOption";
43
44 protected ilExportHandlerConsumerExportOptionCollectionInterface $export_options;
45 protected ilUIServices $ui_services;
46 protected ilHTTPServices $http;
47 protected ilRefineryFactory $refinery;
49 protected ilLanguage $lng;
50 protected ilObject $obj;
55
58 protected ilTree $tree;
59 protected ilExportHandler $export_handler;
60 protected ilExportHandlerConsumerContextInterface $context;
61 protected ilDataFactory $data_factory;
62 protected object $parent_gui;
63 protected bool $public_access_enabled;
64
65 public function __construct(
66 object $a_parent_gui,
67 ?ilObject $a_main_obj = null,
68 bool $public_access_enabled = true,
69 bool $default_export_option_enabled = true
70 ) {
71 global $DIC;
72 $this->ui_services = $DIC->ui();
73 $this->http = $DIC->http();
74 $this->refinery = $DIC->refinery();
75 $this->il_user = $DIC->user();
76 $this->lng = $DIC->language();
77 $this->lng->loadLanguageModule("exp");
78 $this->tpl = $DIC->ui()->mainTemplate();
79 $this->ctrl = $DIC->ctrl();
80 $this->access = $DIC->access();
81 $this->error = $DIC['ilErr'];
82 $this->toolbar = $DIC->toolbar();
83 $this->parent_gui = $a_parent_gui;
84 $this->obj_definition = $DIC['objDefinition'];
85 $this->tree = $DIC->repositoryTree();
86 $this->obj = $a_main_obj ?? $a_parent_gui->getObject();
87 $this->export_handler = new ilExportHandler();
88 $this->context = $this->export_handler->consumer()->context()->handler($this, $this->obj);
89 $this->export_options = $this->export_handler->consumer()->exportOption()->collection();
90 $this->data_factory = new ilDataFactory();
91 $this->public_access_enabled = $public_access_enabled;
92 $this->initExportOptions();
93 if ($default_export_option_enabled) {
95 }
96 }
97
98 final public function isPublicAccessEnabled(): bool
99 {
101 }
102
103 public function executeCommand(): void
104 {
105 // this should work (at least) for repository objects
106 if (method_exists($this->obj, 'getRefId') and $this->obj->getRefId()) {
107 if (!$this->access->checkAccess('write', '', $this->obj->getRefId())) {
108 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->WARNING);
109 }
110 // check export activation of container
111 $exp_limit = new ilExportLimitation();
112 if ($this->obj_definition->isContainer(ilObject::_lookupType($this->obj->getRefId(), true)) &&
113 $exp_limit->getLimitationMode() == ilExportLimitation::SET_EXPORT_DISABLED) {
114 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exp_error_disabled"));
115 return;
116 }
117 }
118 $cmd = $this->ctrl->getCmd(self::CMD_LIST_EXPORT_FILES);
119 if (str_starts_with($cmd, self::CMD_EXPORT_OPTION_PREFIX)) {
120 foreach ($this->export_options as $export_option) {
121 if ($cmd === $this->builtExportOptionCommand($export_option)) {
122 $export_option->onExportOptionSelected($this->context);
123 }
124 }
125 }
126 switch ($cmd) {
128 $this->createXMLExportFile();
129 break;
131 $this->saveItemSelection();
132 break;
134 default:
135 $this->displayExportFiles();
136 break;
137 }
138 }
139
143 public function addFormat(): void
144 {
145
146 }
147
148 public function listExportFiles(): void
149 {
150 $this->displayExportFiles();
151 }
152
156 public function getFormats(): array
157 {
158 return [];
159 }
160
161 final protected function initExportOptionsFromPost(): array
162 {
163 $options = [];
164 if ($this->http->wrapper()->post()->has('cp_options')) {
165 $custom_transformer = $this->refinery->custom()->transformation(
166 function ($array) {
167 return $array;
168 }
169 );
170 $options = $this->http->wrapper()->post()->retrieve(
171 'cp_options',
172 $custom_transformer
173 );
174 }
175 return $options;
176 }
177
178 final protected function builtExportOptionCommand(ilExportHandlerConsumerExportOptionInterface $export_option): string
179 {
180 return self::CMD_EXPORT_OPTION_PREFIX . $export_option->getExportOptionId();
181 }
182
183 final protected function enableStandardXMLExport(): void
184 {
185 $this->export_options = $this->export_options->withElement(new ilExportExportOptionXML());
186 }
187
188 final protected function initExportOptions(): void
189 {
190 $export_options = $this->export_handler->consumer()->exportOption()->allExportOptions();
191 foreach ($export_options as $export_option) {
192 if (
193 in_array($this->obj->getType(), $export_option->getSupportedRepositoryObjectTypes()) and
194 $export_option->isObjectSupported($this->data_factory->objId($this->obj->getId()))
195 ) {
196 $this->export_options = $this->export_options->withElement($export_option);
197 }
198 }
199 }
200
201 final protected function displayExportFiles(): void
202 {
203 if ($this->export_options->count() === 0) {
204 return;
205 }
206 $table = $this->export_handler->table()->handler()
207 ->withExportOptions($this->export_options)
208 ->withContext($this->context)
209 ->withPublicAccessEnabled($this->isPublicAccessEnabled());
210 $table->handleCommands();
211 $infos = [];
212 foreach ($this->export_options as $export_option) {
213 $infos[$export_option->getLabel()] = $this->ctrl->getLinkTarget($this, $this->builtExportOptionCommand($export_option));
214 }
215 if (count($infos) === 1) {
216 $this->toolbar->addComponent($this->ui_services->factory()->button()->standard(
217 sprintf($this->lng->txt("exp_export_single_option"), array_keys($infos)[0]),
218 array_values($infos)[0]
219 ));
220 }
221 if (count($infos) > 1) {
222 $links = [];
223 foreach ($infos as $label => $link) {
224 $links[] = $this->ui_services->factory()->link()->standard($label, $link);
225 }
226 $this->toolbar->addComponent(
227 $this->ui_services->factory()->dropdown()->standard($links)
228 ->withLabel($this->lng->txt("exp_export_dropdown"))
229 );
230 }
231 $this->tpl->setContent($table->getHTML());
232 }
233
234 final protected function createXMLExportFile(): void
235 {
236 if ($this->parent_gui instanceof ilContainerGUI) {
237 $this->showItemSelection();
238 return;
239 }
240 $this->createXMLExport($this->export_handler->consumer()->exportConfig()->allExportConfigs());
241 $this->tpl->setOnScreenMessage(
243 $this->lng->txt("exp_file_created"),
244 true
245 );
246 $this->ctrl->redirect($this, self::CMD_LIST_EXPORT_FILES);
247 }
248
252 final protected function showItemSelection(): void
253 {
254 $this->tpl->addJavaScript('assets/js/ilContainer.js');
255 $this->tpl->setVariable('BODY_ATTRIBUTES', 'onload="ilDisableChilds(\'cmd\');"');
256 $table = new ilExportSelectionTableGUI($this, self::CMD_LIST_EXPORT_FILES, $this->export_handler);
257 $table->parseContainer($this->parent_gui->getObject()->getRefId());
258 $this->tpl->setContent($table->getHTML());
259 }
260
261 final protected function saveItemSelection(): void
262 {
263 // check export limitation
264 $cp_options = $this->initExportOptionsFromPost();
265 $exp_limit = new ilExportLimitation();
266 try {
267 $exp_limit->checkLimitation(
268 $this->parent_gui->getObject()->getRefId(),
269 $cp_options
270 );
271 } catch (Exception $e) {
272 $this->tpl->setOnScreenMessage('failure', $e->getMessage());
273 $this->showItemSelection();
274 return;
275 }
276 // create export
278 $this->tpl->setOnScreenMessage('success', $this->lng->txt('export_created'), true);
279 $this->ctrl->redirect($this, self::CMD_LIST_EXPORT_FILES);
280 }
281
282 final protected function createXMLExport(
283 ExportConfigCollectionInterface $export_configs
284 ): void {
285 $manager = $this->export_handler->manager()->handler();
286 $manager->createExportOfObject($this->obj, $this->il_user->getId(), $export_configs);
287 }
288
289 final protected function createXMLContainerExport(): void
290 {
291 $tree_nodes = $this->tree->getSubTree($this->tree->getNodeData($this->parent_gui->getObject()->getRefId()));
292 $post_export_options = $this->initExportOptionsFromPost();
294 $eo->addOption(ilExportOptions::KEY_ROOT, 0, 0, $this->obj->getId());
295 $items_selected = $eo->addOptions(
296 $this->parent_gui->getObject()->getRefId(),
297 $this->obj_definition,
298 $this->access,
299 $tree_nodes,
300 $post_export_options
301 );
302 $eo->read();
303 $ref_ids_export = [$this->parent_gui->getObject()->getRefId()];
304 $ref_ids_all = [$this->parent_gui->getObject()->getRefId()];
305 $tree_ref_ids = array_map(function ($node) { return (int) $node['ref_id']; }, $tree_nodes);
306 $post_ref_ids = array_map(function ($key) {return (int) $key; }, array_keys($post_export_options));
307 $valid_ref_ids = array_intersect($post_ref_ids, $tree_ref_ids);
308 foreach ($valid_ref_ids as $ref_id) {
309 $info = $post_export_options[$ref_id];
310 $export_option_id = (int) $info["type"];
311 if (
312 $export_option_id === ilExportOptions::EXPORT_OMIT ||
313 !$this->obj_definition->allowExport(ilObject::_lookupType($ref_id, true)) ||
314 !$this->access->checkAccess('write', '', $ref_id)
315 ) {
316 continue;
317 }
318 if ($export_option_id === ilExportOptions::EXPORT_BUILD) {
319 $ref_ids_export[] = $ref_id;
320 }
321 if (
322 $export_option_id === ilExportOptions::EXPORT_BUILD ||
323 $export_option_id === ilExportOptions::EXPORT_EXISTING
324 ) {
325 $ref_ids_all[] = $ref_id;
326 }
327 }
328 $export_configs = $this->export_handler->consumer()->exportConfig()->allExportConfigs();
329 $manager = $this->export_handler->manager()->handler();
330 if (count($ref_ids_all) === 1) {
331 $manager->createExportOfObject($this->obj, $this->il_user->getId(), $export_configs);
332 }
333 if (count($ref_ids_all) > 1) {
334 $obj_ids_export = array_map(function (int $ref_id) { return ilObject::_lookupObjId($ref_id); }, $ref_ids_export);
335 $obj_ids_all = array_map(function (int $ref_id) { return ilObject::_lookupObjId($ref_id); }, $ref_ids_all);
336 $object_id_collection_builder = $manager->getObjectIdCollectioBuilder();
337 foreach ($obj_ids_all as $obj_id) {
338 $object_id_collection_builder = $object_id_collection_builder->addObjectId(
339 $this->data_factory->objId($obj_id),
340 in_array($obj_id, $obj_ids_export)
341 );
342 }
343 $container_export_info = $manager->getContainerExportInfo(
344 $this->data_factory->objId($obj_ids_all[0]),
345 $object_id_collection_builder->getCollection(),
346 $export_configs
347 );
348 $element = $manager->createContainerExport($this->il_user->getId(), $container_export_info);
349 }
350 $eo->delete();
351 }
352}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
error(string $a_errmsg)
Class ilContainerGUI This is a base GUI class for all container objects in ILIAS: root folder,...
Error Handling & global info handling.
Export User Interface Class.
ilRefineryFactory $refinery
bool $public_access_enabled
ilHTTPServices $http
ilCtrlInterface $ctrl
ilToolbarGUI $toolbar
ilDataFactory $data_factory
const CMD_SAVE_ITEM_SELECTION
getFormats()
@depricated
ilAccessHandler $access
ilExportHandlerConsumerExportOptionCollectionInterface $export_options
ilExportHandler $export_handler
showItemSelection()
Show container item selection table.
builtExportOptionCommand(ilExportHandlerConsumerExportOptionInterface $export_option)
ilUIServices $ui_services
ilObjUser $il_user
ilLanguage $lng
__construct(object $a_parent_gui, ?ilObject $a_main_obj=null, bool $public_access_enabled=true, bool $default_export_option_enabled=true)
const CMD_EXPORT_OPTION_PREFIX
const CMD_LIST_EXPORT_FILES
ilExportHandlerConsumerContextInterface $context
ilGlobalTemplateInterface $tpl
ilObjectDefinition $obj_definition
createXMLExport(ExportConfigCollectionInterface $export_configs)
addFormat()
@depricated
ilErrorHandling $error
Export limitation checker.
static newInstance(int $a_export_id)
language handling
User class.
parses the objects.xml it handles the xml-description of all ilias objects
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$info
Definition: entry_point.php:21
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26