ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
20{
24 protected $log;
25
29 function __construct()
30 {
31 $this->log = ilLoggerFactory::getLogger('glo');
32 parent::__construct();
33 }
34
40 public function getSupportedVersions()
41 {
42 return array("5.1.0");
43 }
44
51 function getXmlNamespace($a_entity, $a_schema_version)
52 {
53 return "http://www.ilias.de/xml/Modules/Glossary/".$a_entity;
54 }
55
63 protected function getTypes($a_entity, $a_version)
64 {
65 if ($a_entity == "glo")
66 {
67 switch ($a_version)
68 {
69 case "5.1.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 {
85 switch ($a_version)
86 {
87 case "5.1.0":
88 return array(
89 "Id" => "integer",
90 "GloId" => "integer",
91 "Term" => "text",
92 "Language" => "text",
93 "ImportId" => "text"
94 );
95 }
96 }
97
98 if ($a_entity == "glo_definition")
99 {
100 switch ($a_version)
101 {
102 case "5.1.0":
103 return array(
104 "Id" => "integer",
105 "TermId" => "integer",
106 "ShortText" => "text",
107 "Nr" => "integer",
108 "ShortTextDirty" => "integer"
109 );
110 }
111 }
112
113 if ($a_entity == "glo_advmd_col_order")
114 {
115 switch ($a_version)
116 {
117 case "5.1.0":
118 return array(
119 "GloId" => "integer",
120 "FieldId" => "text",
121 "OrderNr" => "integer"
122 );
123 }
124 }
125
126 }
127
134 function readData($a_entity, $a_version, $a_ids, $a_field = "")
135 {
136 global $ilDB;
137
138 if (!is_array($a_ids))
139 {
140 $a_ids = array($a_ids);
141 }
142
143 if ($a_entity == "glo")
144 {
145 switch ($a_version)
146 {
147 case "5.1.0":
148 $this->getDirectDataFromQuery("SELECT o.title, o.description, g.id, virtual, pres_mode, snippet_length, show_tax, glo_menu_active".
149 " FROM glossary g JOIN object_data o ".
150 " ON (g.id = o.obj_id) ".
151 " WHERE ".$ilDB->in("g.id", $a_ids, false, "integer"));
152 break;
153 }
154 }
155
156 if ($a_entity == "glo_term")
157 {
158 switch ($a_version)
159 {
160 case "5.1.0":
161 // todo: how does import id needs to be set?
162 $this->getDirectDataFromQuery("SELECT id, glo_id, term, language".
163 " FROM glossary_term ".
164 " WHERE ".$ilDB->in("glo_id", $a_ids, false, "integer"));
165 break;
166 }
167 }
168
169 if ($a_entity == "glo_definition")
170 {
171 switch ($a_version)
172 {
173 case "5.1.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 {
183 switch ($a_version)
184 {
185 case "5.1.0":
186 $this->getDirectDataFromQuery("SELECT glo_id, field_id, order_nr".
187 " FROM glo_advmd_col_order ".
188 " WHERE ".$ilDB->in("glo_id", $a_ids, false, "integer"));
189 break;
190 }
191 }
192 }
193
197 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
198 {
199 switch ($a_entity)
200 {
201 case "glo":
202 return array (
203 "glo_term" => array("ids" => $a_rec["Id"]),
204 "glo_advmd_col_order" => array("ids" => $a_rec["Id"])
205 );
206
207 case "glo_term":
208 return array (
209 "glo_definition" => array("ids" => $a_rec["Id"])
210 );
211 }
212
213 return false;
214 }
215
216
223 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
224 {
225 switch ($a_entity)
226 {
227 case "glo":
228
229 include_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
230 if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
231 {
232 $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
233 }
234 else
235 {
236 $newObj = new ilObjGlossary();
237 $newObj->create(true);
238 }
239
240 $newObj->setTitle($a_rec["Title"]);
241 $newObj->setDescription($a_rec["Description"]);
242 $newObj->setVirtualMode($a_rec["Virtual"]);
243 $newObj->setPresentationMode($a_rec["PresMode"]);
244 $newObj->setSnippetLength($a_rec["SnippetLength"]);
245 $newObj->setActiveGlossaryMenu($a_rec["GloMenuActive"]);
246 $newObj->setShowTaxonomy($a_rec["ShowTax"]);
247 $newObj->update(true);
248
249 $this->current_obj = $newObj;
250 $this->old_glo_id = $a_rec["Id"];
251 $a_mapping->addMapping("Modules/Glossary", "glo", $a_rec["Id"], $newObj->getId());
252 $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
253 $a_mapping->addMapping("Services/MetaData", "md",
254 $a_rec["Id"].":0:glo", $newObj->getId().":0:glo");
255 $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
256 break;
257
258 case "glo_term":
259
260 // id, glo_id, term, language, import_id
261
262 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
263 $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
264 $term = new ilGlossaryTerm();
265 $term->setGlossaryId($glo_id);
266 $term->setTerm($a_rec["Term"]);
267 $term->setLanguage($a_rec["Language"]);
268 if ($this->getCurrentInstallationId() > 0)
269 {
270 $term->setImportId("il_".$this->getCurrentInstallationId()."_git_".$a_rec["Id"]);
271 }
272 $term->create();
273 $term_id = $term->getId();
274 $this->log->debug("glo_term, import id: ".$term->getImportId().", term id: ".$term_id);
275
276 $a_mapping->addMapping("Modules/Glossary", "term",
277 $a_rec["Id"], $term_id);
278
279 $a_mapping->addMapping("Services/Taxonomy", "tax_item",
280 "glo:term:".$a_rec["Id"], $term_id);
281
282 $a_mapping->addMapping("Services/Taxonomy", "tax_item_obj_id",
283 "glo:term:".$a_rec["Id"], $glo_id);
284
285 $a_mapping->addMapping("Services/AdvancedMetaData", "advmd_sub_item",
286 "advmd:term:".$a_rec["Id"], $term_id);
287 break;
288
289 case "glo_definition":
290
291 // id, term_id, short_text, nr, short_text_dirty
292
293 include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
294 $term_id = (int) $a_mapping->getMapping("Modules/Glossary", "term", $a_rec["TermId"]);
295 if ((int) $term_id == 0)
296 {
297 $this->log->debug("ERROR: Did not find glossary term glo_term id '".$a_rec["TermId"]."' for definition id '".$a_rec["Id"]."'.");
298 }
299 else
300 {
301 $def = new ilGlossaryDefinition();
302 $def->setTermId($term_id);
303 $def->setShortText($a_rec["ShortText"]);
304 $def->setNr($a_rec["Nr"]);
305 $def->setShortTextDirty($a_rec["ShortTextDirty"]);
306 // no metadata, no page creation
307 $def->create(true, true);
308
309 $a_mapping->addMapping("Modules/Glossary", "def", $a_rec["Id"], $def->getId());
310 $a_mapping->addMapping("Services/COPage", "pg", "gdf:" . $a_rec["Id"],
311 "gdf:" . $def->getId());
312 $a_mapping->addMapping("Services/MetaData", "md",
313 $this->old_glo_id . ":" . $a_rec["Id"] . ":gdf", $this->current_obj->getId() . ":" . $def->getId() . ":gdf");
314 }
315 break;
316
317 case "glo_advmd_col_order":
318 // glo_id, field_id, order_nr
319 // we save the ordering in the mapping, the glossary importer needs to fix this in the final
320 // processing
321 $a_mapping->addMapping("Modules/Glossary", "advmd_col_order", $a_rec["GloId"].":".$a_rec["FieldId"], $a_rec["OrderNr"]);
322 break;
323 }
324 }
325}
326?>
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)
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.
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
global $ilDB