ILIAS  release_8 Revision v8.24
class.ilMediaObjectDataSet.php
Go to the documentation of this file.
1<?php
2
31{
34 protected ilLogger $mob_log;
35 protected bool $use_previous_import_ids = false;
36
37 public function __construct()
38 {
40 $this->mob_log = ilLoggerFactory::getLogger('mob');
41 }
42
48 public function setUsePreviousImportIds(bool $a_val): void
49 {
50 $this->use_previous_import_ids = $a_val;
51 }
52
53 public function getUsePreviousImportIds(): bool
54 {
56 }
57
61 public function getSupportedVersions(): array
62 {
63 return array("5.1.0", "4.3.0", "4.1.0");
64 }
65
66 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
67 {
68 return "https://www.ilias.de/xml/Services/MediaObject/" . $a_entity;
69 }
70
71 protected function getTypes(string $a_entity, string $a_version): array
72 {
73 // mob
74 if ($a_entity == "mob") {
75 switch ($a_version) {
76 case "4.1.0":
77 case "4.3.0":
78 return array(
79 "Id" => "integer",
80 "Title" => "text",
81 "Description" => "text",
82 "Dir" => "directory"
83 );
84
85 case "5.1.0":
86 return array(
87 "Id" => "integer",
88 "Title" => "text",
89 "Description" => "text",
90 "Dir" => "directory",
91 "ImportId" => "text"
92 );
93 }
94 }
95
96 // media item
97 if ($a_entity == "mob_media_item") {
98 switch ($a_version) {
99 case "5.1.0":
100 case "4.3.0":
101 case "4.1.0":
102 return array(
103 "Id" => "integer",
104 "MobId" => "integer",
105 "Width" => "integer",
106 "Height" => "integer",
107 "Halign" => "text",
108 "Caption" => "text",
109 "Nr" => "integer",
110 "Purpose" => "text",
111 "Location" => "text",
112 "LocationType" => "text",
113 "Format" => "text",
114 "TextRepresentation" => "text"
115 );
116
117 }
118 }
119
120 // map areas
121 if ($a_entity == "mob_mi_map_area") {
122 switch ($a_version) {
123 case "4.1.0":
124 case "4.3.0":
125 case "5.1.0":
126 return array(
127 "MiId" => "integer",
128 "Nr" => "integer",
129 "Shape" => "text",
130 "Coords" => "text",
131 "LinkType" => "text",
132 "Title" => "text",
133 "Href" => "text",
134 "Target" => "text",
135 "Type" => "text",
136 "TargetFrame" => "text",
137 "HighlightMode" => "text",
138 "HighlightText" => "text"
139 );
140 }
141 }
142
143 // media item parameter
144 if ($a_entity == "mob_mi_parameter") {
145 switch ($a_version) {
146 case "4.1.0":
147 case "4.3.0":
148 case "5.1.0":
149 return array(
150 "MiId" => "integer",
151 "Name" => "text",
152 "Value" => "text"
153 );
154 }
155 }
156 return [];
157 }
158
159 public function readData(
160 string $a_entity,
161 string $a_version,
162 array $a_ids
163 ): void {
164 $ilDB = $this->db;
165
166 if (!is_array($a_ids)) {
167 $a_ids = array($a_ids);
168 }
169
170 // mob
171 if ($a_entity == "mob") {
172 $this->data = array();
173
174 switch ($a_version) {
175 case "4.1.0":
176 case "4.3.0":
177 foreach ($a_ids as $mob_id) {
178 if (ilObject::_lookupType($mob_id) == "mob") {
179 $this->data[] = array("Id" => $mob_id,
180 "Title" => ilObject::_lookupTitle($mob_id),
181 "Description" => ilObject::_lookupDescription($mob_id)
182 );
183 }
184 }
185 break;
186
187 case "5.1.0":
188 foreach ($a_ids as $mob_id) {
189 if (ilObject::_lookupType($mob_id) == "mob") {
190 $this->data[] = array("Id" => $mob_id,
191 "Title" => ilObject::_lookupTitle($mob_id),
192 "Description" => ilObject::_lookupDescription($mob_id),
193 "ImportId" => ilObject::_lookupImportId($mob_id)
194 );
195 }
196 }
197 break;
198 }
199 }
200
201 // media item
202 if ($a_entity == "mob_media_item") {
203 switch ($a_version) {
204 case "5.1.0":
205 case "4.3.0":
206 case "4.1.0":
207 $this->getDirectDataFromQuery("SELECT id, mob_id, width, height, halign," .
208 "caption, nr, purpose, location, location_type, format, text_representation" .
209 " FROM media_item WHERE " .
210 $ilDB->in("mob_id", $a_ids, false, "integer"));
211 break;
212
213 }
214 }
215
216
217 // media item map area
218 if ($a_entity == "mob_mi_map_area") {
219 switch ($a_version) {
220 case "4.1.0":
221 case "4.3.0":
222 case "5.1.0":
223 foreach ($this->getDirectDataFromQuery("SELECT item_id mi_id, nr" .
224 " ,shape, coords, link_type, title, href, target, type, target_frame, " .
225 " highlight_mode, highlight_class" .
226 " FROM map_area " .
227 " WHERE " .
228 $ilDB->in("item_id", $a_ids, false, "integer") .
229 " ORDER BY nr", true, false) as $r) {
230 $r["Target"] = ilUtil::insertInstIntoID((string) ($r["Target"] ?? ""));
231
232 // see ilPageObject::insertInstIntoIDs
233 if ($r["Type"] == "RepositoryItem") {
234 $id_arr = explode("_", $r["Target"]);
235 $ref_id = $id_arr[3];
236 $obj_id = ilObject::_lookupObjId($id_arr[3]);
237
238 $otype = ilObject::_lookupType($obj_id);
239 if ($obj_id > 0) {
240 $id = $otype . "_" . $obj_id . "_" . $ref_id;
241 $r["Target"] = "il_" . $id_arr[1] . "_" . $id;
242 }
243 }
244
245 $this->data[] = $r;
246 }
247 break;
248 }
249 }
250
251 // media item parameter
252 if ($a_entity == "mob_mi_parameter") {
253 switch ($a_version) {
254 case "4.1.0":
255 case "4.3.0":
256 case "5.1.0":
257 $this->getDirectDataFromQuery("SELECT med_item_id mi_id, name, value" .
258 " FROM mob_parameter " .
259 " WHERE " .
260 $ilDB->in("med_item_id", $a_ids, false, "integer"));
261 break;
262 }
263 }
264 }
265
269 protected function getDependencies(
270 string $a_entity,
271 string $a_version,
272 ?array $a_rec = null,
273 ?array $a_ids = null
274 ): array {
275 switch ($a_entity) {
276 case "mob":
277 return array(
278 "mob_media_item" => array("ids" => $a_rec["Id"] ?? null)
279 );
280
281 case "mob_media_item":
282 return array(
283 "mob_mi_map_area" => array("ids" => $a_rec["Id"] ?? null),
284 "mob_mi_parameter" => array("ids" => $a_rec["Id"] ?? null)
285 );
286 }
287 return [];
288 }
289
290 public function getXmlRecord(
291 string $a_entity,
292 string $a_version,
293 array $a_set
294 ): array {
295 if ($a_entity == "mob") {
296 $dir = ilObjMediaObject::_getDirectory($a_set["Id"]);
297 if (!is_dir($dir)) {
299 }
300 $a_set["Dir"] = $dir;
301 }
302
303 return $a_set;
304 }
305
306 public function importRecord(
307 string $a_entity,
308 array $a_types,
309 array $a_rec,
310 ilImportMapping $a_mapping,
311 string $a_schema_version
312 ): void {
313 $a_rec = $this->stripTags($a_rec);
314 switch ($a_entity) {
315 case "mob":
316
317 $newObj = new ilObjMediaObject();
318 $newObj->setType("mob");
319 $newObj->setTitle($a_rec["Title"]);
320 $newObj->setDescription($a_rec["Description"]);
321 // on translation re-import we are interested in the "previous" import id
322 if ($this->getUsePreviousImportIds()) {
323 $newObj->setImportId($a_rec["ImportId"]);
324 } else {
325 $newObj->setImportId("il_" . $this->getCurrentInstallationId() . "_mob_" . $a_rec["Id"]);
326 }
327 $newObj->create();
328 $newObj->createDirectory();
330 $this->current_mob = $newObj;
331
332 $dir = str_replace("..", "", $a_rec["Dir"]);
333 if ($dir != "" && $this->getImportDirectory() != "") {
334 $source_dir = $this->getImportDirectory() . "/" . $dir;
335 $target_dir = $dir = ilObjMediaObject::_getDirectory($newObj->getId());
336 $this->mob_log->debug("s:-$source_dir-,t:-$target_dir-");
337 ilFileUtils::rCopy($source_dir, $target_dir);
339 ilMediaSvgSanitizer::sanitizeDir($target_dir); // see #20339
340 }
341
342 $a_mapping->addMapping("Services/MediaObjects", "mob", $a_rec["Id"], $newObj->getId());
343 $a_mapping->addMapping(
344 "Services/MetaData",
345 "md",
346 "0:" . $a_rec["Id"] . ":mob",
347 "0:" . $newObj->getId() . ":mob"
348 );
349 break;
350
351 case "mob_media_item":
352
353 // determine parent mob
354 $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
355 if (is_object($this->current_mob) && $this->current_mob->getId() == $mob_id) {
356 $mob = $this->current_mob;
357 } else {
358 $mob = new ilObjMediaObject($mob_id);
359 }
360
361 $newObj = new ilMediaItem();
362 $newObj->setMobId($mob_id);
363 $newObj->setWidth($a_rec["Width"]);
364 $newObj->setHeight($a_rec["Height"]);
365 $newObj->setCaption($a_rec["Caption"]);
366 $newObj->setNr($a_rec["Nr"]);
367 $newObj->setPurpose($a_rec["Purpose"]);
368 $newObj->setLocation($a_rec["Location"]);
369 $newObj->setLocationType($a_rec["LocationType"]);
370 $newObj->setFormat($a_rec["Format"]);
371 $newObj->setTextRepresentation($a_rec["TextRepresentation"]);
372 $newObj->create();
373 $this->current_media_item = $newObj;
374
375 $a_mapping->addMapping("Services/MediaObjects", "mob_media_item", $a_rec["Id"], $newObj->getId());
376
377 break;
378
379 case "mob_mi_parameter":
380
381 // get media item
382 $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
383 if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id) {
384 $med = $this->current_media_item;
385 } else {
386 $med = new ilMediaItem($med_id);
387 }
388 $med->writeParameter($a_rec["Name"], $a_rec["Value"]);
389
390 break;
391
392 case "mob_mi_map_area":
393 // get media item
394 $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
395 if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id) {
396 $med = $this->current_media_item;
397 } else {
398 $med = new ilMediaItem($med_id);
399 }
400
401 $map_area = new ilMapArea();
402 $map_area->setItemId($med_id);
403 $map_area->setNr($a_rec["Nr"]);
404 $map_area->setShape($a_rec["Shape"]);
405 $map_area->setCoords($a_rec["Coords"]);
406 $map_area->setLinkType($a_rec["LinkType"]);
407 $map_area->setTitle($a_rec["Title"]);
408 $map_area->setHref($a_rec["Href"]);
409 $map_area->setTarget($a_rec["Target"]);
410 $map_area->setType($a_rec["Type"]);
411 $map_area->setTargetFrame($a_rec["TargetFrame"]);
412 $map_area->setHighlightMode($a_rec["HighlightMode"]);
413 $map_area->setHighlightClass($a_rec["HighlightClass"]);
414 $map_area->create();
415 break;
416 }
417 }
418}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
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 getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Class ilMapArea.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlNamespace(string $a_entity, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
getXmlRecord(string $a_entity, string $a_version, array $a_set)
Get xml record for version.
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
Determine the dependent sets of data.
setUsePreviousImportIds(bool $a_val)
Set use previous import ids.
static sanitizeDir(string $a_path)
Sanitize directory recursively.
static _createThumbnailDirectory(int $a_obj_id)
Create thumbnail directory.
static renameExecutables(string $a_dir)
static _getDirectory(int $a_mob_id)
Get absolute directory.
static _lookupType(int $id, bool $reference=false)
static _lookupImportId(int $obj_id)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
static insertInstIntoID(string $a_value)
inserts installation id into ILIAS id
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
$ref_id
Definition: ltiauth.php:67
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc