ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilLearningSequenceImporter Class Reference
+ Inheritance diagram for ilLearningSequenceImporter:
+ Collaboration diagram for ilLearningSequenceImporter:

Public Member Functions

 __construct ()
 
 init ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 
 setImport (ilImport $a_val)
 
 getImport ()
 
 init ()
 
 setInstallId (string $a_val)
 
 getInstallId ()
 
 setInstallUrl (string $a_val)
 
 getInstallUrl ()
 
 setSchemaVersion (string $a_val)
 
 getSchemaVersion ()
 
 setImportDirectory (string $a_val)
 
 getImportDirectory ()
 
 setSkipEntities (array $a_val)
 
 getSkipEntities ()
 
 exportedFromSameInstallation ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 

Protected Member Functions

 updateRefId (ilImportMapping $mapping)
 
 buildLSItems (array $ls_data, ilImportMapping $mapping)
 
 buildItemConditions (array $ls_data, ilImportMapping $mapping)
 Creates lso_conditions + condition payload (lso_c_*) based on parsed XML. More...
 
 buildSettings (array $ls_settings, ilImportMapping $mapping)
 
 buildLPSettings (array $lp_settings, ilImportMapping $mapping)
 
 decodeImageData (string $data)
 
 getNewImagePath (string $type, string $path)
 
 writeToFileSystem ($data, string $path)
 

Protected Attributes

PageManagerInterface $page_manager
 
ilObjUser $user
 
ilRbacAdmin $rbac_admin
 
ilLogger $log
 
ilObjLearningSequence $obj
 
array $data
 
- Protected Attributes inherited from ilXmlImporter
array $skip_entities = array()
 
ilImport $imp
 
string $install_id
 
string $install_url
 
string $schema_version
 
string $import_directory
 

Detailed Description

Definition at line 24 of file class.ilLearningSequenceImporter.php.

Constructor & Destructor Documentation

◆ __construct()

ilLearningSequenceImporter::__construct ( )

Reimplemented from ilXmlImporter.

Definition at line 33 of file class.ilLearningSequenceImporter.php.

34 {
35 global $DIC;
37 $this->page_manager = $DIC->copage()->internal()->domain()->page();
38 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References $DIC, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ afterContainerImportProcessing()

ilLearningSequenceImporter::afterContainerImportProcessing ( ilImportMapping  $mapping)

Reimplemented from ilXmlImporter.

Definition at line 123 of file class.ilLearningSequenceImporter.php.

123 : void
124 {
125 $this->updateRefId($mapping);
126 $this->buildLSItems($this->data["item_data"], $mapping);
127 $this->buildItemConditions($this->data["item_data"], $mapping);
128 $this->buildLPSettings($this->data["lp_settings"], $mapping);
129
130 $roles = $this->obj->getLSRoles();
131 $roles->addLSMember(
132 $this->user->getId(),
133 $roles->getDefaultAdminRole()
134 );
135 }
buildLSItems(array $ls_data, ilImportMapping $mapping)
buildLPSettings(array $lp_settings, ilImportMapping $mapping)
buildItemConditions(array $ls_data, ilImportMapping $mapping)
Creates lso_conditions + condition payload (lso_c_*) based on parsed XML.

References buildItemConditions(), buildLPSettings(), buildLSItems(), updateRefId(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ buildItemConditions()

ilLearningSequenceImporter::buildItemConditions ( array  $ls_data,
ilImportMapping  $mapping 
)
protected

Creates lso_conditions + condition payload (lso_c_*) based on parsed XML.

Expected $ls_data format (per item): [ 'ref_id' => <old_ref_id>, 'conditions' => [ [ 'type_id' => <int|string>, // maps to lso_condition_types.type_id 'subtype' => <string|null>, 'data' => <payload array exported by AbstractCondition::export()> ], ... ] ]

Definition at line 194 of file class.ilLearningSequenceImporter.php.

194 : void
195 {
196 $factory = $this->obj->getDI()["conditions.factory"];
197 $handler = $this->obj->getDI()["conditions.handler"];
198
199 $new_lso_ref_id = $this->obj->getRefId();
200
201 foreach ($ls_data as $item_data) {
202 $old_item_ref_id = (string) ($item_data['ref_id'] ?? '');
203 if ($old_item_ref_id === '') {
204 continue;
205 }
206
207 $new_item_ref_id = $mapping->getMapping('components/ILIAS/Container', 'refs', $old_item_ref_id);
208 if ($new_item_ref_id === null) {
209 continue;
210 }
211 $new_item_ref_id = (int) $new_item_ref_id;
212
213 $conditions = is_array($item_data['conditions'] ?? null) ? $item_data['conditions'] : [];
214 if ($conditions === []) {
215 continue;
216 }
217
218 // Avoid duplicates when re-importing/updating: clear existing conditions for this item.
219 $handler->deleteConditionsByRefId($new_lso_ref_id, $new_item_ref_id);
220
221 foreach ($conditions as $cond) {
222 $created = false;
223
224 if (!is_array($cond)) {
225 continue;
226 }
227
228 $type_id_raw = $cond['type'] ?? null;
229 $subtype = isset($cond['subtype']) && is_string($cond['subtype']) && $cond['subtype'] !== ''
230 ? $cond['subtype']
231 : null;
232
233 $payload = is_array($cond['data'] ?? null) ? $cond['data'] : [];
234
235 try {
236 $condition = $factory->getConditionInstanceByName($type_id_raw);
237 $condition->setLsoRefId($new_lso_ref_id);
238 $condition->setObjRefId($new_item_ref_id);
239 if ($subtype !== null && $condition instanceof SubtypeAwareInterface) {
240 $condition->setSubtype($subtype);
241 }
242
243 $condition->create(true);
244 $created = true;
245
246 $new_condition_id = (int) $condition->getConditionId();
247 if ($new_condition_id > 0) {
248 $ref_mappings = array_map(
249 'intval',
250 $mapping->getAllMappings()['components/ILIAS/Container']['refs'] ?? []
251 );
252 $condition->setImportMapping($ref_mappings);
253 $condition->import($payload, $new_condition_id);
254 }
255 } catch (\Throwable $e) {
256 if ($created && isset($condition)) {
257 $condition->delete();
258 }
259
260 $this->log->warning(__METHOD__ . ': condition import failed: ' . $e->getMessage());
261 continue;
262 }
263 }
264 }
265 }
getMapping(string $a_comp, string $a_entity, string $a_old_id)
$handler
Definition: oai.php:31

References Vendor\Package\$e, $handler, ilImportMapping\getAllMappings(), ilImportMapping\getMapping(), and ILIAS\Repository\int().

Referenced by afterContainerImportProcessing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildLPSettings()

ilLearningSequenceImporter::buildLPSettings ( array  $lp_settings,
ilImportMapping  $mapping 
)
protected

Definition at line 291 of file class.ilLearningSequenceImporter.php.

291 : void
292 {
293 $collection = ilLPCollection::getInstanceByMode($this->obj->getId(), (int) $lp_settings["lp_mode"]);
294
295 $new_ref_ids = [];
296 foreach ($lp_settings["lp_item_ref_ids"] as $old_ref_id) {
297 $new_ref_id = $mapping->getMapping("components/ILIAS/Container", "refs", (string) $old_ref_id);
298 if ($new_ref_id === null) {
299 continue;
300 }
301 $new_ref_ids[] = (int) $new_ref_id;
302 }
303
304 if (!is_null($collection)) {
305 $collection->activateEntries($new_ref_ids);
306 }
307
308 $settings = new ilLPObjSettings($this->obj->getId());
309 $settings->setMode((int) $lp_settings["lp_mode"]);
310 $settings->insert();
311 }
$settings
Definition: index.php:44
static getInstanceByMode(int $a_obj_id, int $a_mode)

References $settings, ilLPCollection\getInstanceByMode(), ilImportMapping\getMapping(), and ILIAS\Repository\int().

Referenced by afterContainerImportProcessing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildLSItems()

ilLearningSequenceImporter::buildLSItems ( array  $ls_data,
ilImportMapping  $mapping 
)
protected

Definition at line 145 of file class.ilLearningSequenceImporter.php.

145 : void
146 {
147 $mapped = [];
148 foreach ($ls_data as $data) {
149 $old_ref_id = $data["ref_id"];
150 $new_ref_id = $mapping->getMapping("components/ILIAS/Container", "refs", $old_ref_id);
151 $mapped[$new_ref_id] = $data;
152 }
153
154 $ls_items = $this->obj->getLSItems();
155 $updated = [];
156 foreach ($ls_items as $item) {
157 $item_ref_id = $item->getRefId();
158 if (array_key_exists($item_ref_id, $mapped)) {
159 $item_data = $mapped[$item_ref_id];
160 $post_condition = new ilLSPostCondition(
161 $item_ref_id,
162 $item_data["condition_type"],
163 $item_data["condition_value"]
164 );
165 $item = $item->withPostCondition($post_condition);
166 if (isset($item_data["position"])) {
167 $item = $item->withOrderNumber((int) $item_data["position"]);
168 }
169 $updated[] = $item;
170 }
171 }
172
173 if ($updated) {
174 $this->obj->storeLSItems($updated);
175 }
176 }
A PostCondition does restrict the progression of a user through the learning sequence.

References $data, and ilImportMapping\getMapping().

Referenced by afterContainerImportProcessing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildSettings()

ilLearningSequenceImporter::buildSettings ( array  $ls_settings,
ilImportMapping  $mapping 
)
protected

Definition at line 267 of file class.ilLearningSequenceImporter.php.

267 : void
268 {
269 $settings = $this->obj->getLSSettings();
271 ->withMembersGallery($ls_settings["members_gallery"] === 'true' ? true : false)
272 ;
273 $settings = $settings->withMode((int) $ls_settings["mode"]);
274 $this->obj->updateSettings($settings);
275
276 // boundaries
277 $start_ref_id = (string) ($ls_settings["start_ref_id"] ?? '');
278 $end_ref_id = (string) ($ls_settings["end_ref_id"] ?? '');
279 $new_start_ref_id = $mapping->getMapping("components/ILIAS/Container", "refs", $start_ref_id);
280 $new_end_ref_id = $mapping->getMapping("components/ILIAS/Container", "refs", $end_ref_id);
281
282 $new_start_ref_id = (!empty($new_start_ref_id)) ? (int) $new_start_ref_id : 0;
283 $new_end_ref_id = (!empty($new_end_ref_id)) ? (int) $new_end_ref_id : 0;
284 if ($new_start_ref_id > 0 || $new_end_ref_id > 0) {
285 $boundaries = $this->obj->getDI()["db.boundaries"];
286 $boundaries->setStartRefId($this->obj->getId(), $new_start_ref_id);
287 $boundaries->setEndRefId($this->obj->getId(), $new_end_ref_id);
288 }
289 }

References $settings, and ilImportMapping\getMapping().

Referenced by finalProcessing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decodeImageData()

ilLearningSequenceImporter::decodeImageData ( string  $data)
protected

Definition at line 313 of file class.ilLearningSequenceImporter.php.

313 : string
314 {
315 return base64_decode($data);
316 }

References $data.

◆ finalProcessing()

ilLearningSequenceImporter::finalProcessing ( ilImportMapping  $a_mapping)

Reimplemented from ilXmlImporter.

Definition at line 105 of file class.ilLearningSequenceImporter.php.

105 : void
106 {
107 $this->buildSettings($this->data["settings"], $a_mapping);
108 $this->obj->update();
109
110 // pages
111 $page_map = $a_mapping->getMappingsOfEntity('Services/COPage', 'pg');
112 foreach ($page_map as $old_pg_id => $new_pg_id) {
113 $parts = explode(':', $old_pg_id);
114 $pg_type = $parts[0];
115 $old_obj_id = $parts[1];
116 $parts = explode(':', $new_pg_id);
117 $new_pg_id = array_pop($parts);
118 $new_obj_id = $this->obj->getId();
119 $this->page_manager->writeParentId($pg_type, (int) $new_pg_id, (int) $new_obj_id);
120 }
121 }
getMappingsOfEntity(string $a_comp, string $a_entity)
buildSettings(array $ls_settings, ilImportMapping $mapping)

References buildSettings(), and ilImportMapping\getMappingsOfEntity().

+ Here is the call graph for this function:

◆ getNewImagePath()

ilLearningSequenceImporter::getNewImagePath ( string  $type,
string  $path 
)
protected

Definition at line 318 of file class.ilLearningSequenceImporter.php.

318 : string
319 {
320 $fs = $this->obj->getDI()['db.filesystem'];
321 return $fs->getStoragePathFor(
322 $type,
323 $this->obj->getId(),
324 $fs->getSuffix($path)
325 );
326 }

◆ importXmlRepresentation()

ilLearningSequenceImporter::importXmlRepresentation ( string  $a_entity,
string  $a_id,
string  $a_xml,
ilImportMapping  $a_mapping 
)

Reimplemented from ilXmlImporter.

Definition at line 48 of file class.ilLearningSequenceImporter.php.

48 : void
49 {
50 if ($new_id = $a_mapping->getMapping("components/ILIAS/Container", "objs", $a_id)) {
51 $obj = ilObjectFactory::getInstanceByObjId((int) $new_id, false);
52 if (!$obj instanceof ilObjLearningSequence) {
53 throw new ilImportException('Learning sequence ' . $new_id . ' to import into not found.');
54 }
55 $this->obj = $obj;
56 } else {
57 $this->obj = new ilObjLearningSequence();
58 $this->obj->create();
59 }
60
61 $parser = new ilLearningSequenceXMLParser($this->obj, $a_xml);
62 $this->data = $parser->start();
63
64 $a_mapping->addMapping("components/ILIAS/LearningSequence", "lso", $a_id, (string) $this->obj->getId());
65 $a_mapping->addMapping(
66 'Services/COPage',
67 'pg',
68 LSOPageType::INTRO->value . ':' . $a_id,
69 LSOPageType::INTRO->value . ':' . (string) $this->obj->getId()
70 );
71 $a_mapping->addMapping(
72 'Services/COPage',
73 'pg',
74 LSOPageType::EXTRO->value . ':' . $a_id,
75 LSOPageType::EXTRO->value . ':' . (string) $this->obj->getId()
76 );
77
78 $a_mapping->addMapping(
79 'components/ILIAS/MetaData',
80 'md',
81 $a_id . ':0:lso',
82 (string) $this->obj->getId() . ':0:lso'
83 );
84
85 $a_mapping->addMapping(
86 "components/ILIAS/Taxonomy",
87 "tax_item",
88 "lso:obj:" . $a_id,
89 (string) $this->obj->getId()
90 );
91 $a_mapping->addMapping(
92 "components/ILIAS/Taxonomy",
93 "tax_item_obj_id",
94 "lso:obj:" . $a_id,
95 (string) $this->obj->getId()
96 );
97 $a_mapping->addMapping(
98 "components/ILIAS/Tracking",
99 "obj",
100 (string) $a_id,
101 (string) $this->obj->getId()
102 );
103 }
@ EXTRO
Definition: LSOPageType.php:24
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)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
foreach(array_slice( $argv, 1) as $argument) if(!is_dir($target)) $parser

References $obj, ILIAS\Scripts\PHPStan\$parser, ilImportMapping\addMapping(), EXTRO, ilObjectFactory\getInstanceByObjId(), and ilImportMapping\getMapping().

+ Here is the call graph for this function:

◆ init()

ilLearningSequenceImporter::init ( )

Reimplemented from ilXmlImporter.

Definition at line 40 of file class.ilLearningSequenceImporter.php.

40 : void
41 {
42 global $DIC;
43 $this->user = $DIC["ilUser"];
44 $this->rbac_admin = $DIC["rbacadmin"];
45 $this->log = $DIC["ilLoggerFactory"]->getComponentLogger('lso');
46 }

References $DIC, and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ updateRefId()

ilLearningSequenceImporter::updateRefId ( ilImportMapping  $mapping)
protected

Definition at line 137 of file class.ilLearningSequenceImporter.php.

137 : void
138 {
139 $old_ref_id = $this->data["object"]["ref_id"];
140 $new_ref_id = $mapping->getMapping("components/ILIAS/Container", "refs", $old_ref_id);
141
142 $this->obj->setRefId((int) $new_ref_id);
143 }

References ilImportMapping\getMapping().

Referenced by afterContainerImportProcessing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeToFileSystem()

ilLearningSequenceImporter::writeToFileSystem (   $data,
string  $path 
)
protected

Definition at line 328 of file class.ilLearningSequenceImporter.php.

328 : void
329 {
330 file_put_contents($path, $data);
331 }

References $data.

Field Documentation

◆ $data

array ilLearningSequenceImporter::$data
protected

◆ $log

ilLogger ilLearningSequenceImporter::$log
protected

Definition at line 29 of file class.ilLearningSequenceImporter.php.

◆ $obj

ilObjLearningSequence ilLearningSequenceImporter::$obj
protected

Definition at line 30 of file class.ilLearningSequenceImporter.php.

Referenced by importXmlRepresentation().

◆ $page_manager

PageManagerInterface ilLearningSequenceImporter::$page_manager
protected

Definition at line 26 of file class.ilLearningSequenceImporter.php.

◆ $rbac_admin

ilRbacAdmin ilLearningSequenceImporter::$rbac_admin
protected

Definition at line 28 of file class.ilLearningSequenceImporter.php.

◆ $user

ilObjUser ilLearningSequenceImporter::$user
protected

Definition at line 27 of file class.ilLearningSequenceImporter.php.


The documentation for this class was generated from the following file: