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