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