ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 switch ($a_entity) {
259 case "glo":
260
261 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
262 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
263 } else {
264 $newObj = new ilObjGlossary();
265 $newObj->create(true);
266 }
267
268 $newObj->setTitle($a_rec["Title"]);
269 $newObj->setDescription($a_rec["Description"]);
270 $newObj->setVirtualMode($a_rec["Virtual"]);
271 $newObj->setPresentationMode($a_rec["PresMode"]);
272 $newObj->setSnippetLength($a_rec["SnippetLength"]);
273 $newObj->setActiveGlossaryMenu($a_rec["GloMenuActive"]);
274 $newObj->setShowTaxonomy($a_rec["ShowTax"]);
275 if ($this->getCurrentInstallationId() > 0) {
276 $newObj->setImportId("il_" . $this->getCurrentInstallationId() . "_glo_" . $a_rec["Id"]);
277 }
278 $newObj->update(true);
279
280 $this->current_obj = $newObj;
281 $this->old_glo_id = $a_rec["Id"];
282 $a_mapping->addMapping("Modules/Glossary", "glo", $a_rec["Id"], $newObj->getId());
283 $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
284 $a_mapping->addMapping(
285 "Services/MetaData",
286 "md",
287 $a_rec["Id"] . ":0:glo",
288 $newObj->getId() . ":0:glo"
289 );
290 $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
291 break;
292
293 case "glo_term":
294
295 // id, glo_id, term, language, import_id
296
297 $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
298 $term = new ilGlossaryTerm();
299 $term->setGlossaryId($glo_id);
300 $term->setTerm($a_rec["Term"]);
301 $term->setLanguage($a_rec["Language"]);
302 if ($this->getCurrentInstallationId() > 0) {
303 $term->setImportId("il_" . $this->getCurrentInstallationId() . "_git_" . $a_rec["Id"]);
304 }
305 $term->create();
306 $term_id = $term->getId();
307 $this->log->debug("glo_term, import id: " . $term->getImportId() . ", term id: " . $term_id);
308
309 $a_mapping->addMapping(
310 "Modules/Glossary",
311 "term",
312 $a_rec["Id"],
313 $term_id
314 );
315
316 $a_mapping->addMapping(
317 "Services/Taxonomy",
318 "tax_item",
319 "glo:term:" . $a_rec["Id"],
320 $term_id
321 );
322
323 $a_mapping->addMapping(
324 "Services/Taxonomy",
325 "tax_item_obj_id",
326 "glo:term:" . $a_rec["Id"],
327 $glo_id
328 );
329
330 $a_mapping->addMapping(
331 "Services/AdvancedMetaData",
332 "advmd_sub_item",
333 "advmd:term:" . $a_rec["Id"],
334 $term_id
335 );
336 break;
337
338 case "glo_definition":
339
340 // id, term_id, short_text, nr, short_text_dirty
341
342 $term_id = (int) $a_mapping->getMapping("Modules/Glossary", "term", $a_rec["TermId"]);
343 if ((int) $term_id == 0) {
344 $this->log->debug("ERROR: Did not find glossary term glo_term id '" . $a_rec["TermId"] . "' for definition id '" . $a_rec["Id"] . "'.");
345 } else {
346 $def = new ilGlossaryDefinition();
347 $def->setTermId($term_id);
348 $def->setShortText($a_rec["ShortText"]);
349 $def->setNr($a_rec["Nr"]);
350 $def->setShortTextDirty($a_rec["ShortTextDirty"]);
351 // no metadata, no page creation
352 $def->create(true, true);
353
354 $a_mapping->addMapping("Modules/Glossary", "def", $a_rec["Id"], $def->getId());
355 $a_mapping->addMapping(
356 "Services/COPage",
357 "pg",
358 "gdf:" . $a_rec["Id"],
359 "gdf:" . $def->getId()
360 );
361 $a_mapping->addMapping(
362 "Services/MetaData",
363 "md",
364 $this->old_glo_id . ":" . $a_rec["Id"] . ":gdf",
365 $this->current_obj->getId() . ":" . $def->getId() . ":gdf"
366 );
367 }
368 break;
369
370 case "glo_advmd_col_order":
371 // glo_id, field_id, order_nr
372 // we save the ordering in the mapping, the glossary importer needs to fix this in the final
373 // processing
374 $a_mapping->addMapping("Modules/Glossary", "advmd_col_order", $a_rec["GloId"] . ":" . $a_rec["FieldId"], $a_rec["OrderNr"]);
375 break;
376
377 case "glo_auto_glossaries":
378 $auto_glo_id = ilObject::_lookupObjIdByImportId($a_rec["AutoGloId"]);
379 $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
380 if ($glo_id > 0 && $auto_glo_id > 0 && ilObject::_lookupType($auto_glo_id) == "glo") {
381 $glo = new ilObjGlossary($glo_id, false);
382 $glo->addAutoGlossary($auto_glo_id);
383 $glo->updateAutoGlossaries();
384 }
385 break;
386 }
387 }
388}
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...
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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB
$DIC
Definition: xapitoken.php:46