ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $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");
270 break;
271 }
272 }
273
274 // media item parameter
275 if ($a_entity == "mob_mi_parameter")
276 {
277 switch ($a_version)
278 {
279 case "4.1.0":
280 case "4.3.0":
281 case "5.1.0":
282 $this->getDirectDataFromQuery("SELECT med_item_id mi_id, name, value".
283 " FROM mob_parameter ".
284 " WHERE ".
285 $ilDB->in("med_item_id", $a_ids, false, "integer"));
286 break;
287 }
288 }
289
290 }
291
295 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
296 {
297 switch ($a_entity)
298 {
299 case "mob":
300 return array (
301 "mob_media_item" => array("ids" => $a_rec["Id"])
302 );
303
304 case "mob_media_item":
305 return array (
306 "mob_mi_map_area" => array("ids" => $a_rec["Id"]),
307 "mob_mi_parameter" => array("ids" => $a_rec["Id"])
308 );
309 }
310 return false;
311 }
312
319 function getXmlRecord($a_entity, $a_version, $a_set)
320 {
321 if ($a_entity == "mob")
322 {
323 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
324 $dir = ilObjMediaObject::_getDirectory($a_set["Id"]);
325 $a_set["Dir"] = $dir;
326 }
327
328 return $a_set;
329 }
330
337 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
338 {
339//echo $a_entity;
340//var_dump($a_rec);
341
342 switch ($a_entity)
343 {
344 case "mob":
345
346//var_dump($a_rec);
347
348 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
349 $newObj = new ilObjMediaObject();
350 $newObj->setType("mob");
351 $newObj->setTitle($a_rec["Title"]);
352 $newObj->setDescription($a_rec["Description"]);
353 // on translation re-import we are interested in the "previous" import id
354 if ($this->getUsePreviousImportIds())
355 {
356 $newObj->setImportId($a_rec["ImportId"]);
357 }
358 else
359 {
360 $newObj->setImportId("il_".$this->getCurrentInstallationId()."_mob_".$a_rec["Id"]);
361 }
362 $newObj->create();
363 $newObj->createDirectory();
365 $this->current_mob = $newObj;
366
367 $dir = str_replace("..", "", $a_rec["Dir"]);
368 if ($dir != "" && $this->getImportDirectory() != "")
369 {
370 $source_dir = $this->getImportDirectory()."/".$dir;
371 $target_dir = $dir = ilObjMediaObject::_getDirectory($newObj->getId());
372 ilUtil::rCopy($source_dir, $target_dir);
374 include_once("./Services/MediaObjects/classes/class.ilMediaSvgSanitizer.php");
375 ilMediaSvgSanitizer::sanitizeDir($target_dir); // see #20339
376 }
377
378 $a_mapping->addMapping("Services/MediaObjects", "mob", $a_rec["Id"], $newObj->getId());
379//echo "<br>++add++"."0:".$a_rec["Id"].":mob+0:".$newObj->getId().":mob"."+";
380 $a_mapping->addMapping("Services/MetaData", "md",
381 "0:".$a_rec["Id"].":mob", "0:".$newObj->getId().":mob");
382 break;
383
384 case "mob_media_item":
385
386 // determine parent mob
387 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
388 $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
389 if (is_object($this->current_mob) && $this->current_mob->getId() == $mob_id)
390 {
391 $mob = $this->current_mob;
392 }
393 else
394 {
395 $mob = new ilObjMediaObject($mob_id);
396 }
397
398 include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
399 $newObj = new ilMediaItem();
400 $newObj->setMobId($mob_id);
401 $newObj->setWidth($a_rec["Width"]);
402 $newObj->setHeight($a_rec["Height"]);
403 $newObj->setCaption($a_rec["Caption"]);
404 $newObj->setNr($a_rec["Nr"]);
405 $newObj->setPurpose($a_rec["Purpose"]);
406 $newObj->setLocation($a_rec["Location"]);
407 $newObj->setLocationType($a_rec["LocationType"]);
408 $newObj->setFormat($a_rec["Format"]);
409 $newObj->setTextRepresentation($a_rec["TextRepresentation"]);
410 $newObj->create();
411 $this->current_media_item = $newObj;
412
413 $a_mapping->addMapping("Services/MediaObjects", "mob_media_item", $a_rec["Id"], $newObj->getId());
414
415 break;
416
417 case "mob_mi_parameter":
418
419 // get media item
420 include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
421 $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
422 if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id)
423 {
424 $med = $this->current_media_item;
425 }
426 else
427 {
428 $med = new ilMediaItem($med_id);
429 }
430 $med->writeParameter($a_rec["Name"], $a_rec["Value"]);
431
432 break;
433
434 case "mob_mi_map_area":
435 // get media item
436 include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
437 $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
438 if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id)
439 {
440 $med = $this->current_media_item;
441 }
442 else
443 {
444 $med = new ilMediaItem($med_id);
445 }
446
447 include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
448 $map_area = new ilMapArea();
449 $map_area->setItemId($med_id);
450 $map_area->setNr($a_rec["Nr"]);
451 $map_area->setShape($a_rec["Shape"]);
452 $map_area->setCoords($a_rec["Coords"]);
453 $map_area->setLinkType($a_rec["LinkType"]);
454 $map_area->setTitle($a_rec["Title"]);
455 $map_area->setHref($a_rec["Href"]);
456 $map_area->setTarget($a_rec["Target"]);
457 $map_area->setType($a_rec["Type"]);
458 $map_area->setTargetFrame($a_rec["TargetFrame"]);
459 $map_area->setHighlightMode($a_rec["HighlightMode"]);
460 $map_area->setHighlightClass($a_rec["HighlightClass"]);
461 $map_area->create();
462
463 break;
464 }
465 }
466
467}
468?>
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)
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.
_createThumbnailDirectory($a_obj_id)
Create thumbnail directory.
_getDirectory($a_mob_id)
get directory for files of media object (static)
static renameExecutables($a_dir)
Rename executables.
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 rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
global $ilDB