ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
180  // mep_tree
181  if ($a_entity === "mep_tree") {
182  switch ($a_version) {
183  case "4.1.0":
184  $this->getDirectDataFromQuery("SELECT mep_id, child " .
185  " ,parent,depth,type,title,foreign_id " .
186  " FROM mep_tree JOIN mep_item ON (child = obj_id) " .
187  " WHERE " .
188  $ilDB->in("mep_id", $a_ids, false, "integer") .
189  " ORDER BY depth");
190  break;
191 
192  case "5.1.0":
193  $type = "";
194  if ($this->getMasterLanguageOnly()) {
195  $type = " AND type <> " . $ilDB->quote("mob", "text");
196  }
197 
198  $q = "SELECT mep_id, child " .
199  " ,parent,depth,type,title,foreign_id, import_id " .
200  " FROM mep_tree JOIN mep_item ON (child = obj_id) " .
201  " WHERE " .
202  $ilDB->in("mep_id", $a_ids, false, "integer") .
203  $type .
204  " ORDER BY depth";
205 
206  $set = $ilDB->query($q);
207  $this->data = array();
208  while ($rec = $ilDB->fetchAssoc($set)) {
209  $set2 = $ilDB->query("SELECT for_translation FROM mep_data WHERE id = " . $ilDB->quote($rec["mep_id"], true));
210  $rec2 = $ilDB->fetchAssoc($set2);
211  if (!$rec2["for_translation"]) {
212  $rec["import_id"] = "il_" . IL_INST_ID . "_" . $rec["type"] . "_" . $rec["child"];
213  }
214  $tmp = array();
215  foreach ($rec as $k => $v) {
216  $tmp[$this->convertToLeadingUpper($k)]
217  = $v;
218  }
219  $rec = $tmp;
220 
221  $this->data[] = $rec;
222  }
223 
224  break;
225  }
226  }
227  }
228 
229  protected function getDependencies(
230  string $a_entity,
231  string $a_version,
232  ?array $a_rec = null,
233  ?array $a_ids = null
234  ): array {
235  switch ($a_entity) {
236  case "mep":
237  return array(
238  "mep_tree" => array("ids" => $a_rec["Id"] ?? null)
239  );
240  }
241  return [];
242  }
243 
244  public function importRecord(
245  string $a_entity,
246  array $a_types,
247  array $a_rec,
248  ilImportMapping $a_mapping,
249  string $a_schema_version
250  ): void {
251  $a_rec = $this->stripTags($a_rec);
252 
253  switch ($a_entity) {
254  case "mep":
255 
256  if ($this->getTranslationImportMode()) {
257  return;
258  }
259 
260  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
261  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
262  } else {
263  $newObj = new ilObjMediaPool();
264  $newObj->setType("mep");
265  $newObj->create();
266  }
267 
268  $newObj->setTitle($a_rec["Title"]);
269  $newObj->setDescription($a_rec["Description"]);
270  $newObj->setDefaultWidth((int) $a_rec["DefaultWidth"]);
271  $newObj->setDefaultHeight((int) $a_rec["DefaultHeight"]);
272  $newObj->setForTranslation((bool) ($a_rec["ForTranslation"] ?? false));
273  $newObj->update();
274 
275  $this->current_obj = $newObj;
276  $a_mapping->addMapping("Modules/MediaPool", "mep", $a_rec["Id"], $newObj->getId());
277  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
278  break;
279 
280  case "mep_tree":
281  if (!$this->getTranslationImportMode()) {
282  switch ($a_rec["Type"]) {
283  case "fold":
284  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
285  $fold_id =
286  $this->current_obj->createFolder($a_rec["Title"], $parent);
287  $a_mapping->addMapping(
288  "Modules/MediaPool",
289  "mep_tree",
290  $a_rec["Child"],
291  $fold_id
292  );
293  break;
294 
295  case "mob":
296  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
297  $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["ForeignId"]);
298  $item = new ilMediaPoolItem();
299  $item->setType("mob");
300  $item->setForeignId($mob_id);
301  $item->setImportId($a_rec["ImportId"]);
302  $item->setTitle($a_rec["Title"]);
303  $item->create();
304  if ($item->getId() > 0) {
305  if ($parent === 0) {
306  $parent = null;
307  }
308  $this->current_obj->insertInTree($item->getId(), $parent);
309  }
310  break;
311 
312  case "pg":
313  $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
314 
315  $item = new ilMediaPoolItem();
316  $item->setType("pg");
317  $item->setTitle($a_rec["Title"]);
318  $item->setImportId($a_rec["ImportId"]);
319  $item->create();
320  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $item->getId());
321  $a_mapping->addMapping(
322  "Services/COPage",
323  "pg",
324  "mep:" . $a_rec["Child"],
325  "mep:" . $item->getId()
326  );
327  if ($item->getId() > 0) {
328  if ($parent === 0) {
329  $parent = null;
330  }
331  $this->current_obj->insertInTree($item->getId(), $parent);
332  }
333  break;
334 
335  }
336  } elseif ($a_rec["Type"] === "pg") {
337  $imp_id = explode("_", $a_rec["ImportId"]);
338  if ($imp_id[0] === "il" &&
339  (int) $imp_id[1] == (int) IL_INST_ID &&
340  $imp_id[2] === "pg"
341  ) {
342  $pg_id = $imp_id[3];
343  $pool = ilMediaPoolItem::getPoolForItemId($pg_id);
344  $pool = current($pool);
345  if ($pool == $this->getTranslationMep()->getId()) {
346  $a_mapping->addMapping("Modules/MediaPool", "pg", $a_rec["Child"], $pg_id);
347  $a_mapping->addMapping(
348  "Services/COPage",
349  "pg",
350  "mep:" . $a_rec["Child"],
351  "mep:" . $pg_id
352  );
353  }
354  }
355  }
356  break;
357  }
358  }
359 }
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...
$type
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...
stripTags(array $rec, array $omit_keys=[])
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...