ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilGlossaryDataSet.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
18{
22 protected $log;
23
27 public function __construct()
28 {
29 global $DIC;
30
31 $this->db = $DIC->database();
32 $this->log = ilLoggerFactory::getLogger('glo');
34 }
35
41 public function getSupportedVersions()
42 {
43 return array("5.1.0", "5.4.0");
44 }
45
52 public function getXmlNamespace($a_entity, $a_schema_version)
53 {
54 return "http://www.ilias.de/xml/Modules/Glossary/" . $a_entity;
55 }
56
64 protected function getTypes($a_entity, $a_version)
65 {
66 if ($a_entity == "glo") {
67 switch ($a_version) {
68 case "5.1.0":
69 case "5.4.0":
70 return array(
71 "Id" => "integer",
72 "Title" => "text",
73 "Description" => "text",
74 "Virtual" => "text",
75 "PresMode" => "text",
76 "SnippetLength" => "integer",
77 "GloMenuActive" => "text",
78 "ShowTax" => "integer"
79 );
80 }
81 }
82
83 if ($a_entity == "glo_term") {
84 switch ($a_version) {
85 case "5.1.0":
86 case "5.4.0":
87 return array(
88 "Id" => "integer",
89 "GloId" => "integer",
90 "Term" => "text",
91 "Language" => "text",
92 "ImportId" => "text"
93 );
94 }
95 }
96
97 if ($a_entity == "glo_definition") {
98 switch ($a_version) {
99 case "5.1.0":
100 case "5.4.0":
101 return array(
102 "Id" => "integer",
103 "TermId" => "integer",
104 "ShortText" => "text",
105 "Nr" => "integer",
106 "ShortTextDirty" => "integer"
107 );
108 }
109 }
110
111 if ($a_entity == "glo_advmd_col_order") {
112 switch ($a_version) {
113 case "5.1.0":
114 case "5.4.0":
115 return array(
116 "GloId" => "integer",
117 "FieldId" => "text",
118 "OrderNr" => "integer"
119 );
120 }
121 }
122
123 if ($a_entity == "glo_auto_glossaries") {
124 switch ($a_version) {
125 case "5.4.0":
126 return array(
127 "GloId" => "integer",
128 "AutoGloId" => "text"
129 );
130 }
131 }
132 }
133
140 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
141 {
143
144 if (!is_array($a_ids)) {
145 $a_ids = array($a_ids);
146 }
147
148 if ($a_entity == "glo") {
149 switch ($a_version) {
150 case "5.1.0":
151 case "5.4.0":
152 $this->getDirectDataFromQuery("SELECT o.title, o.description, g.id, g.virtual, pres_mode, snippet_length, show_tax, glo_menu_active" .
153 " FROM glossary g JOIN object_data o " .
154 " ON (g.id = o.obj_id) " .
155 " WHERE " . $ilDB->in("g.id", $a_ids, false, "integer"));
156 break;
157 }
158 }
159
160 if ($a_entity == "glo_term") {
161 switch ($a_version) {
162 case "5.1.0":
163 $this->getDirectDataFromQuery("SELECT id, glo_id, term, language" .
164 " FROM glossary_term " .
165 " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
166 break;
167
168 case "5.4.0":
169 $this->getDirectDataFromQuery("SELECT id, glo_id, term, language" .
170 " FROM glossary_term " .
171 " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
172
173 $set = $ilDB->query("SELECT r.term_id, r.glo_id, t.term, t.language " .
174 "FROM glo_term_reference r JOIN glossary_term t ON (r.term_id = t.id) " .
175 " WHERE " . $ilDB->in("r.glo_id", $a_ids, false, "integer"));
176 while ($rec = $ilDB->fetchAssoc($set)) {
177 $this->data[] = [
178 "Id" => $rec["term_id"],
179 "GloId" => $rec["glo_id"],
180 "Term" => $rec["term"],
181 "Language" => $rec["language"],
182 ];
183 }
184 break;
185 }
186 }
187
188 if ($a_entity == "glo_definition") {
189 switch ($a_version) {
190 case "5.1.0":
191 case "5.4.0":
192 $this->getDirectDataFromQuery("SELECT id, term_id, short_text, nr, short_text_dirty" .
193 " FROM glossary_definition " .
194 " WHERE " . $ilDB->in("term_id", $a_ids, false, "integer"));
195 break;
196 }
197 }
198
199 if ($a_entity == "glo_advmd_col_order") {
200 switch ($a_version) {
201 case "5.1.0":
202 case "5.4.0":
203 $this->getDirectDataFromQuery("SELECT glo_id, field_id, order_nr" .
204 " FROM glo_advmd_col_order " .
205 " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
206 break;
207 }
208 }
209
210 if ($a_entity == "glo_auto_glossaries") {
211 switch ($a_version) {
212 case "5.4.0":
213 $set = $ilDB->query("SELECT * FROM glo_glossaries " .
214 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
215 $this->data = [];
216 while ($rec = $ilDB->fetchAssoc($set)) {
217 $this->data[] = [
218 "GloId" => $rec["id"],
219 "AutoGloId" => "il_" . IL_INST_ID . "_glo_" . $rec["glo_id"]
220 ];
221 }
222 break;
223 }
224 }
225 }
226
230 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
231 {
232 switch ($a_entity) {
233 case "glo":
234 return array(
235 "glo_term" => array("ids" => $a_rec["Id"]),
236 "glo_advmd_col_order" => array("ids" => $a_rec["Id"]),
237 "glo_auto_glossaries" => array("ids" => $a_rec["Id"])
238 );
239
240 case "glo_term":
241 return array(
242 "glo_definition" => array("ids" => $a_rec["Id"])
243 );
244 }
245
246 return false;
247 }
248
249
256 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
257 {
258 $a_rec = $this->stripTags($a_rec);
259 switch ($a_entity) {
260 case "glo":
261
262 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
263 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
264 } else {
265 $newObj = new ilObjGlossary();
266 $newObj->create(true);
267 }
268
269 $newObj->setTitle($a_rec["Title"]);
270 $newObj->setDescription($a_rec["Description"]);
271 $newObj->setVirtualMode($a_rec["Virtual"]);
272 $newObj->setPresentationMode($a_rec["PresMode"]);
273 $newObj->setSnippetLength($a_rec["SnippetLength"]);
274 $newObj->setActiveGlossaryMenu($a_rec["GloMenuActive"]);
275 $newObj->setShowTaxonomy($a_rec["ShowTax"]);
276 if ($this->getCurrentInstallationId() > 0) {
277 $newObj->setImportId("il_" . $this->getCurrentInstallationId() . "_glo_" . $a_rec["Id"]);
278 }
279 $newObj->update(true);
280
281 $this->current_obj = $newObj;
282 $this->old_glo_id = $a_rec["Id"];
283 $a_mapping->addMapping("Modules/Glossary", "glo", $a_rec["Id"], $newObj->getId());
284 $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
285 $a_mapping->addMapping(
286 "Services/MetaData",
287 "md",
288 $a_rec["Id"] . ":0:glo",
289 $newObj->getId() . ":0:glo"
290 );
291 $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
292 break;
293
294 case "glo_term":
295
296 // id, glo_id, term, language, import_id
297
298 $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
299 $term = new ilGlossaryTerm();
300 $term->setGlossaryId($glo_id);
301 $term->setTerm($a_rec["Term"]);
302 $term->setLanguage($a_rec["Language"]);
303 if ($this->getCurrentInstallationId() > 0) {
304 $term->setImportId("il_" . $this->getCurrentInstallationId() . "_git_" . $a_rec["Id"]);
305 }
306 $term->create();
307 $term_id = $term->getId();
308 $this->log->debug("glo_term, import id: " . $term->getImportId() . ", term id: " . $term_id);
309
310 $a_mapping->addMapping(
311 "Modules/Glossary",
312 "term",
313 $a_rec["Id"],
314 $term_id
315 );
316
317 $a_mapping->addMapping(
318 "Services/Taxonomy",
319 "tax_item",
320 "glo:term:" . $a_rec["Id"],
321 $term_id
322 );
323
324 $a_mapping->addMapping(
325 "Services/Taxonomy",
326 "tax_item_obj_id",
327 "glo:term:" . $a_rec["Id"],
328 $glo_id
329 );
330
331 $a_mapping->addMapping(
332 "Services/AdvancedMetaData",
333 "advmd_sub_item",
334 "advmd:term:" . $a_rec["Id"],
335 $term_id
336 );
337 break;
338
339 case "glo_definition":
340
341 // id, term_id, short_text, nr, short_text_dirty
342
343 $term_id = (int) $a_mapping->getMapping("Modules/Glossary", "term", $a_rec["TermId"]);
344 if ((int) $term_id == 0) {
345 $this->log->debug("ERROR: Did not find glossary term glo_term id '" . $a_rec["TermId"] . "' for definition id '" . $a_rec["Id"] . "'.");
346 } else {
347 $def = new ilGlossaryDefinition();
348 $def->setTermId($term_id);
349 $def->setShortText($a_rec["ShortText"]);
350 $def->setNr($a_rec["Nr"]);
351 $def->setShortTextDirty($a_rec["ShortTextDirty"]);
352 // no metadata, no page creation
353 $def->create(true, true);
354
355 $a_mapping->addMapping("Modules/Glossary", "def", $a_rec["Id"], $def->getId());
356 $a_mapping->addMapping(
357 "Services/COPage",
358 "pg",
359 "gdf:" . $a_rec["Id"],
360 "gdf:" . $def->getId()
361 );
362 $a_mapping->addMapping(
363 "Services/MetaData",
364 "md",
365 $this->old_glo_id . ":" . $a_rec["Id"] . ":gdf",
366 $this->current_obj->getId() . ":" . $def->getId() . ":gdf"
367 );
368 }
369 break;
370
371 case "glo_advmd_col_order":
372 // glo_id, field_id, order_nr
373 // we save the ordering in the mapping, the glossary importer needs to fix this in the final
374 // processing
375 $a_mapping->addMapping("Modules/Glossary", "advmd_col_order", $a_rec["GloId"] . ":" . $a_rec["FieldId"], $a_rec["OrderNr"]);
376 break;
377
378 case "glo_auto_glossaries":
379 $auto_glo_id = ilObject::_lookupObjIdByImportId($a_rec["AutoGloId"]);
380 $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
381 if ($glo_id > 0 && $auto_glo_id > 0 && ilObject::_lookupType($auto_glo_id) == "glo") {
382 $glo = new ilObjGlossary($glo_id, false);
383 $glo->addAutoGlossary($auto_glo_id);
384 $glo->updateAutoGlossaries();
385 }
386 break;
387 }
388 }
389}
An exception for terminatinating execution or to throw for unit testing.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
stripTags(array $rec, array $omit_keys=[])
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
getCurrentInstallationId()
Get current installation id.
Glossary Data set class.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getSupportedVersions()
Get supported versions.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
getTypes($a_entity, $a_version)
Get field types for entity.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
Class ilGlossaryDefinition.
static getLogger($a_component_id)
Get component logger.
Class ilObjGlossary.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjIdByImportId($a_import_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB