ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
20 {
27  public function getSupportedVersions()
28  {
29  return array("4.3.0", "4.1.0");
30  }
31 
38  function getXmlNamespace($a_entity, $a_schema_version)
39  {
40  return "http://www.ilias.de/xml/Services/MediaObject/".$a_entity;
41  }
42 
49  protected function getTypes($a_entity, $a_version)
50  {
51  // mob
52  if ($a_entity == "mob")
53  {
54  switch ($a_version)
55  {
56  case "4.1.0":
57  case "4.3.0":
58  return array(
59  "Id" => "integer",
60  "Title" => "text",
61  "Description" => "text",
62  "Dir" => "directory"
63  );
64  }
65  }
66 
67  // media item
68  if ($a_entity == "mob_media_item")
69  {
70  switch ($a_version)
71  {
72  case "4.1.0":
73  return array(
74  "Id" => "integer",
75  "MobId" => "integer",
76  "Width" => "integer",
77  "Height" => "integer",
78  "Halign" => "text",
79  "Caption" => "text",
80  "Nr" => "integer",
81  "Purpose" => "text",
82  "Location" => "text",
83  "LocationType" => "text",
84  "Format" => "text",
85  "TextRepresentation" => "text"
86  );
87 
88  case "4.3.0":
89  return array(
90  "Id" => "integer",
91  "MobId" => "integer",
92  "Width" => "integer",
93  "Height" => "integer",
94  "Halign" => "text",
95  "Caption" => "text",
96  "Nr" => "integer",
97  "Purpose" => "text",
98  "Location" => "text",
99  "LocationType" => "text",
100  "Format" => "text",
101  "TextRepresentation" => "text"
102  );
103  }
104  }
105 
106  // map areas
107  if ($a_entity == "mob_mi_map_area")
108  {
109  switch ($a_version)
110  {
111  case "4.1.0":
112  case "4.3.0":
113  return array(
114  "MiId" => "integer",
115  "Nr" => "integer",
116  "Shape" => "text",
117  "Coords" => "text",
118  "LinkType" => "text",
119  "Title" => "text",
120  "Href" => "text",
121  "Target" => "text",
122  "Type" => "text",
123  "TargetFrame" => "text",
124  "HighlightMode" => "text",
125  "HighlightText" => "text"
126  );
127  }
128  }
129 
130  // media item parameter
131  if ($a_entity == "mob_mi_parameter")
132  {
133  switch ($a_version)
134  {
135  case "4.1.0":
136  case "4.3.0":
137  return array(
138  "MiId" => "integer",
139  "Name" => "text",
140  "Value" => "text"
141  );
142  }
143  }
144  }
145 
152  function readData($a_entity, $a_version, $a_ids, $a_field = "")
153  {
154  global $ilDB;
155 
156  if (!is_array($a_ids))
157  {
158  $a_ids = array($a_ids);
159  }
160 
161  // mob
162  if ($a_entity == "mob")
163  {
164  $this->data = array();
165 
166  foreach ($a_ids as $mob_id)
167  {
168  if (ilObject::_lookupType($mob_id) == "mob")
169  {
170  $this->data[] = array ("Id" => $mob_id,
171  "Title" => ilObject::_lookupTitle($mob_id),
172  "Description" => ilObject::_lookupDescription($mob_id));
173  }
174  }
175  }
176 
177  // media item
178  if ($a_entity == "mob_media_item")
179  {
180  switch ($a_version)
181  {
182  case "4.1.0":
183  $this->getDirectDataFromQuery("SELECT id, mob_id, width, height, halign,".
184  "caption, nr, purpose, location, location_type, format, text_representation".
185  " FROM media_item WHERE ".
186  $ilDB->in("mob_id", $a_ids, false, "integer"));
187  break;
188 
189  case "4.3.0":
190  $this->getDirectDataFromQuery("SELECT id, mob_id, width, height, halign,".
191  "caption, nr, purpose, location, location_type, format, text_representation".
192  " FROM media_item WHERE ".
193  $ilDB->in("mob_id", $a_ids, false, "integer"));
194  break;
195  }
196  }
197 
198 
199  // media item map area
200  if ($a_entity == "mob_mi_map_area")
201  {
202  switch ($a_version)
203  {
204  case "4.1.0":
205  case "4.3.0":
206  $this->getDirectDataFromQuery("SELECT item_id mi_id, nr".
207  " ,shape, coords, link_type, title, href, target, type, target_frame, ".
208  " highlight_mode, highlight_class".
209  " FROM map_area ".
210  " WHERE ".
211  $ilDB->in("item_id", $a_ids, false, "integer").
212  " ORDER BY nr");
213  break;
214  }
215  }
216 
217  // media item parameter
218  if ($a_entity == "mob_mi_parameter")
219  {
220  switch ($a_version)
221  {
222  case "4.1.0":
223  case "4.3.0":
224  $this->getDirectDataFromQuery("SELECT med_item_id mi_id, name, value".
225  " FROM mob_parameter ".
226  " WHERE ".
227  $ilDB->in("med_item_id", $a_ids, false, "integer"));
228  break;
229  }
230  }
231 
232  }
233 
237  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
238  {
239  switch ($a_entity)
240  {
241  case "mob":
242  return array (
243  "mob_media_item" => array("ids" => $a_rec["Id"])
244  );
245 
246  case "mob_media_item":
247  return array (
248  "mob_mi_map_area" => array("ids" => $a_rec["Id"]),
249  "mob_mi_parameter" => array("ids" => $a_rec["Id"])
250  );
251  }
252  return false;
253  }
254 
261  function getXmlRecord($a_entity, $a_version, $a_set)
262  {
263  if ($a_entity == "mob")
264  {
265  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
266  $dir = ilObjMediaObject::_getDirectory($a_set["Id"]);
267  $a_set["Dir"] = $dir;
268  }
269 
270  return $a_set;
271  }
272 
279  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
280  {
281 //echo $a_entity;
282 //var_dump($a_rec);
283 
284  switch ($a_entity)
285  {
286  case "mob":
287 
288 //var_dump($a_rec);
289 
290  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
291  $newObj = new ilObjMediaObject();
292  $newObj->setType("mob");
293  $newObj->setTitle($a_rec["Title"]);
294  $newObj->setDescription($a_rec["Description"]);
295  $newObj->create();
296  $newObj->createDirectory();
298  $this->current_mob = $newObj;
299 
300  $dir = str_replace("..", "", $a_rec["Dir"]);
301  if ($dir != "" && $this->getImportDirectory() != "")
302  {
303  $source_dir = $this->getImportDirectory()."/".$dir;
304  $target_dir = $dir = ilObjMediaObject::_getDirectory($newObj->getId());
305  ilUtil::rCopy($source_dir, $target_dir);
306  }
307 
308  $a_mapping->addMapping("Services/MediaObjects", "mob", $a_rec["Id"], $newObj->getId());
309 //echo "<br>++add++"."0:".$a_rec["Id"].":mob+0:".$newObj->getId().":mob"."+";
310  $a_mapping->addMapping("Services/MetaData", "md",
311  "0:".$a_rec["Id"].":mob", "0:".$newObj->getId().":mob");
312  break;
313 
314  case "mob_media_item":
315 
316  // determine parent mob
317  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
318  $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
319  if (is_object($this->current_mob) && $this->current_mob->getId() == $mob_id)
320  {
321  $mob = $this->current_mob;
322  }
323  else
324  {
325  $mob = new ilObjMediaObject($mob_id);
326  }
327 
328  include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
329  $newObj = new ilMediaItem();
330  $newObj->setMobId($mob_id);
331  $newObj->setWidth($a_rec["Width"]);
332  $newObj->setHeight($a_rec["Height"]);
333  $newObj->setCaption($a_rec["Caption"]);
334  $newObj->setNr($a_rec["Nr"]);
335  $newObj->setPurpose($a_rec["Purpose"]);
336  $newObj->setLocation($a_rec["Location"]);
337  $newObj->setLocationType($a_rec["LocationType"]);
338  $newObj->setFormat($a_rec["Format"]);
339  $newObj->setTextRepresentation($a_rec["TextRepresentation"]);
340  $newObj->create();
341  $this->current_media_item = $newObj;
342 
343  $a_mapping->addMapping("Services/MediaObjects", "mob_media_item", $a_rec["Id"], $newObj->getId());
344 
345  break;
346 
347  case "mob_mi_parameter":
348 
349  // get media item
350  include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
351  $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
352  if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id)
353  {
354  $med = $this->current_media_item;
355  }
356  else
357  {
358  $med = new ilMediaItem($med_id);
359  }
360  $med->writeParameter($a_rec["Name"], $a_rec["Value"]);
361 
362  break;
363 
364  case "mob_mi_map_area":
365  // get media item
366  include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
367  $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
368  if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id)
369  {
370  $med = $this->current_media_item;
371  }
372  else
373  {
374  $med = new ilMediaItem($med_id);
375  }
376 
377  include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
378  $map_area = new ilMapArea();
379  $map_area->setItemId($med_id);
380  $map_area->setNr($a_rec["Nr"]);
381  $map_area->setShape($a_rec["Shape"]);
382  $map_area->setCoords($a_rec["Coords"]);
383  $map_area->setLinkType($a_rec["LinkType"]);
384  $map_area->setTitle($a_rec["Title"]);
385  $map_area->setHref($a_rec["Href"]);
386  $map_area->setTarget($a_rec["Target"]);
387  $map_area->setType($a_rec["Type"]);
388  $map_area->setTargetFrame($a_rec["TargetFrame"]);
389  $map_area->setHighlightMode($a_rec["HighlightMode"]);
390  $map_area->setHighlightClass($a_rec["HighlightClass"]);
391  $map_area->create();
392 
393  break;
394  }
395  }
396 
397 }
398 ?>