ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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;
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
84 {
85 return $this->transl_into_mep;
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('components/ILIAS/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("components/ILIAS/MediaPool", "mep", $a_rec["Id"], $newObj->getId());
276 $a_mapping->addMapping("components/ILIAS/ILIASObject", "obj", $a_rec["Id"], $newObj->getId());
277 $a_mapping->addMapping(
278 "components/ILIAS/MetaData",
279 "md",
280 $a_rec["Id"] . ":0:mep",
281 $newObj->getId() . ":0:mep"
282 );
283 break;
284
285 case "mep_tree":
286 if (!$this->getTranslationImportMode()) {
287 switch ($a_rec["Type"]) {
288 case "fold":
289 $parent = (int) $a_mapping->getMapping("components/ILIAS/MediaPool", "mep_tree", $a_rec["Parent"]);
290 $fold_id =
291 $this->current_obj->createFolder($a_rec["Title"], $parent);
292 $a_mapping->addMapping(
293 "components/ILIAS/MediaPool",
294 "mep_tree",
295 $a_rec["Child"],
296 $fold_id
297 );
298 break;
299
300 case "mob":
301 $parent = (int) $a_mapping->getMapping("components/ILIAS/MediaPool", "mep_tree", $a_rec["Parent"]);
302 $mob_id = (int) $a_mapping->getMapping("components/ILIAS/MediaObjects", "mob", $a_rec["ForeignId"]);
303 $item = new ilMediaPoolItem();
304 $item->setType("mob");
305 $item->setForeignId($mob_id);
306 $item->setImportId($a_rec["ImportId"]);
307 $item->setTitle($a_rec["Title"]);
308 $item->create();
309 if ($item->getId() > 0) {
310 if ($parent === 0) {
311 $parent = null;
312 }
313 $this->current_obj->insertInTree($item->getId(), $parent);
314 }
315 break;
316
317 case "pg":
318 $parent = (int) $a_mapping->getMapping("components/ILIAS/MediaPool", "mep_tree", $a_rec["Parent"]);
319
320 $item = new ilMediaPoolItem();
321 $item->setType("pg");
322 $item->setTitle($a_rec["Title"]);
323 $item->setImportId($a_rec["ImportId"]);
324 $item->create();
325 $a_mapping->addMapping("components/ILIAS/MediaPool", "pg", $a_rec["Child"], $item->getId());
326 $a_mapping->addMapping(
327 "components/ILIAS/COPage",
328 "pg",
329 "mep:" . $a_rec["Child"],
330 "mep:" . $item->getId()
331 );
332 if ($item->getId() > 0) {
333 if ($parent === 0) {
334 $parent = null;
335 }
336 $this->current_obj->insertInTree($item->getId(), $parent);
337 }
338 break;
339 }
340 } elseif ($a_rec["Type"] === "pg") {
341 $imp_id = explode("_", $a_rec["ImportId"]);
342 if ($imp_id[0] === "il" &&
343 (int) $imp_id[1] == (int) IL_INST_ID &&
344 $imp_id[2] === "pg"
345 ) {
346 $pg_id = $imp_id[3];
347 $pool = ilMediaPoolItem::getPoolForItemId($pg_id);
348 $pool = current($pool);
349 if ($pool == $this->getTranslationMep()->getId()) {
350 $a_mapping->addMapping("components/ILIAS/MediaPool", "pg", $a_rec["Child"], $pg_id);
351 $a_mapping->addMapping(
352 "components/ILIAS/COPage",
353 "pg",
354 "mep:" . $a_rec["Child"],
355 "mep:" . $pg_id
356 );
357 }
358 }
359 }
360 break;
361 }
362 }
363}
A dataset contains in data in a common structure that can be shared and transformed for different pur...
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlNamespace(string $a_entity, string $a_schema_version)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
setTranslationImportMode(?ilObjMediaPool $a_mep, string $a_lang="")
getTranslationMep()
Get translation pool (import)
setMasterLanguageOnly(bool $a_val)
Set master language only (export)
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getPoolForItemId(int $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
const IL_INST_ID
Definition: constants.php:40
if(!file_exists('../ilias.ini.php'))
$q
Definition: shib_logout.php:23