ILIAS  Release_4_2_x_branch Revision 61807
 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 
141  function readData($a_entity, $a_version, $a_ids, $a_field = "")
142  {
143  global $ilDB;
144 
145  if (!is_array($a_ids))
146  {
147  $a_ids = array($a_ids);
148  }
149 
150  // mob
151  if ($a_entity == "mob")
152  {
153  $this->data = array();
154 
155  foreach ($a_ids as $mob_id)
156  {
157  if (ilObject::_lookupType($mob_id) == "mob")
158  {
159  $this->data[] = array ("Id" => $mob_id,
160  "Title" => ilObject::_lookupTitle($mob_id),
161  "Description" => ilObject::_lookupDescription($mob_id));
162  }
163  }
164  }
165 
166  // media item
167  if ($a_entity == "mob_media_item")
168  {
169  switch ($a_version)
170  {
171  case "4.1.0":
172  $this->getDirectDataFromQuery("SELECT id, mob_id, width, height, halign,".
173  "caption, nr, purpose, location, location_type, format, text_representation".
174  " FROM media_item WHERE ".
175  $ilDB->in("mob_id", $a_ids, false, "integer"));
176  break;
177  }
178  }
179 
180 
181  // media item map area
182  if ($a_entity == "mob_mi_map_area")
183  {
184  switch ($a_version)
185  {
186  case "4.1.0":
187  $this->getDirectDataFromQuery("SELECT item_id mi_id, nr".
188  " ,shape, coords, link_type, title, href, target, type, target_frame ".
189  " FROM map_area ".
190  " WHERE ".
191  $ilDB->in("item_id", $a_ids, false, "integer").
192  " ORDER BY nr");
193  break;
194  }
195  }
196 
197  // media item parameter
198  if ($a_entity == "mob_mi_parameter")
199  {
200  switch ($a_version)
201  {
202  case "4.1.0":
203  $this->getDirectDataFromQuery("SELECT med_item_id mi_id, name, value".
204  " FROM mob_parameter ".
205  " WHERE ".
206  $ilDB->in("med_item_id", $a_ids, false, "integer"));
207  break;
208  }
209  }
210 
211  }
212 
216  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
217  {
218  switch ($a_entity)
219  {
220  case "mob":
221  return array (
222  "mob_media_item" => array("ids" => $a_rec["Id"])
223  );
224 
225  case "mob_media_item":
226  return array (
227  "mob_mi_map_area" => array("ids" => $a_rec["Id"]),
228  "mob_mi_parameter" => array("ids" => $a_rec["Id"])
229  );
230  }
231  return false;
232  }
233 
240  function getXmlRecord($a_entity, $a_version, $a_set)
241  {
242  if ($a_entity == "mob")
243  {
244  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
245  $dir = ilObjMediaObject::_getDirectory($a_set["Id"]);
246  $a_set["Dir"] = $dir;
247  }
248 
249  return $a_set;
250  }
251 
258  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
259  {
260 //echo $a_entity;
261 //var_dump($a_rec);
262 
263  switch ($a_entity)
264  {
265  case "mob":
266 
267 //var_dump($a_rec);
268 
269  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
270  $newObj = new ilObjMediaObject();
271  $newObj->setType("mob");
272  $newObj->setTitle($a_rec["Title"]);
273  $newObj->setDescription($a_rec["Description"]);
274  $newObj->create();
275  $newObj->createDirectory();
277  $this->current_mob = $newObj;
278 
279  $dir = str_replace("..", "", $a_rec["Dir"]);
280  if ($dir != "" && $this->getImportDirectory() != "")
281  {
282  $source_dir = $this->getImportDirectory()."/".$dir;
283  $target_dir = $dir = ilObjMediaObject::_getDirectory($newObj->getId());
284  ilUtil::rCopy($source_dir, $target_dir);
285  }
286 
287  $a_mapping->addMapping("Services/MediaObjects", "mob", $a_rec["Id"], $newObj->getId());
288 //echo "<br>++add++"."0:".$a_rec["Id"].":mob+0:".$newObj->getId().":mob"."+";
289  $a_mapping->addMapping("Services/MetaData", "md",
290  "0:".$a_rec["Id"].":mob", "0:".$newObj->getId().":mob");
291  break;
292 
293  case "mob_media_item":
294 
295  // determine parent mob
296  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
297  $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
298  if (is_object($this->current_mob) && $this->current_mob->getId() == $mob_id)
299  {
300  $mob = $this->current_mob;
301  }
302  else
303  {
304  $mob = new ilObjMediaObject($mob_id);
305  }
306 
307  include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
308  $newObj = new ilMediaItem();
309  $newObj->setMobId($mob_id);
310  $newObj->setWidth($a_rec["Width"]);
311  $newObj->setHeight($a_rec["Height"]);
312  $newObj->setCaption($a_rec["Caption"]);
313  $newObj->setNr($a_rec["Nr"]);
314  $newObj->setPurpose($a_rec["Purpose"]);
315  $newObj->setLocation($a_rec["Location"]);
316  $newObj->setLocationType($a_rec["LocationType"]);
317  $newObj->setFormat($a_rec["Format"]);
318  $newObj->setFormat($a_rec["Format"]);
319  $newObj->setTextRepresentation($a_rec["TextRepresentation"]);
320  $newObj->create();
321  $this->current_media_item = $newObj;
322 
323  $a_mapping->addMapping("Services/MediaObjects", "mob_media_item", $a_rec["Id"], $newObj->getId());
324 
325  break;
326 
327  case "mob_mi_parameter":
328 
329  // get media item
330  include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
331  $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
332  if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id)
333  {
334  $med = $this->current_media_item;
335  }
336  else
337  {
338  $med = new ilMediaItem($med_id);
339  }
340  $med->writeParameter($a_rec["Name"], $a_rec["Value"]);
341 
342  break;
343 
344  case "mob_mi_map_area":
345  // get media item
346  include_once("./Services/MediaObjects/classes/class.ilMediaItem.php");
347  $med_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob_media_item", $a_rec["MiId"]);
348  if (is_object($this->current_media_item) && $this->current_media_item->getId() == $med_id)
349  {
350  $med = $this->current_media_item;
351  }
352  else
353  {
354  $med = new ilMediaItem($med_id);
355  }
356 
357  include_once("./Services/MediaObjects/classes/class.ilMapArea.php");
358  $map_area = new ilMapArea();
359  $map_area->setItemId($med_id);
360  $map_area->setNr($a_rec["Nr"]);
361  $map_area->setShape($a_rec["Shape"]);
362  $map_area->setCoords($a_rec["Coords"]);
363  $map_area->setLinkType($a_rec["LinkType"]);
364  $map_area->setTitle($a_rec["Title"]);
365  $map_area->setHref($a_rec["Href"]);
366  $map_area->setTarget($a_rec["Target"]);
367  $map_area->setType($a_rec["Type"]);
368  $map_area->setTargetFrame($a_rec["TargetFrame"]);
369  $map_area->create();
370 
371  break;
372  }
373  }
374 
375 }
376 ?>