ILIAS  release_8 Revision v8.24
class.ilLearningSequenceImporter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected ilObjUser $user;
25 protected ilLogger $log;
26 protected ilObject $obj;
27 protected array $data;
28
29 public function init(): void
30 {
31 global $DIC;
32 $this->user = $DIC["ilUser"];
33 $this->rbac_admin = $DIC["rbacadmin"];
34 $this->log = $DIC["ilLoggerFactory"]->getRootLogger();
35 }
36
37 public function importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping): void
38 {
39 if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_id)) {
40 $this->obj = ilObjectFactory::getInstanceByObjId((int) $new_id, false);
41 } else {
42 $this->obj = new ilObjLearningSequence();
43 $this->obj->create();
44 }
45
46 $parser = new ilLearningSequenceXMLParser($this->obj, $a_xml);
47 $this->data = $parser->start();
48
49 $a_mapping->addMapping("Modules/LearningSequence", "lso", $a_id, (string) $this->obj->getId());
50 }
51
52 public function finalProcessing(ilImportMapping $a_mapping): void
53 {
54 $this->buildSettings($this->data["settings"]);
55
56 $this->obj->update();
57 }
58
59 public function afterContainerImportProcessing(ilImportMapping $mapping): void
60 {
61 $this->updateRefId($mapping);
62 $this->buildLSItems($this->data["item_data"], $mapping);
63 $this->buildLPSettings($this->data["lp_settings"], $mapping);
64
65 $roles = $this->obj->getLSRoles();
66 $roles->addLSMember(
67 $this->user->getId(),
68 $roles->getDefaultAdminRole()
69 );
70 }
71
72 protected function updateRefId(ilImportMapping $mapping): void
73 {
74 $old_ref_id = $this->data["object"]["ref_id"];
75 $new_ref_id = $mapping->getMapping("Services/Container", "refs", $old_ref_id);
76
77 $this->obj->setRefId((int) $new_ref_id);
78 }
79
80 protected function buildLSItems(array $ls_data, ilImportMapping $mapping): void
81 {
82 $ls_items = array();
83 foreach ($ls_data as $data) {
84 $old_ref_id = $data["id"];
85 $new_ref_id = $mapping->getMapping("Services/Container", "refs", $old_ref_id);
86
87 $ls_item_pc_value = null;
88 if (key_exists("ls_item_pc_value", $data)) {
89 $ls_item_pc_value = $data["ls_item_pc_value"];
90 }
91
92 $post_condition = new ilLSPostCondition(
93 (int) $new_ref_id,
94 $data["ls_item_pc_condition_type"],
95 $ls_item_pc_value
96 );
97
98 $ls_items[] = new LSItem(
99 $data["ls_item_type"] ?? "",
100 $data["ls_item_title"] ?? "",
101 $data["ls_item_description"] ?? "",
102 $data["ls_item_icon_path"] ?? "",
103 (bool) $data["ls_item_is_online"],
104 (int) $data["ls_item_order_number"],
105 $post_condition,
106 (int) $new_ref_id
107 );
108 }
109
110 $this->obj->storeLSItems($ls_items);
111 }
112
113 protected function buildSettings(array $ls_settings): void
114 {
115 $settings = $this->obj->getLSSettings();
117 ->withAbstract($ls_settings["abstract"])
118 ->withExtro($ls_settings["extro"])
119 ->withMembersGallery((bool) $ls_settings["members_gallery"])
120 ;
121
122 if ($ls_settings["abstract_img"] != "") {
123 $path = $this->getNewImagePath(ilLearningSequenceFilesystem::IMG_ABSTRACT, $ls_settings['abstract_img']);
124 $abstract_img_data = $this->decodeImageData($ls_settings["abstract_img_data"]);
125 $this->writeToFileSystem($abstract_img_data, $path);
127 ->withAbstractImage($path)
128 ;
129 }
130
131 if ($ls_settings["extro_img"] != "") {
132 $path = $this->getNewImagePath(ilLearningSequenceFilesystem::IMG_EXTRO, $ls_settings['extro_img']);
133 $extro_img_data = $this->decodeImageData($ls_settings["extro_img_data"]);
134 $this->writeToFileSystem($extro_img_data, $path);
136 ->withExtroImage($path)
137 ;
138 }
139
140 $this->obj->updateSettings($settings);
141 }
142
143 protected function buildLPSettings(array $lp_settings, ilImportMapping $mapping): void
144 {
145 $collection = ilLPCollection::getInstanceByMode($this->obj->getId(), (int) $lp_settings["lp_mode"]);
146
147 $new_ref_ids = array_map(function ($old_ref_id) use ($mapping) {
148 return $mapping->getMapping("Services/Container", "refs", $old_ref_id);
149 }, $lp_settings["lp_item_ref_ids"]);
150
151 if (!is_null($collection)) {
152 $collection->activateEntries($new_ref_ids);
153 }
154
155 $settings = new ilLPObjSettings($this->obj->getId());
156 $settings->setMode((int) $lp_settings["lp_mode"]);
157 $settings->insert();
158 }
159
160 protected function decodeImageData(string $data): string
161 {
162 return base64_decode($data);
163 }
164
165 protected function getNewImagePath(string $type, string $path): string
166 {
167 $fs = $this->obj->getDI()['db.filesystem'];
168 return $fs->getStoragePathFor(
169 $type,
170 $this->obj->getId(),
171 $fs->getSuffix($path)
172 );
173 }
174
175 protected function writeToFileSystem($data, string $path): void
176 {
177 file_put_contents($path, $data);
178 }
179}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: LSItem.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
static getInstanceByMode(int $a_obj_id, int $a_mode)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildLSItems(array $ls_data, ilImportMapping $mapping)
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
buildLPSettings(array $lp_settings, ilImportMapping $mapping)
getNewImagePath(string $type, string $path)
afterContainerImportProcessing(ilImportMapping $mapping)
finalProcessing(ilImportMapping $a_mapping)
Component logger with individual log levels by component id.
User class.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilRbacAdmin Core functions for role based access control.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$type