ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilMediaObjectDataSet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/DataSet/classes/class.ilDataSet.php");
5
20{
21 protected $use_previous_import_ids = false;
22
28 function setUsePreviousImportIds($a_val)
29 {
30 $this->use_previous_import_ids = $a_val;
31 }
32
39 {
41 }
42
49 public function getSupportedVersions()
50 {
51 return array("5.1.0", "4.3.0", "4.1.0");
52 }
53
60 function getXmlNamespace($a_entity, $a_schema_version)
61 {
62 return "http://www.ilias.de/xml/Services/MediaObject/".$a_entity;
63 }
64
71 protected function getTypes($a_entity, $a_version)
72 {
73 // mob
74 if ($a_entity == "mob")
75 {
76 switch ($a_version)
77 {
78 case "4.1.0":
79 case "4.3.0":
80 return array(
81 "Id" => "integer",
82 "Title" => "text",
83 "Description" => "text",
84 "Dir" => "directory"
85 );
86
87 case "5.1.0":
88 return array(
89 "Id" => "integer",
90 "Title" => "text",
91 "Description" => "text",
92 "Dir" => "directory",
93 "ImportId" => "text"
94 );
95 }
96 }
97
98 // media item
99 if ($a_entity == "mob_media_item")
100 {
101 switch ($a_version)
102 {
103 case "4.1.0":
104 return array(
105 "Id" => "integer",
106 "MobId" => "integer",
107 "Width" => "integer",
108 "Height" => "integer",
109 "Halign" => "text",
110 "Caption" => "text",
111 "Nr" => "integer",
112 "Purpose" => "text",
113 "Location" => "text",
114 "LocationType" => "text",
115 "Format" => "text",
116 "TextRepresentation" => "text"
117 );
118
119 case "4.3.0":
120 case "5.1.0":
121 return array(
122 "Id" => "integer",
123 "MobId" => "integer",
124 "Width" => "integer",
125 "Height" => "integer",
126 "Halign" => "text",
127 "Caption" => "text",
128 "Nr" => "integer",
129 "Purpose" => "text",
130 "Location" => "text",
131 "LocationType" => "text",
132 "Format" => "text",
133 "TextRepresentation" => "text"
134 );
135 }
136 }
137
138 // map areas
139 if ($a_entity == "mob_mi_map_area")
140 {
141 switch ($a_version)
142 {
143 case "4.1.0":
144 case "4.3.0":
145 case "5.1.0":
146 return array(
147 "MiId" => "integer",
148 "Nr" => "integer",
149 "Shape" => "text",
150 "Coords" => "text",
151 "LinkType" => "text",
152 "Title" => "text",
153 "Href" => "text",
154 "Target" => "text",
155 "Type" => "text",
156 "TargetFrame" => "text",
157 "HighlightMode" => "text",
158 "HighlightText" => "text"
159 );
160 }
161 }
162
163 // media item parameter
164 if ($a_entity == "mob_mi_parameter")
165 {
166 switch ($a_version)
167 {
168 case "4.1.0":
169 case "4.3.0":
170 case "5.1.0":
171 return array(
172 "MiId" => "integer",
173 "Name" => "text",
174 "Value" => "text"
175 );
176 }
177 }
178 }
179
186 function readData($a_entity, $a_version, $a_ids, $a_field = "")
187 {
188 global $ilDB;
189
190 if (!is_array($a_ids))
191 {
192 $a_ids = array($a_ids);
193 }
194
195 // mob
196 if ($a_entity == "mob")
197 {
198 $this->data = array();
199
200 switch ($a_version)
201 {
202 case "4.1.0":
203 case "4.3.0":
204 foreach ($a_ids as $mob_id)
205 {
206 if (ilObject::_lookupType($mob_id) == "mob")
207 {
208 $this->data[] = array ("Id" => $mob_id,
209 "Title" => ilObject::_lookupTitle($mob_id),
210 "Description" => ilObject::_lookupDescription($mob_id)
211 );
212 }
213 }
214 break;
215
216 case "5.1.0":
217 foreach ($a_ids as $mob_id)
218 {
219 if (ilObject::_lookupType($mob_id) == "mob")
220 {
221 $this->data[] = array ("Id" => $mob_id,
222 "Title" => ilObject::_lookupTitle($mob_id),
223 "Description" => ilObject::_lookupDescription($mob_id),
224 "ImportId" => ilObject::_lookupImportId($mob_id)
225 );
226 }
227 }
228 break;
229 }
230 }
231
232 // media item
233 if ($a_entity == "mob_media_item")
234 {
235 switch ($a_version)
236 {
237 case "4.1.0":
238 $this->getDirectDataFromQuery("SELECT id, mob_id, width, height, halign,".
239 "caption, nr, purpose, location, location_type, format, text_representation".
240 " FROM media_item WHERE ".
241 $ilDB->in("mob_id", $a_ids, false, "integer"));
242 break;
243
244 case "4.3.0":
245 case "5.1.0":
246 $this->getDirectDataFromQuery("SELECT id, mob_id, width, height, halign,".
247 "caption, nr, purpose, location, location_type, format, text_representation".
248 " FROM media_item WHERE ".
249 $ilDB->in("mob_id", $a_ids, false, "integer"));
250 break;
251 }
252 }
253
254
255 // media item map area
256 if ($a_entity == "mob_mi_map_area")
257 {
258 switch ($a_version)
259 {
260 case "4.1.0":
261 case "4.3.0":
262 case "5.1.0":
263 foreach ($this->getDirectDataFromQuery("SELECT item_id mi_id, nr".
264 " ,shape, coords, link_type, title, href, target, type, target_frame, ".
265 " highlight_mode, highlight_class".
266 " FROM map_area ".
267 " WHERE ".
268 $ilDB->in("item_id", $a_ids, false, "integer").
269 " ORDER BY nr", true, false) as $r)
270 {
271 $r["Target"] = ilUtil::insertInstIntoID($r["Target"]);
272
273 // see ilPageObject::insertInstIntoIDs
274 if ($r["Type"] == "RepositoryItem")
275 {
276 $id_arr = explode("_", $r["Target"]);
277 $ref_id = $id_arr[3];
278 $obj_id = ilObject::_lookupObjId($id_arr[3]);
279
280 $otype = ilObject::_lookupType($obj_id);
281 if ($obj_id > 0)
282 {
283 $id = $otype."_".$obj_id."_".$ref_id;
284 $r["Target"] = "il_".$id_arr[1]."_".$id;
285 }
286 }
287
288 $this->data[] = $r;
289 }
290 break;
291 }
292 }
293
294 // media item parameter
295 if ($a_entity == "mob_mi_parameter")
296 {
297 switch ($a_version)
298 {
299 case "4.1.0":
300 case "4.3.0":
301 case "5.1.0":
302 $this->getDirectDataFromQuery("SELECT med_item_id mi_id, name, value".
303 " FROM mob_parameter ".
304 " WHERE ".
305 $ilDB->in("med_item_id", $a_ids, false, "integer"));
306 break;
307 }
308 }
309
310 }
311
315 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
316 {
317 switch ($a_entity)
318 {
319 case "mob":
320 return array (
321 "mob_media_item" => array("ids" => $a_rec["Id"])
322 );
323
324 case "mob_media_item":
325 return array (
326 "mob_mi_map_area" => array("ids" => $a_rec["Id"]),
327 "mob_mi_parameter" => array("ids" => $a_rec["Id"])
328 );
329 }
330 return false;
331 }
332
339 function getXmlRecord($a_entity, $a_version, $a_set)
340 {
341 if ($a_entity == "mob")
342 {
343 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
344 $dir = ilObjMediaObject::_getDirectory($a_set["Id"]);
345 $a_set["Dir"] = $dir;
346 }
347
348 return $a_set;
349 }
350
357 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
358 {
359//echo $a_entity;
360//var_dump($a_rec);
361
362 switch ($a_entity)
363 {
364 case "mob":
365
366//var_dump($a_rec);
367
368 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
369 $newObj = new ilObjMediaObject();
370 $newObj->setType("mob");
371 $newObj->setTitle($a_rec["Title"]);
372 $newObj->setDescription($a_rec["Description"]);
373 // on translation re-import we are interested in the "previous" import id
374 if ($this->getUsePreviousImportIds())
375 {
376 $newObj->setImportId($a_rec["ImportId"]);
377 }
378 else
379 {
380 $newObj->setImportId("il_".$this->getCurrentInstallationId()."_mob_".$a_rec["Id"]);
381 }
382 $newObj->create();
383 $newObj->createDirectory();
385 $this->current_mob = $newObj;
386
387 $dir = str_replace("..", "", $a_rec["Dir"]);
388 if ($dir != "" && $this->getImportDirectory() != "")
389 {
390 $source_dir = $this->getImportDirectory()."/".$dir;
391 $target_dir = $dir = ilObjMediaObject::_getDirectory($newObj->getId());
392 ilUtil::rCopy($source_dir, $target_dir);
394 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
395 ilMediaSvgSanitizer::sanitizeDir($target_dir); // see #20339
396 }
397
398 $a_mapping->addMapping("Services/MediaObjects", "mob", $a_rec["Id"], $newObj->getId());
399//echo "<br>++add++"."0:".$a_rec["Id"].":mob+0:".$newObj->getId().":mob"."+";
400 $a_mapping->addMapping("Services/MetaData", "md",
401 "0:".$a_rec["Id"].":mob", "0:".$newObj->getId().":mob");
402 break;
403
404 case "mob_media_item":
405
406 // determine parent mob
407 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
408 $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
409 if (is_object($this->current_mob) && $this->current_mob->getId() == $mob_id)
410 {
411 $mob = $this->current_mob;
412 }
413 else
414 {
415 $mob = new ilObjMediaObject($mob_id);
416 }
417
418 include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
419 $newObj = new ilMediaItem();
420 $newObj->setMobId($mob_id);
421 $newObj->setWidth($a_rec["Width"]);
422 $newObj->setHeight($a_rec["Height"]);
423 $newObj->setCaption($a_rec["Caption"]);
424 $newObj->setNr($a_rec["Nr"]);
425 $newObj->setPurpose($a_rec["Purpose"]);
426 $newObj->setLocation($a_rec["Location"]);
427 $newObj->setLocationType($a_rec["LocationType"]);
428 $newObj->setFormat($a_rec["Format"]);
429 $newObj->setTextRepresentation($a_rec["TextRepresentation"]);
430 $newObj->create();
431 $this->current_media_item = $newObj;
432
433 $a_mapping->addMapping("Services/MediaObjects", "mob_media_item", $a_rec["Id"], $newObj->getId());
434
435 break;
436
437 case "mob_mi_parameter":
438
439 // get media item
440 include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
441 $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
442 if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id)
443 {
444 $med = $this->current_media_item;
445 }
446 else
447 {
448 $med = new ilMediaItem($med_id);
449 }
450 $med->writeParameter($a_rec["Name"], $a_rec["Value"]);
451
452 break;
453
454 case "mob_mi_map_area":
455 // get media item
456 include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
457 $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
458 if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id)
459 {
460 $med = $this->current_media_item;
461 }
462 else
463 {
464 $med = new ilMediaItem($med_id);
465 }
466
467 include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
468 $map_area = new ilMapArea();
469 $map_area->setItemId($med_id);
470 $map_area->setNr($a_rec["Nr"]);
471 $map_area->setShape($a_rec["Shape"]);
472 $map_area->setCoords($a_rec["Coords"]);
473 $map_area->setLinkType($a_rec["LinkType"]);
474 $map_area->setTitle($a_rec["Title"]);
475 $map_area->setHref($a_rec["Href"]);
476 $map_area->setTarget($a_rec["Target"]);
477 $map_area->setType($a_rec["Type"]);
478 $map_area->setTargetFrame($a_rec["TargetFrame"]);
479 $map_area->setHighlightMode($a_rec["HighlightMode"]);
480 $map_area->setHighlightClass($a_rec["HighlightClass"]);
481 $map_area->create();
482
483 break;
484 }
485 }
486
487}
488?>
An exception for terminatinating execution or to throw for unit testing.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
getImportDirectory()
Get import directory.
getCurrentInstallationId()
Get current installation id.
Class ilMapArea.
Class ilMediaItem.
Media Pool Data set class.
getTypes($a_entity, $a_version)
Get field types for entity.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
setUsePreviousImportIds($a_val)
Set use previous import ids.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getUsePreviousImportIds()
Get use previous import ids.
getSupportedVersions()
Get supported versions.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
static sanitizeDir($a_path)
Sanitize directory recursively.
Class ilObjMediaObject.
static _getDirectory($a_mob_id)
get directory for files of media object (static)
static _createThumbnailDirectory($a_obj_id)
Create thumbnail directory.
static renameExecutables($a_dir)
Rename executables.
static _lookupObjId($a_id)
static _lookupImportId($a_obj_id)
static _lookupTitle($a_id)
lookup object title
static _lookupDescription($a_id)
lookup object description
static _lookupType($a_id, $a_reference=false)
lookup object type
static insertInstIntoID($a_value)
inserts installation id into ILIAS id
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
$r
Definition: example_031.php:79
$ref_id
Definition: sahs_server.php:39
global $ilDB