ILIAS  release_7 Revision v7.30-3-g800a261c036
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 
283  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
284  {
285  $a_rec = $this->stripTags($a_rec);
286 
287  switch ($a_entity) {
288  case "mep":
289 
290  if ($this->getTranslationImportMode()) {
291  return;
292  }
293 
294  include_once("./Modules/MediaPool/classes/class.ilObjMediaPool.php");
295 
296  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
297  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
298  } else {
299  $newObj = new ilObjMediaPool();
300  $newObj->setType("mep");
301  $newObj->create(true);
302  }
303 
304  $newObj->setTitle($a_rec["Title"]);
305  $newObj->setDescription($a_rec["Description"]);
306  $newObj->setDefaultWidth($a_rec["DefaultWidth"]);
307  $newObj->setDefaultHeight($a_rec["DefaultHeight"]);
308  $newObj->setForTranslation($a_rec["ForTranslation"]);
309  $newObj->update();
310 
311  $this->current_obj = $newObj;
312  $a_mapping->addMapping("Modules/MediaPool", "mep", $a_rec["Id"], $newObj->getId());
313  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
314  break;
315 
316  case "mep_tree":
317  if (!$this->getTranslationImportMode()) {
318  switch ($a_rec["Type"]) {
319  case "fold":
320  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
321  $fold_id =
322  $this->current_obj->createFolder($a_rec["Title"], $parent);
323  $a_mapping->addMapping(
324  "Modules/MediaPool",
325  "mep_tree",
326  $a_rec["Child"],
327  $fold_id
328  );
329  break;
330 
331  case "mob":
332  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
333  $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["ForeignId"]);
334  $item = new ilMediaPoolItem();
335  $item->setType("mob");
336  $item->setForeignId($mob_id);
337  $item->setImportId($a_rec["ImportId"]);
338  $item->setTitle($a_rec["Title"]);
339  $item->create();
340  if ($item->getId() > 0) {
341  $this->current_obj->insertInTree($item->getId(), $parent);
342  }
343  break;
344 
345  case "pg":
346  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
347 
348  $item = new ilMediaPoolItem();
349  $item->setType("pg");
350  $item->setTitle($a_rec["Title"]);
351  $item->setImportId($a_rec["ImportId"]);
352  $item->create();
353  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $item->getId());
354  $a_mapping->addMapping(
355  "Services/COPage",
356  "pg",
357  "mep:" . $a_rec["Child"],
358  "mep:" . $item->getId()
359  );
360  if ($item->getId() > 0) {
361  $this->current_obj->insertInTree($item->getId(), $parent);
362  }
363  break;
364 
365  }
366  } else {
367  if ($a_rec["Type"] == "pg") {
368  $imp_id = explode("_", $a_rec["ImportId"]);
369  if ($imp_id[0] == "il" &&
370  (int) $imp_id[1] == (int) IL_INST_ID &&
371  $imp_id[2] == "pg"
372  ) {
373  $pg_id = $imp_id[3];
374  include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
375  $pool = ilMediaPoolItem::getPoolForItemId($pg_id);
376  $pool = current($pool);
377  if ($pool == $this->getTranslationLM()->getId()) {
378  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $pg_id);
379  $a_mapping->addMapping(
380  "Services/COPage",
381  "pg",
382  "mep:" . $a_rec["Child"],
383  "mep:" . $pg_id
384  );
385  }
386  }
387  }
388  }
389  break;
390  }
391  }
392 }
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.
const IL_INST_ID
Definition: constants.php:38
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.
global $ilDB
getTypes($a_entity, $a_version)
Get field types for entity.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
stripTags(array $rec, array $omit_keys=[])
A dataset contains in data in a common structure that can be shared and transformed for different pur...