ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
20 {
24  protected $log;
25 
29  public function __construct()
30  {
31  global $DIC;
32 
33  $this->db = $DIC->database();
34  $this->log = ilLoggerFactory::getLogger('glo');
35  parent::__construct();
36  }
37 
43  public function getSupportedVersions()
44  {
45  return array("5.1.0");
46  }
47 
54  public function getXmlNamespace($a_entity, $a_schema_version)
55  {
56  return "http://www.ilias.de/xml/Modules/Glossary/" . $a_entity;
57  }
58 
66  protected function getTypes($a_entity, $a_version)
67  {
68  if ($a_entity == "glo") {
69  switch ($a_version) {
70  case "5.1.0":
71  return array(
72  "Id" => "integer",
73  "Title" => "text",
74  "Description" => "text",
75  "Virtual" => "text",
76  "PresMode" => "text",
77  "SnippetLength" => "integer",
78  "GloMenuActive" => "text",
79  "ShowTax" => "integer"
80  );
81  }
82  }
83 
84  if ($a_entity == "glo_term") {
85  switch ($a_version) {
86  case "5.1.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  return array(
101  "Id" => "integer",
102  "TermId" => "integer",
103  "ShortText" => "text",
104  "Nr" => "integer",
105  "ShortTextDirty" => "integer"
106  );
107  }
108  }
109 
110  if ($a_entity == "glo_advmd_col_order") {
111  switch ($a_version) {
112  case "5.1.0":
113  return array(
114  "GloId" => "integer",
115  "FieldId" => "text",
116  "OrderNr" => "integer"
117  );
118  }
119  }
120  }
121 
128  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
129  {
130  $ilDB = $this->db;
131 
132  if (!is_array($a_ids)) {
133  $a_ids = array($a_ids);
134  }
135 
136  if ($a_entity == "glo") {
137  switch ($a_version) {
138  case "5.1.0":
139  $this->getDirectDataFromQuery("SELECT o.title, o.description, g.id, g.virtual, pres_mode, snippet_length, show_tax, glo_menu_active" .
140  " FROM glossary g JOIN object_data o " .
141  " ON (g.id = o.obj_id) " .
142  " WHERE " . $ilDB->in("g.id", $a_ids, false, "integer"));
143  break;
144  }
145  }
146 
147  if ($a_entity == "glo_term") {
148  switch ($a_version) {
149  case "5.1.0":
150  // todo: how does import id needs to be set?
151  $this->getDirectDataFromQuery("SELECT id, glo_id, term, language" .
152  " FROM glossary_term " .
153  " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
154  break;
155  }
156  }
157 
158  if ($a_entity == "glo_definition") {
159  switch ($a_version) {
160  case "5.1.0":
161  $this->getDirectDataFromQuery("SELECT id, term_id, short_text, nr, short_text_dirty" .
162  " FROM glossary_definition " .
163  " WHERE " . $ilDB->in("term_id", $a_ids, false, "integer"));
164  break;
165  }
166  }
167 
168  if ($a_entity == "glo_advmd_col_order") {
169  switch ($a_version) {
170  case "5.1.0":
171  $this->getDirectDataFromQuery("SELECT glo_id, field_id, order_nr" .
172  " FROM glo_advmd_col_order " .
173  " WHERE " . $ilDB->in("glo_id", $a_ids, false, "integer"));
174  break;
175  }
176  }
177  }
178 
182  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
183  {
184  switch ($a_entity) {
185  case "glo":
186  return array(
187  "glo_term" => array("ids" => $a_rec["Id"]),
188  "glo_advmd_col_order" => array("ids" => $a_rec["Id"])
189  );
190 
191  case "glo_term":
192  return array(
193  "glo_definition" => array("ids" => $a_rec["Id"])
194  );
195  }
196 
197  return false;
198  }
199 
200 
207  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
208  {
209  switch ($a_entity) {
210  case "glo":
211 
212  include_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
213  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
214  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
215  } else {
216  $newObj = new ilObjGlossary();
217  $newObj->create(true);
218  }
219 
220  $newObj->setTitle($a_rec["Title"]);
221  $newObj->setDescription($a_rec["Description"]);
222  $newObj->setVirtualMode($a_rec["Virtual"]);
223  $newObj->setPresentationMode($a_rec["PresMode"]);
224  $newObj->setSnippetLength($a_rec["SnippetLength"]);
225  $newObj->setActiveGlossaryMenu($a_rec["GloMenuActive"]);
226  $newObj->setShowTaxonomy($a_rec["ShowTax"]);
227  $newObj->update(true);
228 
229  $this->current_obj = $newObj;
230  $this->old_glo_id = $a_rec["Id"];
231  $a_mapping->addMapping("Modules/Glossary", "glo", $a_rec["Id"], $newObj->getId());
232  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
233  $a_mapping->addMapping(
234  "Services/MetaData",
235  "md",
236  $a_rec["Id"] . ":0:glo",
237  $newObj->getId() . ":0:glo"
238  );
239  $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
240  break;
241 
242  case "glo_term":
243 
244  // id, glo_id, term, language, import_id
245 
246  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
247  $glo_id = (int) $a_mapping->getMapping("Modules/Glossary", "glo", $a_rec["GloId"]);
248  $term = new ilGlossaryTerm();
249  $term->setGlossaryId($glo_id);
250  $term->setTerm($a_rec["Term"]);
251  $term->setLanguage($a_rec["Language"]);
252  if ($this->getCurrentInstallationId() > 0) {
253  $term->setImportId("il_" . $this->getCurrentInstallationId() . "_git_" . $a_rec["Id"]);
254  }
255  $term->create();
256  $term_id = $term->getId();
257  $this->log->debug("glo_term, import id: " . $term->getImportId() . ", term id: " . $term_id);
258 
259  $a_mapping->addMapping(
260  "Modules/Glossary",
261  "term",
262  $a_rec["Id"],
263  $term_id
264  );
265 
266  $a_mapping->addMapping(
267  "Services/Taxonomy",
268  "tax_item",
269  "glo:term:" . $a_rec["Id"],
270  $term_id
271  );
272 
273  $a_mapping->addMapping(
274  "Services/Taxonomy",
275  "tax_item_obj_id",
276  "glo:term:" . $a_rec["Id"],
277  $glo_id
278  );
279 
280  $a_mapping->addMapping(
281  "Services/AdvancedMetaData",
282  "advmd_sub_item",
283  "advmd:term:" . $a_rec["Id"],
284  $term_id
285  );
286  break;
287 
288  case "glo_definition":
289 
290  // id, term_id, short_text, nr, short_text_dirty
291 
292  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
293  $term_id = (int) $a_mapping->getMapping("Modules/Glossary", "term", $a_rec["TermId"]);
294  if ((int) $term_id == 0) {
295  $this->log->debug("ERROR: Did not find glossary term glo_term id '" . $a_rec["TermId"] . "' for definition id '" . $a_rec["Id"] . "'.");
296  } else {
297  $def = new ilGlossaryDefinition();
298  $def->setTermId($term_id);
299  $def->setShortText($a_rec["ShortText"]);
300  $def->setNr($a_rec["Nr"]);
301  $def->setShortTextDirty($a_rec["ShortTextDirty"]);
302  // no metadata, no page creation
303  $def->create(true, true);
304 
305  $a_mapping->addMapping("Modules/Glossary", "def", $a_rec["Id"], $def->getId());
306  $a_mapping->addMapping(
307  "Services/COPage",
308  "pg",
309  "gdf:" . $a_rec["Id"],
310  "gdf:" . $def->getId()
311  );
312  $a_mapping->addMapping(
313  "Services/MetaData",
314  "md",
315  $this->old_glo_id . ":" . $a_rec["Id"] . ":gdf",
316  $this->current_obj->getId() . ":" . $def->getId() . ":gdf"
317  );
318  }
319  break;
320 
321  case "glo_advmd_col_order":
322  // glo_id, field_id, order_nr
323  // we save the ordering in the mapping, the glossary importer needs to fix this in the final
324  // processing
325  $a_mapping->addMapping("Modules/Glossary", "advmd_col_order", $a_rec["GloId"] . ":" . $a_rec["FieldId"], $a_rec["OrderNr"]);
326  break;
327  }
328  }
329 }
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
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 ...
global $DIC
Definition: saml.php:7
Class ilGlossaryTerm.
Class ilObjGlossary.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
getSupportedVersions()
Get supported versions.
Glossary Data set class.
getCurrentInstallationId()
Get current installation id.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
Class ilGlossaryDefinition.
global $ilDB
$def
Definition: croninfo.php:21
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
static getLogger($a_component_id)
Get component logger.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getTypes($a_entity, $a_version)
Get field types for entity.