ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function getXmlNamespace($a_entity, $a_schema_version)
42  {
43  return "http://www.ilias.de/xml/Modules/MediaPool/" . $a_entity;
44  }
45 
51  public function setMasterLanguageOnly($a_val)
52  {
53  $this->master_lang_only = $a_val;
54  }
55 
61  public function getMasterLanguageOnly()
62  {
64  }
65 
72  public function setTranslationImportMode($a_lm, $a_lang = "")
73  {
74  if ($a_lm != null) {
75  $this->transl_into = true;
76  $this->transl_into_lm = $a_lm;
77  $this->transl_lang = $a_lang;
78  } else {
79  $this->transl_into = false;
80  }
81  }
82 
88  public function getTranslationImportMode()
89  {
90  return $this->transl_into;
91  }
92 
98  public function getTranslationLM()
99  {
100  return $this->transl_into_lm;
101  }
102 
108  public function getTranslationLang()
109  {
110  return $this->transl_lang;
111  }
112 
119  protected function getTypes($a_entity, $a_version)
120  {
121  // mep
122  if ($a_entity == "mep") {
123  switch ($a_version) {
124  case "4.1.0":
125  return array(
126  "Id" => "integer",
127  "Title" => "text",
128  "Description" => "text",
129  "DefaultWidth" => "integer",
130  "DefaultHeight" => "integer");
131 
132  case "5.1.0":
133  return array(
134  "Id" => "integer",
135  "Title" => "text",
136  "Description" => "text",
137  "DefaultWidth" => "integer",
138  "DefaultHeight" => "integer",
139  "ForTranslation" => "integer"
140  );
141  }
142  }
143 
144  // mep_tree
145  if ($a_entity == "mep_tree") {
146  switch ($a_version) {
147  case "4.1.0":
148  case "5.1.0":
149  return array(
150  "MepId" => "integer",
151  "Child" => "integer",
152  "Parent" => "integer",
153  "Depth" => "integer",
154  "Type" => "text",
155  "Title" => "text",
156  "ForeignId" => "integer",
157  "ImportId" => "text"
158  );
159  }
160  }
161  }
162 
169  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
170  {
171  $ilDB = $this->db;
172 
173  if (!is_array($a_ids)) {
174  $a_ids = array($a_ids);
175  }
176 
177  // mep_data
178  if ($a_entity == "mep") {
179  switch ($a_version) {
180  case "4.1.0":
181  $this->getDirectDataFromQuery("SELECT id, title, description, " .
182  " default_width, default_height" .
183  " FROM mep_data JOIN object_data ON (mep_data.id = object_data.obj_id) " .
184  "WHERE " .
185  $ilDB->in("id", $a_ids, false, "integer"));
186  break;
187 
188  case "5.1.0":
189  $q = "SELECT id, title, description, " .
190  " default_width, default_height" .
191  " FROM mep_data JOIN object_data ON (mep_data.id = object_data.obj_id) " .
192  "WHERE " .
193  $ilDB->in("id", $a_ids, false, "integer");
194 
195  $set = $ilDB->query($q);
196  $this->data = array();
197  while ($rec = $ilDB->fetchAssoc($set)) {
198  if ($this->getMasterLanguageOnly()) {
199  $rec["for_translation"] = 1;
200  }
201  $tmp = array();
202  foreach ($rec as $k => $v) {
203  $tmp[$this->convertToLeadingUpper($k)]
204  = $v;
205  }
206  $rec = $tmp;
207 
208  $this->data[] = $rec;
209  }
210  break;
211 
212  }
213  }
214 
215  // mep_tree
216  if ($a_entity == "mep_tree") {
217  switch ($a_version) {
218  case "4.1.0":
219  $this->getDirectDataFromQuery("SELECT mep_id, child " .
220  " ,parent,depth,type,title,foreign_id " .
221  " FROM mep_tree JOIN mep_item ON (child = obj_id) " .
222  " WHERE " .
223  $ilDB->in("mep_id", $a_ids, false, "integer") .
224  " ORDER BY depth");
225  break;
226 
227  case "5.1.0":
228  $type = "";
229  if ($this->getMasterLanguageOnly()) {
230  $type = " AND type <> " . $ilDB->quote("mob", "text");
231  }
232 
233  $q = "SELECT mep_id, child " .
234  " ,parent,depth,type,title,foreign_id, import_id " .
235  " FROM mep_tree JOIN mep_item ON (child = obj_id) " .
236  " WHERE " .
237  $ilDB->in("mep_id", $a_ids, false, "integer") .
238  $type .
239  " ORDER BY depth";
240 
241  $set = $ilDB->query($q);
242  $this->data = array();
243  while ($rec = $ilDB->fetchAssoc($set)) {
244  $set2 = $ilDB->query("SELECT for_translation FROM mep_data WHERE id = " . $ilDB->quote($rec["mep_id"], true));
245  $rec2 = $ilDB->fetchAssoc($set2);
246  if (!$rec2["for_translation"]) {
247  $rec["import_id"] = "il_" . IL_INST_ID . "_" . $rec["type"] . "_" . $rec["child"];
248  }
249  $tmp = array();
250  foreach ($rec as $k => $v) {
251  $tmp[$this->convertToLeadingUpper($k)]
252  = $v;
253  }
254  $rec = $tmp;
255 
256  $this->data[] = $rec;
257  }
258 
259  break;
260  }
261  }
262  }
263 
267  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
268  {
269  switch ($a_entity) {
270  case "mep":
271  return array(
272  "mep_tree" => array("ids" => $a_rec["Id"])
273  );
274  }
275  return false;
276  }
277 
281 
282 
289  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
290  {
291  //echo $a_entity;
292  //var_dump($a_rec);
293 
294  switch ($a_entity) {
295  case "mep":
296 
297  if ($this->getTranslationImportMode()) {
298  return;
299  }
300 
301  include_once("./Modules/MediaPool/classes/class.ilObjMediaPool.php");
302 
303  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
304  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
305  } else {
306  $newObj = new ilObjMediaPool();
307  $newObj->setType("mep");
308  $newObj->create(true);
309  }
310 
311  $newObj->setTitle($a_rec["Title"]);
312  $newObj->setDescription($a_rec["Description"]);
313  $newObj->setDefaultWidth($a_rec["DefaultWidth"]);
314  $newObj->setDefaultHeight($a_rec["DefaultHeight"]);
315  $newObj->setForTranslation($a_rec["ForTranslation"]);
316  $newObj->update();
317 
318  $this->current_obj = $newObj;
319  $a_mapping->addMapping("Modules/MediaPool", "mep", $a_rec["Id"], $newObj->getId());
320  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
321  break;
322 
323  case "mep_tree":
324  if (!$this->getTranslationImportMode()) {
325  switch ($a_rec["Type"]) {
326  case "fold":
327  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
328  $fold_id =
329  $this->current_obj->createFolder($a_rec["Title"], $parent);
330  $a_mapping->addMapping(
331  "Modules/MediaPool",
332  "mep_tree",
333  $a_rec["Child"],
334  $fold_id
335  );
336  break;
337 
338  case "mob":
339  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
340  $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["ForeignId"]);
341  $item = new ilMediaPoolItem();
342  $item->setType("mob");
343  $item->setForeignId($mob_id);
344  $item->setImportId($a_rec["ImportId"]);
345  $item->setTitle($a_rec["Title"]);
346  $item->create();
347  if ($item->getId() > 0) {
348  $this->current_obj->insertInTree($item->getId(), $parent);
349  }
350  break;
351 
352  case "pg":
353  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
354 
355  $item = new ilMediaPoolItem();
356  $item->setType("pg");
357  $item->setTitle($a_rec["Title"]);
358  $item->setImportId($a_rec["ImportId"]);
359  $item->create();
360  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $item->getId());
361  $a_mapping->addMapping(
362  "Services/COPage",
363  "pg",
364  "mep:" . $a_rec["Child"],
365  "mep:" . $item->getId()
366  );
367  if ($item->getId() > 0) {
368  $this->current_obj->insertInTree($item->getId(), $parent);
369  }
370  break;
371 
372  }
373  } else {
374  if ($a_rec["Type"] == "pg") {
375  $imp_id = explode("_", $a_rec["ImportId"]);
376  if ($imp_id[0] == "il" &&
377  (int) $imp_id[1] == (int) IL_INST_ID &&
378  $imp_id[2] == "pg"
379  ) {
380  $pg_id = $imp_id[3];
381  include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
382  $pool = ilMediaPoolItem::getPoolForItemId($pg_id);
383  $pool = current($pool);
384  if ($pool == $this->getTranslationLM()->getId()) {
385  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $pg_id);
386  $a_mapping->addMapping(
387  "Services/COPage",
388  "pg",
389  "mep:" . $a_rec["Child"],
390  "mep:" . $pg_id
391  );
392  }
393  }
394  }
395  }
396  break;
397  }
398  }
399 }
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)
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 ...
$type
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
Media Pool Item.
Media pool object.
$this data['403_header']
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...