ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilMediaPoolDataSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
18 {
19  protected $master_lang_only = false;
20  protected $transl_into = false;
21  protected $transl_into_lm = null;
22  protected $transl_lang = "";
23 
30  public function getSupportedVersions()
31  {
32  return array("5.1.0", "4.1.0");
33  }
34 
41  function getXmlNamespace($a_entity, $a_schema_version)
42  {
43  return "http://www.ilias.de/xml/Modules/MediaPool/".$a_entity;
44  }
45 
51  function setMasterLanguageOnly($a_val)
52  {
53  $this->master_lang_only = $a_val;
54  }
55 
62  {
64  }
65 
72  function setTranslationImportMode($a_lm, $a_lang = "")
73  {
74  if ($a_lm != null)
75  {
76  $this->transl_into = true;
77  $this->transl_into_lm = $a_lm;
78  $this->transl_lang = $a_lang;
79  }
80  else
81  {
82  $this->transl_into = false;
83  }
84  }
85 
92  {
93  return $this->transl_into;
94  }
95 
101  function getTranslationLM()
102  {
103  return $this->transl_into_lm;
104  }
105 
112  {
113  return $this->transl_lang;
114  }
115 
122  protected function getTypes($a_entity, $a_version)
123  {
124  // mep
125  if ($a_entity == "mep")
126  {
127  switch ($a_version)
128  {
129  case "4.1.0":
130  return array(
131  "Id" => "integer",
132  "Title" => "text",
133  "Description" => "text",
134  "DefaultWidth" => "integer",
135  "DefaultHeight" => "integer");
136 
137  case "5.1.0":
138  return array(
139  "Id" => "integer",
140  "Title" => "text",
141  "Description" => "text",
142  "DefaultWidth" => "integer",
143  "DefaultHeight" => "integer",
144  "ForTranslation" => "integer"
145  );
146  }
147  }
148 
149  // mep_tree
150  if ($a_entity == "mep_tree")
151  {
152  switch ($a_version)
153  {
154  case "4.1.0":
155  case "5.1.0":
156  return array(
157  "MepId" => "integer",
158  "Child" => "integer",
159  "Parent" => "integer",
160  "Depth" => "integer",
161  "Type" => "text",
162  "Title" => "text",
163  "ForeignId" => "integer",
164  "ImportId" => "text"
165  );
166  }
167  }
168  }
169 
176  function readData($a_entity, $a_version, $a_ids, $a_field = "")
177  {
178  global $ilDB;
179 
180  if (!is_array($a_ids))
181  {
182  $a_ids = array($a_ids);
183  }
184 
185  // mep_data
186  if ($a_entity == "mep")
187  {
188  switch ($a_version)
189  {
190  case "4.1.0":
191  $this->getDirectDataFromQuery("SELECT id, title, description, ".
192  " default_width, default_height".
193  " FROM mep_data JOIN object_data ON (mep_data.id = object_data.obj_id) ".
194  "WHERE ".
195  $ilDB->in("id", $a_ids, false, "integer"));
196  break;
197 
198  case "5.1.0":
199  $q = "SELECT id, title, description, ".
200  " default_width, default_height".
201  " FROM mep_data JOIN object_data ON (mep_data.id = object_data.obj_id) ".
202  "WHERE ".
203  $ilDB->in("id", $a_ids, false, "integer");
204 
205  $set = $ilDB->query($q);
206  $this->data = array();
207  while ($rec = $ilDB->fetchAssoc($set))
208  {
209  if ($this->getMasterLanguageOnly())
210  {
211  $rec["for_translation"] = 1;
212  }
213  $tmp = array();
214  foreach ($rec as $k => $v)
215  {
216  $tmp[$this->convertToLeadingUpper($k)]
217  = $v;
218  }
219  $rec = $tmp;
220 
221  $this->data[] = $rec;
222  }
223  break;
224 
225  }
226  }
227 
228  // mep_tree
229  if ($a_entity == "mep_tree")
230  {
231  switch ($a_version)
232  {
233  case "4.1.0":
234  $this->getDirectDataFromQuery("SELECT mep_id, child ".
235  " ,parent,depth,type,title,foreign_id ".
236  " FROM mep_tree JOIN mep_item ON (child = obj_id) ".
237  " WHERE ".
238  $ilDB->in("mep_id", $a_ids, false, "integer").
239  " ORDER BY depth");
240  break;
241 
242  case "5.1.0":
243  $type = "";
244  if ($this->getMasterLanguageOnly())
245  {
246  $type = " AND type <> ".$ilDB->quote("mob", "text");
247  }
248 
249  $q = "SELECT mep_id, child ".
250  " ,parent,depth,type,title,foreign_id, import_id ".
251  " FROM mep_tree JOIN mep_item ON (child = obj_id) ".
252  " WHERE ".
253  $ilDB->in("mep_id", $a_ids, false, "integer").
254  $type.
255  " ORDER BY depth";
256 
257  $set = $ilDB->query($q);
258  $this->data = array();
259  while ($rec = $ilDB->fetchAssoc($set))
260  {
261  $set2 = $ilDB->query("SELECT for_translation FROM mep_data WHERE id = ".$ilDB->quote($rec["mep_id"], true));
262  $rec2 = $ilDB->fetchAssoc($set2);
263  if (!$rec2["for_translation"])
264  {
265  $rec["import_id"] = "il_".IL_INST_ID."_".$rec["type"]."_".$rec["child"];
266  }
267  $tmp = array();
268  foreach ($rec as $k => $v)
269  {
270  $tmp[$this->convertToLeadingUpper($k)]
271  = $v;
272  }
273  $rec = $tmp;
274 
275  $this->data[] = $rec;
276  }
277 
278  break;
279  }
280  }
281  }
282 
286  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
287  {
288  switch ($a_entity)
289  {
290  case "mep":
291  return array (
292  "mep_tree" => array("ids" => $a_rec["Id"])
293  );
294  }
295  return false;
296  }
297 
301 
302 
309  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
310  {
311 //echo $a_entity;
312 //var_dump($a_rec);
313 
314  switch ($a_entity)
315  {
316  case "mep":
317 
318  if ($this->getTranslationImportMode())
319  {
320  return;
321  }
322 
323  include_once("./Modules/MediaPool/classes/class.ilObjMediaPool.php");
324 
325  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
326  {
327  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
328  }
329  else
330  {
331  $newObj = new ilObjMediaPool();
332  $newObj->setType("mep");
333  $newObj->create(true);
334  }
335 
336  $newObj->setTitle($a_rec["Title"]);
337  $newObj->setDescription($a_rec["Description"]);
338  $newObj->setDefaultWidth($a_rec["DefaultWidth"]);
339  $newObj->setDefaultHeight($a_rec["DefaultHeight"]);
340  $newObj->setForTranslation($a_rec["ForTranslation"]);
341  $newObj->update();
342 
343  $this->current_obj = $newObj;
344  $a_mapping->addMapping("Modules/MediaPool", "mep", $a_rec["Id"], $newObj->getId());
345  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
346  break;
347 
348  case "mep_tree":
349  if (!$this->getTranslationImportMode())
350  {
351  switch ($a_rec["Type"])
352  {
353  case "fold":
354  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
355  $fold_id =
356  $this->current_obj->createFolder($a_rec["Title"], $parent);
357  $a_mapping->addMapping("Modules/MediaPool", "mep_tree", $a_rec["Child"],
358  $fold_id);
359  break;
360 
361  case "mob":
362  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
363  $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["ForeignId"]);
364  $item = new ilMediaPoolItem();
365  $item->setType("mob");
366  $item->setForeignId($mob_id);
367  $item->setImportId($a_rec["ImportId"]);
368  $item->setTitle($a_rec["Title"]);
369  $item->create();
370  if ($item->getId() > 0)
371  {
372  $this->current_obj->insertInTree($item->getId(), $parent);
373  }
374  break;
375 
376  case "pg":
377  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
378 
379  $item = new ilMediaPoolItem();
380  $item->setType("pg");
381  $item->setTitle($a_rec["Title"]);
382  $item->setImportId($a_rec["ImportId"]);
383  $item->create();
384  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $item->getId());
385  $a_mapping->addMapping("Services/COPage", "pg", "mep:".$a_rec["Child"],
386  "mep:".$item->getId());
387  if ($item->getId() > 0)
388  {
389  $this->current_obj->insertInTree($item->getId(), $parent);
390  }
391  break;
392 
393  }
394  }
395  else
396  {
397  if ($a_rec["Type"] == "pg")
398  {
399  $imp_id = explode("_", $a_rec["ImportId"]);
400  if ($imp_id[0] == "il" &&
401  (int) $imp_id[1] == (int) IL_INST_ID &&
402  $imp_id[2] == "pg"
403  )
404  {
405  $pg_id = $imp_id[3];
406  include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
407  $pool = ilMediaPoolItem::getPoolForItemId($pg_id);
408  $pool = current($pool);
409  if ($pool == $this->getTranslationLM()->getId())
410  {
411  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $pg_id);
412  $a_mapping->addMapping("Services/COPage", "pg", "mep:".$a_rec["Child"],
413  "mep:".$pg_id);
414  }
415  }
416  }
417  }
418  break;
419  }
420  }
421 }
422 ?>
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
getMasterLanguageOnly()
Get master language only (export)
setMasterLanguageOnly($a_val)
Set master language only (export)
Add some data
static getPoolForItemId($a_id)
Get media pools for item id.
getTranslationImportMode()
Get translation import mode.
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 ...
getTranslationLM()
Get translation lm (import.
getTranslationLang()
Get translation language (import.
convertToLeadingUpper($a_str)
Make xyz_abc a XyzAbc string.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
setTranslationImportMode($a_lm, $a_lang="")
Set translation import mode.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getSupportedVersions()
Get supported versions.
Media Pool Data set class.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
Media Pool Item.
Media pool object.
global $ilDB
getTypes($a_entity, $a_version)
Get field types for entity.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
A dataset contains in data in a common structure that can be shared and transformed for different pur...