ILIAS  release_8 Revision v8.24
class.ilGlossaryDataSet.php
Go to the documentation of this file.
1<?php
2
31{
32 protected int $old_glo_id;
34 protected ilLogger $log;
35
36 public function __construct()
37 {
38 global $DIC;
39
40 $this->db = $DIC->database();
41 $this->log = ilLoggerFactory::getLogger('glo');
43 }
44
45 public function getSupportedVersions(): array
46 {
47 return array("5.1.0", "5.4.0");
48 }
49
50 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
51 {
52 return "https://www.ilias.de/xml/Modules/Glossary/" . $a_entity;
53 }
54
55 protected function getTypes(string $a_entity, string $a_version): array
56 {
57 if ($a_entity == "glo") {
58 switch ($a_version) {
59 case "5.1.0":
60 case "5.4.0":
61 return array(
62 "Id" => "integer",
63 "Title" => "text",
64 "Description" => "text",
65 "Virtual" => "text",
66 "PresMode" => "text",
67 "SnippetLength" => "integer",
68 "GloMenuActive" => "text",
69 "ShowTax" => "integer"
70 );
71 }
72 }
73
74 if ($a_entity == "glo_term") {
75 switch ($a_version) {
76 case "5.1.0":
77 case "5.4.0":
78 return array(
79 "Id" => "integer",
80 "GloId" => "integer",
81 "Term" => "text",
82 "Language" => "text",
83 "ImportId" => "text"
84 );
85 }
86 }
87
88 if ($a_entity == "glo_definition") {
89 switch ($a_version) {
90 case "5.1.0":
91 case "5.4.0":
92 return array(
93 "Id" => "integer",
94 "TermId" => "integer",
95 "ShortText" => "text",
96 "Nr" => "integer",
97 "ShortTextDirty" => "integer"
98 );
99 }
100 }
101
102 if ($a_entity == "glo_advmd_col_order") {
103 switch ($a_version) {
104 case "5.1.0":
105 case "5.4.0":
106 return array(
107 "GloId" => "integer",
108 "FieldId" => "text",
109 "OrderNr" => "integer"
110 );
111 }
112 }
113
114 if ($a_entity == "glo_auto_glossaries") {
115 switch ($a_version) {
116 case "5.4.0":
117 return array(
118 "GloId" => "integer",
119 "AutoGloId" => "text"
120 );
121 }
122 }
123 return [];
124 }
125
126 public function readData(string $a_entity, string $a_version, array $a_ids): void
127 {
129
130 if ($a_entity == "glo") {
131 switch ($a_version) {
132 case "5.1.0":
133 case "5.4.0":
134 $this->getDirectDataFromQuery("SELECT o.title, o.description, g.id, g.virtual, pres_mode, snippet_length, show_tax, glo_menu_active" .
135 " FROM glossary g JOIN object_data o " .
136 " ON (g.id = o.obj_id) " .
137 " WHERE " . $ilDB->in("g.id", $a_ids, false, "integer"));
138 break;
139 }
140 }
141
142 if ($a_entity == "glo_term") {
143 switch ($a_version) {
144 case "5.1.0":
145 $this->getDirectDataFromQuery("SELECT id, glo_id, term, language" .
146 " FROM glossary_term " .
147 " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
148 break;
149
150 case "5.4.0":
151 $this->getDirectDataFromQuery("SELECT id, glo_id, term, language" .
152 " FROM glossary_term " .
153 " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
154
155 $set = $ilDB->query("SELECT r.term_id, r.glo_id, t.term, t.language " .
156 "FROM glo_term_reference r JOIN glossary_term t ON (r.term_id = t.id) " .
157 " WHERE " . $ilDB->in("r.glo_id", $a_ids, false, "integer"));
158 while ($rec = $ilDB->fetchAssoc($set)) {
159 $this->data[] = [
160 "Id" => $rec["term_id"],
161 "GloId" => $rec["glo_id"],
162 "Term" => $rec["term"],
163 "Language" => $rec["language"],
164 ];
165 }
166 break;
167 }
168 }
169
170 if ($a_entity == "glo_definition") {
171 switch ($a_version) {
172 case "5.1.0":
173 case "5.4.0":
174 $this->getDirectDataFromQuery("SELECT id, term_id, short_text, nr, short_text_dirty" .
175 " FROM glossary_definition " .
176 " WHERE " . $ilDB->in("term_id", $a_ids, false, "integer"));
177 break;
178 }
179 }
180
181 if ($a_entity == "glo_advmd_col_order") {
182 switch ($a_version) {
183 case "5.1.0":
184 case "5.4.0":
185 $this->getDirectDataFromQuery("SELECT glo_id, field_id, order_nr" .
186 " FROM glo_advmd_col_order " .
187 " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
188 break;
189 }
190 }
191
192 if ($a_entity == "glo_auto_glossaries") {
193 switch ($a_version) {
194 case "5.4.0":
195 $set = $ilDB->query("SELECT * FROM glo_glossaries " .
196 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
197 $this->data = [];
198 while ($rec = $ilDB->fetchAssoc($set)) {
199 $this->data[] = [
200 "GloId" => $rec["id"],
201 "AutoGloId" => "il_" . IL_INST_ID . "_glo_" . $rec["glo_id"]
202 ];
203 }
204 break;
205 }
206 }
207 }
208
212 protected function getDependencies(
213 string $a_entity,
214 string $a_version,
215 ?array $a_rec = null,
216 ?array $a_ids = null
217 ): array {
218 switch ($a_entity) {
219 case "glo":
220 return array(
221 "glo_term" => array("ids" => $a_rec["Id"] ?? null),
222 "glo_advmd_col_order" => array("ids" => $a_rec["Id"] ?? null),
223 "glo_auto_glossaries" => array("ids" => $a_rec["Id"] ?? null)
224 );
225
226 case "glo_term":
227 return array(
228 "glo_definition" => array("ids" => $a_rec["Id"] ?? null)
229 );
230 }
231
232 return [];
233 }
234
235
236 public function importRecord(
237 string $a_entity,
238 array $a_types,
239 array $a_rec,
240 ilImportMapping $a_mapping,
241 string $a_schema_version
242 ): void {
243 $a_rec = $this->stripTags($a_rec);
244 switch ($a_entity) {
245 case "glo":
246
247 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
248 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
249 } else {
250 $newObj = new ilObjGlossary();
251 $newObj->create(true);
252 }
253
254 $newObj->setTitle($a_rec["Title"]);
255 $newObj->setDescription($a_rec["Description"]);
256 $newObj->setVirtualMode($a_rec["Virtual"]);
257 $newObj->setPresentationMode($a_rec["PresMode"]);
258 $newObj->setSnippetLength((int) ($a_rec["SnippetLength"] ?? 0));
259 $newObj->setActiveGlossaryMenu((bool) ($a_rec["GloMenuActive"] ?? false));
260 $newObj->setShowTaxonomy((bool) ($a_rec["ShowTax"] ?? false));
261 if ($this->getCurrentInstallationId() > 0) {
262 $newObj->setImportId("il_" . $this->getCurrentInstallationId() . "_glo_" . $a_rec["Id"]);
263 }
264 $newObj->update();
265
266 $this->current_obj = $newObj;
267 $this->old_glo_id = $a_rec["Id"];
268 $a_mapping->addMapping("Modules/Glossary", "glo", $a_rec["Id"], $newObj->getId());
269 $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
270 $a_mapping->addMapping(
271 "Services/MetaData",
272 "md",
273 $a_rec["Id"] . ":0:glo",
274 $newObj->getId() . ":0:glo"
275 );
276 $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
277 break;
278
279 case "glo_term":
280
281 // id, glo_id, term, language, import_id
282
283 $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
284 $term = new ilGlossaryTerm();
285 $term->setGlossaryId($glo_id);
286 $term->setTerm($a_rec["Term"]);
287 $term->setLanguage($a_rec["Language"]);
288 if ($this->getCurrentInstallationId() > 0) {
289 $term->setImportId("il_" . $this->getCurrentInstallationId() . "_git_" . $a_rec["Id"]);
290 }
291 $term->create();
292 $term_id = $term->getId();
293 $this->log->debug("glo_term, import id: " . $term->getImportId() . ", term id: " . $term_id);
294
295 $a_mapping->addMapping(
296 "Modules/Glossary",
297 "term",
298 $a_rec["Id"],
299 $term_id
300 );
301
302 $a_mapping->addMapping(
303 "Services/Taxonomy",
304 "tax_item",
305 "glo:term:" . $a_rec["Id"],
306 $term_id
307 );
308
309 $a_mapping->addMapping(
310 "Services/Taxonomy",
311 "tax_item_obj_id",
312 "glo:term:" . $a_rec["Id"],
313 $glo_id
314 );
315
316 $a_mapping->addMapping(
317 "Services/AdvancedMetaData",
318 "advmd_sub_item",
319 "advmd:term:" . $a_rec["Id"],
320 $term_id
321 );
322 break;
323
324 case "glo_definition":
325
326 // id, term_id, short_text, nr, short_text_dirty
327
328 $term_id = (int) $a_mapping->getMapping("Modules/Glossary", "term", $a_rec["TermId"]);
329 if ($term_id == 0) {
330 $this->log->debug("ERROR: Did not find glossary term glo_term id '" . $a_rec["TermId"] . "' for definition id '" . $a_rec["Id"] . "'.");
331 } else {
332 $def = new ilGlossaryDefinition();
333 $def->setTermId($term_id);
334 $def->setShortText($a_rec["ShortText"]);
335 $def->setNr($a_rec["Nr"]);
336 $def->setShortTextDirty($a_rec["ShortTextDirty"]);
337 // no metadata, no page creation
338 $def->create(true, true);
339
340 $a_mapping->addMapping("Modules/Glossary", "def", $a_rec["Id"], $def->getId());
341 $a_mapping->addMapping(
342 "Services/COPage",
343 "pg",
344 "gdf:" . $a_rec["Id"],
345 "gdf:" . $def->getId()
346 );
347 $a_mapping->addMapping(
348 "Services/MetaData",
349 "md",
350 $this->old_glo_id . ":" . $a_rec["Id"] . ":gdf",
351 $this->current_obj->getId() . ":" . $def->getId() . ":gdf"
352 );
353 }
354 break;
355
356 case "glo_advmd_col_order":
357 // glo_id, field_id, order_nr
358 // we save the ordering in the mapping, the glossary importer needs to fix this in the final
359 // processing
360 $a_mapping->addMapping("Modules/Glossary", "advmd_col_order", $a_rec["GloId"] . ":" . $a_rec["FieldId"], $a_rec["OrderNr"]);
361 break;
362
363 case "glo_auto_glossaries":
364 $auto_glo_id = ilObject::_lookupObjIdByImportId($a_rec["AutoGloId"]);
365 $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
366 if ($glo_id > 0 && $auto_glo_id > 0 && ilObject::_lookupType($auto_glo_id) == "glo") {
367 $glo = new ilObjGlossary($glo_id, false);
368 $glo->addAutoGlossary($auto_glo_id);
369 $glo->updateAutoGlossaries();
370 }
371 break;
372 }
373 }
374}
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 ...
ilDBInterface $db
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
Determine the dependent sets of data.
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
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.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component 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
static _lookupType(int $id, bool $reference=false)
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc