ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLearningSequenceImporter.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
9{
13 protected $obj;
14
18 protected $data;
19
20 public function init()
21 {
22 global $DIC;
23 $this->user = $DIC["ilUser"];
24 $this->rbac_admin = $DIC["rbacadmin"];
25 $this->log = $DIC["ilLoggerFactory"]->getRootLogger();
26 }
27
28 public function importXmlRepresentation($entity, $id, $xml, $mapping)
29 {
30 if ($new_id = $mapping->getMapping("Services/Container", "objs", $id)) {
31 $this->obj = ilObjectFactory::getInstanceByObjId($new_id, false);
32 } else {
33 $this->obj = new ilObjLearningSequence();
34 $this->obj->create();
35 }
36
37 $parser = new ilLearningSequenceXMLParser($this->obj, $xml);
38 $this->data = $parser->start();
39
40 $mapping->addMapping("Modules/LearningSequence", "lso", $id, $this->obj->getId());
41 }
42
43 public function finalProcessing($mapping)
44 {
45 $this->buildSettings($this->data["settings"]);
46
47 $this->obj->update();
48 }
49
51 {
52 $this->updateRefId($mapping);
53 $this->buildLSItems($this->data["item_data"], $mapping);
54 $this->buildLPSettings($this->data["lp_settings"], $mapping);
55
56 $this->obj->addMember((int) $this->user->getId(), $this->obj->getDefaultAdminRole());
57 }
58
59 protected function updateRefId(ilImportMapping $mapping)
60 {
61 $old_ref_id = $this->data["object"]["ref_id"];
62 $new_ref_id = $mapping->getMapping("Services/Container", "refs", $old_ref_id);
63
64 $this->obj->setRefId($new_ref_id);
65 }
66
67 protected function buildLSItems(array $ls_data, ilImportMapping $mapping)
68 {
69 $ls_items = array();
70 foreach ($ls_data as $data) {
71 $old_ref_id = $data["id"];
72 $new_ref_id = $mapping->getMapping("Services/Container", "refs", $old_ref_id);
73
74 $post_condition = new ilLSPostCondition(
75 (int) $new_ref_id,
76 $data["ls_item_pc_condition_type"],
77 $data["ls_item_pc_value"]
78 );
79
80 $ls_items[] = new LSItem(
81 $data["ls_item_type"] ?? "",
82 $data["ls_item_title"] ?? "",
83 $data["ls_item_description"] ?? "",
84 $data["ls_item_icon_path"] ?? "",
85 (bool) $data["ls_item_is_online"],
86 (int) $data["ls_item_order_number"],
87 $post_condition,
88 (int) $new_ref_id
89 );
90 }
91
92 $this->obj->storeLSItems($ls_items);
93 }
94
95 protected function buildSettings(array $ls_settings)
96 {
97 $settings = $this->obj->getLSSettings();
98 $settings = $settings
99 ->withAbstract($ls_settings["abstract"])
100 ->withExtro($ls_settings["extro"])
101 ->withMembersGallery((bool) $ls_settings["members_gallery"])
102 ;
103
104 if ($ls_settings["abstract_img"] != "") {
105 $path = $this->getNewImagePath(ilLearningSequenceFilesystem::IMG_ABSTRACT, $ls_settings['abstract_img']);
106 $abstract_img_data = $this->decodeImageData($ls_settings["abstract_img_data"]);
107 $this->writeToFileSystem($abstract_img_data, $path);
108 $settings = $settings
109 ->withAbstractImage($path)
110 ;
111 }
112
113 if ($ls_settings["extro_img"] != "") {
114 $path = $this->getNewImagePath(ilLearningSequenceFilesystem::IMG_EXTRO, $ls_settings['extro_img']);
115 $extro_img_data = $this->decodeImageData($ls_settings["extro_img_data"]);
116 $this->writeToFileSystem($extro_img_data, $path);
117 $settings = $settings
118 ->withExtroImage($path)
119 ;
120 }
121
122 $this->obj->updateSettings($settings);
123 }
124
125 protected function buildLPSettings(array $lp_settings, ilImportMapping $mapping)
126 {
127 $collection = ilLPCollection::getInstanceByMode($this->obj->getId(), (int) $lp_settings["lp_mode"]);
128
129 $new_ref_ids = array_map(function ($old_ref_id) use ($mapping) {
130 return $mapping->getMapping("Services/Container", "refs", $old_ref_id);
131 }, $lp_settings["lp_item_ref_ids"]);
132
133 if (!is_null($collection)) {
134 $collection->activateEntries($new_ref_ids);
135 }
136
137 $settings = new ilLPObjSettings($this->obj->getId());
138 $settings->setMode((int) $lp_settings["lp_mode"]);
139 $settings->insert();
140 }
141
142 protected function decodeImageData(string $data)
143 {
144 return base64_decode($data);
145 }
146
147 protected function getNewImagePath(string $type, string $path) : string
148 {
149 $fs = $this->obj->getLSFileSystem();
150 return $fs->getStoragePathFor(
151 $type,
152 (int) $this->obj->getId(),
153 $fs->getSuffix($path)
154 );
155 }
156
157 protected function writeToFileSystem($data, string $path)
158 {
159 file_put_contents($path, $data);
160 }
161}
$parser
Definition: BPMN2Parser.php:23
user()
Definition: user.php:4
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
Data holding class LSItem .
Definition: LSItem.php:12
getMapping($a_comp, $a_entity, $a_old_id)
Get a mapping.
static getInstanceByMode($a_obj_id, $a_mode)
A PostCondition does restrict the progression of a user through the learning sequence.
buildLSItems(array $ls_data, ilImportMapping $mapping)
finalProcessing($mapping)
Final processing.
buildLPSettings(array $lp_settings, ilImportMapping $mapping)
importXmlRepresentation($entity, $id, $xml, $mapping)
Import xml representation.
getNewImagePath(string $type, string $path)
afterContainerImportProcessing(ilImportMapping $mapping)
Called after all container objects have been implemented.
Class ilObjLearningSequence.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Xml importer class.
if(!array_key_exists('StateId', $_REQUEST)) $id
$type
global $DIC
Definition: saml.php:7
$this data['403_header']