ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  // map areas
120  if ($a_entity == "mob_mi_map_area") {
121  switch ($a_version) {
122  case "4.1.0":
123  case "4.3.0":
124  case "5.1.0":
125  return array(
126  "MiId" => "integer",
127  "Nr" => "integer",
128  "Shape" => "text",
129  "Coords" => "text",
130  "LinkType" => "text",
131  "Title" => "text",
132  "Href" => "text",
133  "Target" => "text",
134  "Type" => "text",
135  "TargetFrame" => "text",
136  "HighlightMode" => "text",
137  "HighlightText" => "text"
138  );
139  }
140  }
141 
142  // media item parameter
143  if ($a_entity == "mob_mi_parameter") {
144  switch ($a_version) {
145  case "4.1.0":
146  case "4.3.0":
147  case "5.1.0":
148  return array(
149  "MiId" => "integer",
150  "Name" => "text",
151  "Value" => "text"
152  );
153  }
154  }
155  return [];
156  }
157 
158  public function readData(
159  string $a_entity,
160  string $a_version,
161  array $a_ids
162  ): void {
163  $ilDB = $this->db;
164 
165  if (!is_array($a_ids)) {
166  $a_ids = array($a_ids);
167  }
168 
169  // mob
170  if ($a_entity == "mob") {
171  $this->data = array();
172 
173  switch ($a_version) {
174  case "4.1.0":
175  case "4.3.0":
176  foreach ($a_ids as $mob_id) {
177  if (ilObject::_lookupType($mob_id) == "mob") {
178  $this->data[] = array("Id" => $mob_id,
179  "Title" => ilObject::_lookupTitle($mob_id),
180  "Description" => ilObject::_lookupDescription($mob_id)
181  );
182  }
183  }
184  break;
185 
186  case "5.1.0":
187  foreach ($a_ids as $mob_id) {
188  if (ilObject::_lookupType($mob_id) == "mob") {
189  $this->data[] = array("Id" => $mob_id,
190  "Title" => ilObject::_lookupTitle($mob_id),
191  "Description" => ilObject::_lookupDescription($mob_id),
192  "ImportId" => ilObject::_lookupImportId($mob_id)
193  );
194  }
195  }
196  break;
197  }
198  }
199 
200  // media item
201  if ($a_entity == "mob_media_item") {
202  switch ($a_version) {
203  case "5.1.0":
204  case "4.3.0":
205  case "4.1.0":
206  $this->getDirectDataFromQuery("SELECT id, mob_id, width, height, halign," .
207  "caption, nr, purpose, location, location_type, format, text_representation" .
208  " FROM media_item WHERE " .
209  $ilDB->in("mob_id", $a_ids, false, "integer"));
210  break;
211  }
212  }
213 
214 
215  // media item map area
216  if ($a_entity == "mob_mi_map_area") {
217  switch ($a_version) {
218  case "4.1.0":
219  case "4.3.0":
220  case "5.1.0":
221  foreach ($this->getDirectDataFromQuery("SELECT item_id mi_id, nr" .
222  " ,shape, coords, link_type, title, href, target, type, target_frame, " .
223  " highlight_mode, highlight_class" .
224  " FROM map_area " .
225  " WHERE " .
226  $ilDB->in("item_id", $a_ids, false, "integer") .
227  " ORDER BY nr", true, false) as $r) {
228  $r["Target"] = ilUtil::insertInstIntoID((string) ($r["Target"] ?? ""));
229 
230  // see ilPageObject::insertInstIntoIDs
231  if ($r["Type"] == "RepositoryItem") {
232  $id_arr = explode("_", $r["Target"]);
233  $ref_id = $id_arr[3];
234  $obj_id = ilObject::_lookupObjId($id_arr[3]);
235 
236  $otype = ilObject::_lookupType($obj_id);
237  if ($obj_id > 0) {
238  $id = $otype . "_" . $obj_id . "_" . $ref_id;
239  $r["Target"] = "il_" . $id_arr[1] . "_" . $id;
240  }
241  }
242 
243  $this->data[] = $r;
244  }
245  break;
246  }
247  }
248 
249  // media item parameter
250  if ($a_entity == "mob_mi_parameter") {
251  switch ($a_version) {
252  case "4.1.0":
253  case "4.3.0":
254  case "5.1.0":
255  $this->getDirectDataFromQuery("SELECT med_item_id mi_id, name, value" .
256  " FROM mob_parameter " .
257  " WHERE " .
258  $ilDB->in("med_item_id", $a_ids, false, "integer"));
259  break;
260  }
261  }
262  }
263 
267  protected function getDependencies(
268  string $a_entity,
269  string $a_version,
270  ?array $a_rec = null,
271  ?array $a_ids = null
272  ): array {
273  switch ($a_entity) {
274  case "mob":
275  return array(
276  "mob_media_item" => array("ids" => $a_rec["Id"] ?? null)
277  );
278 
279  case "mob_media_item":
280  return array(
281  "mob_mi_map_area" => array("ids" => $a_rec["Id"] ?? null),
282  "mob_mi_parameter" => array("ids" => $a_rec["Id"] ?? null)
283  );
284  }
285  return [];
286  }
287 
288  public function getXmlRecord(
289  string $a_entity,
290  string $a_version,
291  array $a_set
292  ): array {
293  if ($a_entity == "mob") {
294  $dir = ilObjMediaObject::_getDirectory($a_set["Id"]);
295  if (!is_dir($dir)) {
297  }
298  $a_set["Dir"] = $dir;
299  }
300 
301  return $a_set;
302  }
303 
304  public function importRecord(
305  string $a_entity,
306  array $a_types,
307  array $a_rec,
308  ilImportMapping $a_mapping,
309  string $a_schema_version
310  ): void {
311  $a_rec = $this->stripTags($a_rec);
312  switch ($a_entity) {
313  case "mob":
314 
315  $newObj = new ilObjMediaObject();
316  $newObj->setType("mob");
317  $newObj->setTitle($a_rec["Title"]);
318  $newObj->setDescription($a_rec["Description"]);
319  // on translation re-import we are interested in the "previous" import id
320  if ($this->getUsePreviousImportIds()) {
321  $newObj->setImportId($a_rec["ImportId"]);
322  } else {
323  $newObj->setImportId("il_" . $this->getCurrentInstallationId() . "_mob_" . $a_rec["Id"]);
324  }
325  $newObj->create();
326  $newObj->createDirectory();
328  $this->current_mob = $newObj;
329 
330  $dir = str_replace("..", "", $a_rec["Dir"]);
331  if ($dir != "" && $this->getImportDirectory() != "") {
332  $source_dir = $this->getImportDirectory() . "/" . $dir;
333  $target_dir = $dir = ilObjMediaObject::_getDirectory($newObj->getId());
334  $this->mob_log->debug("s:-$source_dir-,t:-$target_dir-");
335  ilFileUtils::rCopy($source_dir, $target_dir);
337  ilMediaSvgSanitizer::sanitizeDir($target_dir); // see #20339
338  }
339 
340  $a_mapping->addMapping("Services/MediaObjects", "mob", $a_rec["Id"], $newObj->getId());
341  $a_mapping->addMapping(
342  "Services/MetaData",
343  "md",
344  "0:" . $a_rec["Id"] . ":mob",
345  "0:" . $newObj->getId() . ":mob"
346  );
347  break;
348 
349  case "mob_media_item":
350 
351  // determine parent mob
352  $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
353  if (is_object($this->current_mob) && $this->current_mob->getId() == $mob_id) {
354  $mob = $this->current_mob;
355  } else {
356  $mob = new ilObjMediaObject($mob_id);
357  }
358 
359  $newObj = new ilMediaItem();
360  $newObj->setMobId($mob_id);
361  $newObj->setWidth($a_rec["Width"]);
362  $newObj->setHeight($a_rec["Height"]);
363  $newObj->setCaption($a_rec["Caption"]);
364  $newObj->setNr($a_rec["Nr"]);
365  $newObj->setPurpose($a_rec["Purpose"]);
366  $newObj->setLocation($a_rec["Location"]);
367  $newObj->setLocationType($a_rec["LocationType"]);
368  $newObj->setFormat($a_rec["Format"]);
369  $newObj->setTextRepresentation($a_rec["TextRepresentation"]);
370  $newObj->create();
371  $this->current_media_item = $newObj;
372 
373  $a_mapping->addMapping("Services/MediaObjects", "mob_media_item", $a_rec["Id"], $newObj->getId());
374 
375  break;
376 
377  case "mob_mi_parameter":
378 
379  // get media item
380  $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
381  if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id) {
383  } else {
384  $med = new ilMediaItem($med_id);
385  }
386  $med->writeParameter($a_rec["Name"], $a_rec["Value"]);
387 
388  break;
389 
390  case "mob_mi_map_area":
391  // get media item
392  $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
393  if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id) {
395  } else {
396  $med = new ilMediaItem($med_id);
397  }
398 
399  $map_area = new ilMapArea();
400  $map_area->setItemId($med_id);
401  $map_area->setNr($a_rec["Nr"]);
402  $map_area->setShape($a_rec["Shape"]);
403  $map_area->setCoords($a_rec["Coords"]);
404  $map_area->setLinkType($a_rec["LinkType"]);
405  $map_area->setTitle($a_rec["Title"]);
406  $map_area->setHref($a_rec["Href"]);
407  $map_area->setTarget($a_rec["Target"]);
408  $map_area->setType($a_rec["Type"]);
409  $map_area->setTargetFrame($a_rec["TargetFrame"]);
410  $map_area->setHighlightMode($a_rec["HighlightMode"]);
411  $map_area->setHighlightClass($a_rec["HighlightClass"]);
412  $map_area->create();
413  break;
414  }
415  }
416 }
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
static sanitizeDir(string $a_path)
Sanitize directory recursively.
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _createThumbnailDirectory(int $a_obj_id)
Create thumbnail directory.
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static renameExecutables(string $a_dir)
static _lookupObjId(int $ref_id)
static _lookupImportId(int $obj_id)
static _getDirectory(int $a_mob_id)
Get absolute directory.
$ref_id
Definition: ltiauth.php:67
__construct(VocabulariesInterface $vocabularies)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
ilDBInterface $db
static _lookupTitle(int $obj_id)
getXmlNamespace(string $a_entity, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCurrentInstallationId()
static _lookupDescription(int $obj_id)
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 ...
Class ilMapArea.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
Determine the dependent sets of data.
getXmlRecord(string $a_entity, string $a_version, array $a_set)
stripTags(array $rec, array $omit_keys=[])
static _lookupType(int $id, bool $reference=false)
static insertInstIntoID(string $a_value)
inserts installation id into ILIAS id
readData(string $a_entity, string $a_version, array $a_ids)
setUsePreviousImportIds(bool $a_val)
Set use previous import ids.
$r