ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilGlossaryDataSet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/DataSet/classes/class.ilDataSet.php");
5
21{
25 protected $log;
26
30 public function __construct()
31 {
32 global $DIC;
33
34 $this->db = $DIC->database();
35 $this->log = ilLoggerFactory::getLogger('glo');
36 parent::__construct();
37 }
38
44 public function getSupportedVersions()
45 {
46 return array("5.1.0", "5.4.0");
47 }
48
55 public function getXmlNamespace($a_entity, $a_schema_version)
56 {
57 return "http://www.ilias.de/xml/Modules/Glossary/" . $a_entity;
58 }
59
67 protected function getTypes($a_entity, $a_version)
68 {
69 if ($a_entity == "glo") {
70 switch ($a_version) {
71 case "5.1.0":
72 case "5.4.0":
73 return array(
74 "Id" => "integer",
75 "Title" => "text",
76 "Description" => "text",
77 "Virtual" => "text",
78 "PresMode" => "text",
79 "SnippetLength" => "integer",
80 "GloMenuActive" => "text",
81 "ShowTax" => "integer"
82 );
83 }
84 }
85
86 if ($a_entity == "glo_term") {
87 switch ($a_version) {
88 case "5.1.0":
89 case "5.4.0":
90 return array(
91 "Id" => "integer",
92 "GloId" => "integer",
93 "Term" => "text",
94 "Language" => "text",
95 "ImportId" => "text"
96 );
97 }
98 }
99
100 if ($a_entity == "glo_definition") {
101 switch ($a_version) {
102 case "5.1.0":
103 case "5.4.0":
104 return array(
105 "Id" => "integer",
106 "TermId" => "integer",
107 "ShortText" => "text",
108 "Nr" => "integer",
109 "ShortTextDirty" => "integer"
110 );
111 }
112 }
113
114 if ($a_entity == "glo_advmd_col_order") {
115 switch ($a_version) {
116 case "5.1.0":
117 case "5.4.0":
118 return array(
119 "GloId" => "integer",
120 "FieldId" => "text",
121 "OrderNr" => "integer"
122 );
123 }
124 }
125
126 if ($a_entity == "glo_auto_glossaries") {
127 switch ($a_version) {
128 case "5.4.0":
129 return array(
130 "GloId" => "integer",
131 "AutoGloId" => "text"
132 );
133 }
134 }
135 }
136
143 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
144 {
146
147 if (!is_array($a_ids)) {
148 $a_ids = array($a_ids);
149 }
150
151 if ($a_entity == "glo") {
152 switch ($a_version) {
153 case "5.1.0":
154 case "5.4.0":
155 $this->getDirectDataFromQuery("SELECT o.title, o.description, g.id, g.virtual, pres_mode, snippet_length, show_tax, glo_menu_active" .
156 " FROM glossary g JOIN object_data o " .
157 " ON (g.id = o.obj_id) " .
158 " WHERE " . $ilDB->in("g.id", $a_ids, false, "integer"));
159 break;
160 }
161 }
162
163 if ($a_entity == "glo_term") {
164 switch ($a_version) {
165 case "5.1.0":
166 $this->getDirectDataFromQuery("SELECT id, glo_id, term, language" .
167 " FROM glossary_term " .
168 " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
169 break;
170
171 case "5.4.0":
172 $this->getDirectDataFromQuery("SELECT id, glo_id, term, language" .
173 " FROM glossary_term " .
174 " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
175
176 $set = $ilDB->query("SELECT r.term_id, r.glo_id, t.term, t.language " .
177 "FROM glo_term_reference r JOIN glossary_term t ON (r.term_id = t.id) " .
178 " WHERE " . $ilDB->in("r.glo_id", $a_ids, false, "integer"));
179 while ($rec = $ilDB->fetchAssoc($set)) {
180 $this->data[] = [
181 "Id" => $rec["term_id"],
182 "GloId" => $rec["glo_id"],
183 "Term" => $rec["term"],
184 "Language" => $rec["language"],
185 ];
186 }
187 break;
188 }
189 }
190
191 if ($a_entity == "glo_definition") {
192 switch ($a_version) {
193 case "5.1.0":
194 case "5.4.0":
195 $this->getDirectDataFromQuery("SELECT id, term_id, short_text, nr, short_text_dirty" .
196 " FROM glossary_definition " .
197 " WHERE " . $ilDB->in("term_id", $a_ids, false, "integer"));
198 break;
199 }
200 }
201
202 if ($a_entity == "glo_advmd_col_order") {
203 switch ($a_version) {
204 case "5.1.0":
205 case "5.4.0":
206 $this->getDirectDataFromQuery("SELECT glo_id, field_id, order_nr" .
207 " FROM glo_advmd_col_order " .
208 " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
209 break;
210 }
211 }
212
213 if ($a_entity == "glo_auto_glossaries") {
214 switch ($a_version) {
215 case "5.4.0":
216 $set = $ilDB->query("SELECT * FROM glo_glossaries " .
217 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
218 $this->data = [];
219 while ($rec = $ilDB->fetchAssoc($set)) {
220 $this->data[] = [
221 "GloId" => $rec["id"],
222 "AutoGloId" => "il_" . IL_INST_ID . "_glo_" . $rec["glo_id"]
223 ];
224 }
225 break;
226 }
227 }
228 }
229
233 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
234 {
235 switch ($a_entity) {
236 case "glo":
237 return array(
238 "glo_term" => array("ids" => $a_rec["Id"]),
239 "glo_advmd_col_order" => array("ids" => $a_rec["Id"]),
240 "glo_auto_glossaries" => array("ids" => $a_rec["Id"])
241 );
242
243 case "glo_term":
244 return array(
245 "glo_definition" => array("ids" => $a_rec["Id"])
246 );
247 }
248
249 return false;
250 }
251
252
259 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
260 {
261 switch ($a_entity) {
262 case "glo":
263
264 include_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
265 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
266 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
267 } else {
268 $newObj = new ilObjGlossary();
269 $newObj->create(true);
270 }
271
272 $newObj->setTitle($a_rec["Title"]);
273 $newObj->setDescription($a_rec["Description"]);
274 $newObj->setVirtualMode($a_rec["Virtual"]);
275 $newObj->setPresentationMode($a_rec["PresMode"]);
276 $newObj->setSnippetLength($a_rec["SnippetLength"]);
277 $newObj->setActiveGlossaryMenu($a_rec["GloMenuActive"]);
278 $newObj->setShowTaxonomy($a_rec["ShowTax"]);
279 if ($this->getCurrentInstallationId() > 0) {
280 $newObj->setImportId("il_" . $this->getCurrentInstallationId() . "_glo_" . $a_rec["Id"]);
281 }
282 $newObj->update(true);
283
284 $this->current_obj = $newObj;
285 $this->old_glo_id = $a_rec["Id"];
286 $a_mapping->addMapping("Modules/Glossary", "glo", $a_rec["Id"], $newObj->getId());
287 $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
288 $a_mapping->addMapping(
289 "Services/MetaData",
290 "md",
291 $a_rec["Id"] . ":0:glo",
292 $newObj->getId() . ":0:glo"
293 );
294 $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
295 break;
296
297 case "glo_term":
298
299 // id, glo_id, term, language, import_id
300
301 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
302 $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
303 $term = new ilGlossaryTerm();
304 $term->setGlossaryId($glo_id);
305 $term->setTerm($a_rec["Term"]);
306 $term->setLanguage($a_rec["Language"]);
307 if ($this->getCurrentInstallationId() > 0) {
308 $term->setImportId("il_" . $this->getCurrentInstallationId() . "_git_" . $a_rec["Id"]);
309 }
310 $term->create();
311 $term_id = $term->getId();
312 $this->log->debug("glo_term, import id: " . $term->getImportId() . ", term id: " . $term_id);
313
314 $a_mapping->addMapping(
315 "Modules/Glossary",
316 "term",
317 $a_rec["Id"],
318 $term_id
319 );
320
321 $a_mapping->addMapping(
322 "Services/Taxonomy",
323 "tax_item",
324 "glo:term:" . $a_rec["Id"],
325 $term_id
326 );
327
328 $a_mapping->addMapping(
329 "Services/Taxonomy",
330 "tax_item_obj_id",
331 "glo:term:" . $a_rec["Id"],
332 $glo_id
333 );
334
335 $a_mapping->addMapping(
336 "Services/AdvancedMetaData",
337 "advmd_sub_item",
338 "advmd:term:" . $a_rec["Id"],
339 $term_id
340 );
341 break;
342
343 case "glo_definition":
344
345 // id, term_id, short_text, nr, short_text_dirty
346
347 include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
348 $term_id = (int) $a_mapping->getMapping("Modules/Glossary", "term", $a_rec["TermId"]);
349 if ((int) $term_id == 0) {
350 $this->log->debug("ERROR: Did not find glossary term glo_term id '" . $a_rec["TermId"] . "' for definition id '" . $a_rec["Id"] . "'.");
351 } else {
353 $def->setTermId($term_id);
354 $def->setShortText($a_rec["ShortText"]);
355 $def->setNr($a_rec["Nr"]);
356 $def->setShortTextDirty($a_rec["ShortTextDirty"]);
357 // no metadata, no page creation
358 $def->create(true, true);
359
360 $a_mapping->addMapping("Modules/Glossary", "def", $a_rec["Id"], $def->getId());
361 $a_mapping->addMapping(
362 "Services/COPage",
363 "pg",
364 "gdf:" . $a_rec["Id"],
365 "gdf:" . $def->getId()
366 );
367 $a_mapping->addMapping(
368 "Services/MetaData",
369 "md",
370 $this->old_glo_id . ":" . $a_rec["Id"] . ":gdf",
371 $this->current_obj->getId() . ":" . $def->getId() . ":gdf"
372 );
373 }
374 break;
375
376 case "glo_advmd_col_order":
377 // glo_id, field_id, order_nr
378 // we save the ordering in the mapping, the glossary importer needs to fix this in the final
379 // processing
380 $a_mapping->addMapping("Modules/Glossary", "advmd_col_order", $a_rec["GloId"] . ":" . $a_rec["FieldId"], $a_rec["OrderNr"]);
381 break;
382
383 case "glo_auto_glossaries":
384 $auto_glo_id = ilObject::_lookupObjIdByImportId($a_rec["AutoGloId"]);
385 $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
386 if ($glo_id > 0 && $auto_glo_id > 0 && ilObject::_lookupType($auto_glo_id) == "glo") {
387 $glo = new ilObjGlossary($glo_id, false);
388 $glo->addAutoGlossary($auto_glo_id);
389 $glo->updateAutoGlossaries();
390 }
391 break;
392 }
393 }
394}
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.
Class ilGlossaryTerm.
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
$def
Definition: croninfo.php:21
global $DIC
Definition: saml.php:7
global $ilDB
$this data['403_header']