ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMediaPoolDataSet.php
Go to the documentation of this file.
1 <?php
2 
29 {
33  protected ?ilObjMediaPool $current_obj = null;
34  protected bool $master_lang_only = false;
35  protected bool $transl_into = false;
36  protected ?ilObjMediaPool $transl_into_mep = null;
37  protected string $transl_lang = "";
38 
39  public function getSupportedVersions(): array
40  {
41  return array("5.1.0", "4.1.0");
42  }
43 
44  protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
45  {
46  return "https://www.ilias.de/xml/Modules/MediaPool/" . $a_entity;
47  }
48 
52  public function setMasterLanguageOnly(bool $a_val): void
53  {
54  $this->master_lang_only = $a_val;
55  }
56 
57  public function getMasterLanguageOnly(): bool
58  {
60  }
61 
62  public function setTranslationImportMode(
63  ?ilObjMediaPool $a_mep,
64  string $a_lang = ""
65  ): void {
66  if ($a_mep !== null) {
67  $this->transl_into = true;
68  $this->transl_into_mep = $a_mep;
69  $this->transl_lang = $a_lang;
70  } else {
71  $this->transl_into = false;
72  }
73  }
74 
75  public function getTranslationImportMode(): bool
76  {
77  return $this->transl_into;
78  }
79 
83  public function getTranslationMep(): ?ilObjMediaPool
84  {
86  }
87 
88  public function getTranslationLang(): string
89  {
90  return $this->transl_lang;
91  }
92 
93  protected function getTypes(string $a_entity, string $a_version): array
94  {
95  // mep
96  if ($a_entity === "mep") {
97  switch ($a_version) {
98  case "4.1.0":
99  return array(
100  "Id" => "integer",
101  "Title" => "text",
102  "Description" => "text",
103  "DefaultWidth" => "integer",
104  "DefaultHeight" => "integer");
105 
106  case "5.1.0":
107  return array(
108  "Id" => "integer",
109  "Title" => "text",
110  "Description" => "text",
111  "DefaultWidth" => "integer",
112  "DefaultHeight" => "integer",
113  "ForTranslation" => "integer"
114  );
115  }
116  }
117 
118  // mep_tree
119  if ($a_entity === "mep_tree") {
120  switch ($a_version) {
121  case "4.1.0":
122  case "5.1.0":
123  return array(
124  "MepId" => "integer",
125  "Child" => "integer",
126  "Parent" => "integer",
127  "Depth" => "integer",
128  "Type" => "text",
129  "Title" => "text",
130  "ForeignId" => "integer",
131  "ImportId" => "text"
132  );
133  }
134  }
135  return [];
136  }
137 
138  public function readData(string $a_entity, string $a_version, array $a_ids): void
139  {
140  $ilDB = $this->db;
141 
142  // mep_data
143  if ($a_entity === "mep") {
144  switch ($a_version) {
145  case "4.1.0":
146  $this->getDirectDataFromQuery("SELECT id, title, description, " .
147  " default_width, default_height" .
148  " FROM mep_data JOIN object_data ON (mep_data.id = object_data.obj_id) " .
149  "WHERE " .
150  $ilDB->in("id", $a_ids, false, "integer"));
151  break;
152 
153  case "5.1.0":
154  $q = "SELECT id, title, description, " .
155  " default_width, default_height" .
156  " FROM mep_data JOIN object_data ON (mep_data.id = object_data.obj_id) " .
157  "WHERE " .
158  $ilDB->in("id", $a_ids, false, "integer");
159 
160  $set = $ilDB->query($q);
161  $this->data = array();
162  while ($rec = $ilDB->fetchAssoc($set)) {
163  if ($this->getMasterLanguageOnly()) {
164  $rec["for_translation"] = 1;
165  }
166  $tmp = array();
167  foreach ($rec as $k => $v) {
168  $tmp[$this->convertToLeadingUpper($k)]
169  = $v;
170  }
171  $rec = $tmp;
172 
173  $this->data[] = $rec;
174  }
175  break;
176  }
177  }
178 
179  // mep_tree
180  if ($a_entity === "mep_tree") {
181  switch ($a_version) {
182  case "4.1.0":
183  $this->getDirectDataFromQuery("SELECT mep_id, child " .
184  " ,parent,depth,type,title,foreign_id " .
185  " FROM mep_tree JOIN mep_item ON (child = obj_id) " .
186  " WHERE " .
187  $ilDB->in("mep_id", $a_ids, false, "integer") .
188  " ORDER BY depth");
189  break;
190 
191  case "5.1.0":
192  $type = "";
193  if ($this->getMasterLanguageOnly()) {
194  $type = " AND type <> " . $ilDB->quote("mob", "text");
195  }
196 
197  $q = "SELECT mep_id, child " .
198  " ,parent,depth,type,title,foreign_id, import_id " .
199  " FROM mep_tree JOIN mep_item ON (child = obj_id) " .
200  " WHERE " .
201  $ilDB->in("mep_id", $a_ids, false, "integer") .
202  $type .
203  " ORDER BY depth";
204 
205  $set = $ilDB->query($q);
206  $this->data = array();
207  while ($rec = $ilDB->fetchAssoc($set)) {
208  $set2 = $ilDB->query("SELECT for_translation FROM mep_data WHERE id = " . $ilDB->quote($rec["mep_id"], true));
209  $rec2 = $ilDB->fetchAssoc($set2);
210  if (!$rec2["for_translation"]) {
211  $rec["import_id"] = "il_" . IL_INST_ID . "_" . $rec["type"] . "_" . $rec["child"];
212  }
213  $tmp = array();
214  foreach ($rec as $k => $v) {
215  $tmp[$this->convertToLeadingUpper($k)]
216  = $v;
217  }
218  $rec = $tmp;
219 
220  $this->data[] = $rec;
221  }
222 
223  break;
224  }
225  }
226  }
227 
228  protected function getDependencies(
229  string $a_entity,
230  string $a_version,
231  ?array $a_rec = null,
232  ?array $a_ids = null
233  ): array {
234  switch ($a_entity) {
235  case "mep":
236  return array(
237  "mep_tree" => array("ids" => $a_rec["Id"] ?? null)
238  );
239  }
240  return [];
241  }
242 
243  public function importRecord(
244  string $a_entity,
245  array $a_types,
246  array $a_rec,
247  ilImportMapping $a_mapping,
248  string $a_schema_version
249  ): void {
250  $a_rec = $this->stripTags($a_rec);
251 
252  switch ($a_entity) {
253  case "mep":
254 
255  if ($this->getTranslationImportMode()) {
256  return;
257  }
258 
259  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
260  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
261  } else {
262  $newObj = new ilObjMediaPool();
263  $newObj->setType("mep");
264  $newObj->create();
265  }
266 
267  $newObj->setTitle($a_rec["Title"]);
268  $newObj->setDescription($a_rec["Description"]);
269  $newObj->setDefaultWidth((int) $a_rec["DefaultWidth"]);
270  $newObj->setDefaultHeight((int) $a_rec["DefaultHeight"]);
271  $newObj->setForTranslation((bool) ($a_rec["ForTranslation"] ?? false));
272  $newObj->update();
273 
274  $this->current_obj = $newObj;
275  $a_mapping->addMapping("Modules/MediaPool", "mep", $a_rec["Id"], $newObj->getId());
276  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
277  break;
278 
279  case "mep_tree":
280  if (!$this->getTranslationImportMode()) {
281  switch ($a_rec["Type"]) {
282  case "fold":
283  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
284  $fold_id =
285  $this->current_obj->createFolder($a_rec["Title"], $parent);
286  $a_mapping->addMapping(
287  "Modules/MediaPool",
288  "mep_tree",
289  $a_rec["Child"],
290  $fold_id
291  );
292  break;
293 
294  case "mob":
295  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
296  $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["ForeignId"]);
297  $item = new ilMediaPoolItem();
298  $item->setType("mob");
299  $item->setForeignId($mob_id);
300  $item->setImportId($a_rec["ImportId"]);
301  $item->setTitle($a_rec["Title"]);
302  $item->create();
303  if ($item->getId() > 0) {
304  if ($parent === 0) {
305  $parent = null;
306  }
307  $this->current_obj->insertInTree($item->getId(), $parent);
308  }
309  break;
310 
311  case "pg":
312  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
313 
314  $item = new ilMediaPoolItem();
315  $item->setType("pg");
316  $item->setTitle($a_rec["Title"]);
317  $item->setImportId($a_rec["ImportId"]);
318  $item->create();
319  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $item->getId());
320  $a_mapping->addMapping(
321  "Services/COPage",
322  "pg",
323  "mep:" . $a_rec["Child"],
324  "mep:" . $item->getId()
325  );
326  if ($item->getId() > 0) {
327  if ($parent === 0) {
328  $parent = null;
329  }
330  $this->current_obj->insertInTree($item->getId(), $parent);
331  }
332  break;
333  }
334  } elseif ($a_rec["Type"] === "pg") {
335  $imp_id = explode("_", $a_rec["ImportId"]);
336  if ($imp_id[0] === "il" &&
337  (int) $imp_id[1] == (int) IL_INST_ID &&
338  $imp_id[2] === "pg"
339  ) {
340  $pg_id = $imp_id[3];
341  $pool = ilMediaPoolItem::getPoolForItemId($pg_id);
342  $pool = current($pool);
343  if ($pool == $this->getTranslationMep()->getId()) {
344  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $pg_id);
345  $a_mapping->addMapping(
346  "Services/COPage",
347  "pg",
348  "mep:" . $a_rec["Child"],
349  "mep:" . $pg_id
350  );
351  }
352  }
353  }
354  break;
355  }
356  }
357 }
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
getTranslationMep()
Get translation pool (import)
convertToLeadingUpper(string $a_str)
Make xyz_abc a XyzAbc string.
const IL_INST_ID
Definition: constants.php:40
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getPoolForItemId(int $a_id)
setMasterLanguageOnly(bool $a_val)
Set master language only (export)
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
readData(string $a_entity, string $a_version, array $a_ids)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
ilDBInterface $db
setTranslationImportMode(?ilObjMediaPool $a_mep, string $a_lang="")
getXmlNamespace(string $a_entity, string $a_schema_version)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$q
Definition: shib_logout.php:21
stripTags(array $rec, array $omit_keys=[])