ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLearningModuleDataSet.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 
5 
20 {
21  protected $master_lang_only = false;
22  protected $transl_into = false;
23  protected $transl_into_lm = null;
24  protected $transl_lang = "";
25 
29  protected $lm_log;
30 
34  public function __construct()
35  {
37 
38  $this->lm_log = ilLoggerFactory::getLogger('lm');
39  }
45  public function setMasterLanguageOnly($a_val)
46  {
47  $this->master_lang_only = $a_val;
48  }
49 
55  public function getMasterLanguageOnly()
56  {
58  }
59 
66  public function setTranslationImportMode($a_lm, $a_lang = "")
67  {
68  if ($a_lm != null) {
69  $this->transl_into = true;
70  $this->transl_into_lm = $a_lm;
71  $this->transl_lang = $a_lang;
72  } else {
73  $this->transl_into = false;
74  }
75  }
76 
82  public function getTranslationImportMode()
83  {
84  return $this->transl_into;
85  }
86 
92  public function getTranslationLM()
93  {
94  return $this->transl_into_lm;
95  }
96 
102  public function getTranslationLang()
103  {
104  return $this->transl_lang;
105  }
106 
113  public function getSupportedVersions()
114  {
115  return array("5.1.0", "5.4.0");
116  }
117 
124  public function getXmlNamespace($a_entity, $a_schema_version)
125  {
126  return "http://www.ilias.de/xml/Modules/LearningModule/" . $a_entity;
127  }
128 
136  protected function getTypes($a_entity, $a_version)
137  {
138  if ($a_entity == "lm") {
139  switch ($a_version) {
140  case "5.1.0":
141  return array(
142  "Id" => "integer",
143  "Title" => "text",
144  "Description" => "text",
145  "DefaultLayout" => "text",
146  "PageHeader" => "text",
147  "TocActive" => "text",
148  "LMMenuActive" => "text",
149  "TOCMode" => "text",
150  "PrintViewActive" => "text",
151  "Numbering" => "text",
152  "HistUserComments" => "text",
153  "PublicAccessMode" => "text",
154  "PubNotes" => "text",
155  "HeaderPage" => "integer",
156  "FooterPage" => "integer",
157  "LayoutPerPage" => "integer",
158  "Rating" => "integer",
159  "HideHeadFootPrint" => "integer",
160  "DisableDefFeedback" => "integer",
161  "RatingPages" => "integer",
162  "ProgrIcons" => "integer",
163  "StoreTries" => "integer",
164  "RestrictForwNav" => "integer",
165  "Comments" => "integer",
166  "ForTranslation" => "integer",
167  "StyleId" => "integer"
168  );
169 
170  case "5.4.0":
171  return array(
172  "Id" => "integer",
173  "Title" => "text",
174  "Description" => "text",
175  "DefaultLayout" => "text",
176  "PageHeader" => "text",
177  "TocActive" => "text",
178  "LMMenuActive" => "text",
179  "TOCMode" => "text",
180  "PrintViewActive" => "text",
181  "NoGloAppendix" => "text",
182  "Numbering" => "text",
183  "HistUserComments" => "text",
184  "PublicAccessMode" => "text",
185  "PubNotes" => "text",
186  "HeaderPage" => "integer",
187  "FooterPage" => "integer",
188  "LayoutPerPage" => "integer",
189  "Rating" => "integer",
190  "HideHeadFootPrint" => "integer",
191  "DisableDefFeedback" => "integer",
192  "RatingPages" => "integer",
193  "ProgrIcons" => "integer",
194  "StoreTries" => "integer",
195  "RestrictForwNav" => "integer",
196  "Comments" => "integer",
197  "ForTranslation" => "integer",
198  "StyleId" => "integer"
199  );
200 
201  }
202  }
203 
204  if ($a_entity == "lm_tree") {
205  switch ($a_version) {
206  case "5.1.0":
207  case "5.4.0":
208  return array(
209  "LmId" => "integer",
210  "Child" => "integer",
211  "Parent" => "integer",
212  "Depth" => "integer",
213  "Type" => "text",
214  "Title" => "text",
215  "ShortTitle" => "text",
216  "PublicAccess" => "text",
217  "Active" => "text",
218  "Layout" => "text",
219  "ImportId" => "text"
220  );
221  }
222  }
223 
224  if ($a_entity == "lm_menu") {
225  switch ($a_version) {
226  case "5.1.0":
227  case "5.4.0":
228  return array(
229  "LmId" => "integer",
230  "LinkType" => "text",
231  "Title" => "text",
232  "Target" => "text",
233  "LinkRefId" => "text",
234  "Active" => "text"
235  );
236  }
237  }
238 
239  if ($a_entity == "lm_data_transl") {
240  switch ($a_version) {
241  case "5.1.0":
242  case "5.4.0":
243  return array(
244  "Id" => "integer",
245  "Lang" => "text",
246  "Title" => "text",
247  "ShortTitle" => "text"
248  );
249  }
250  }
251  }
252 
259  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
260  {
261  $ilDB = $this->db;
262 
263  if (!is_array($a_ids)) {
264  $a_ids = array($a_ids);
265  }
266 
267  if ($a_entity == "lm") {
268  switch ($a_version) {
269  case "5.1.0":
270  case "5.4.0":
271  switch ($a_version) {
272  case "5.1.0":
273  $q = "SELECT id, title, description," .
274  " default_layout, page_header, toc_active, lm_menu_active, toc_mode, print_view_active, numbering," .
275  " hist_user_comments, public_access_mode, header_page, footer_page, layout_per_page, rating, " .
276  " hide_head_foot_print, disable_def_feedback, rating_pages, store_tries, restrict_forw_nav, progr_icons, stylesheet style_id" .
277  " FROM content_object JOIN object_data ON (content_object.id = object_data.obj_id)" .
278  " WHERE " . $ilDB->in("id", $a_ids, false, "integer");
279  break;
280 
281  case "5.4.0":
282  $q = "SELECT id, title, description," .
283  " default_layout, page_header, toc_active, lm_menu_active, toc_mode, print_view_active, numbering," .
284  " hist_user_comments, public_access_mode, no_glo_appendix, header_page, footer_page, layout_per_page, rating, " .
285  " hide_head_foot_print, disable_def_feedback, rating_pages, store_tries, restrict_forw_nav, progr_icons, stylesheet style_id" .
286  " FROM content_object JOIN object_data ON (content_object.id = object_data.obj_id)" .
287  " WHERE " . $ilDB->in("id", $a_ids, false, "integer");
288 
289  }
290 
291  $set = $ilDB->query($q);
292  $this->data = array();
293  while ($rec = $ilDB->fetchAssoc($set)) {
294  // comments activated?
295  $rec["comments"] = ilNote::commentsActivated($rec["id"], 0, "lm");
296 
297  if ($this->getMasterLanguageOnly()) {
298  $rec["for_translation"] = 1;
299  }
300  $tmp = array();
301  foreach ($rec as $k => $v) {
302  $tmp[$this->convertToLeadingUpper($k)]
303  = $v;
304  }
305  $rec = $tmp;
306 
307  $this->data[] = $rec;
308  }
309  break;
310 
311 
312  break;
313  }
314  }
315 
316  if ($a_entity == "lm_tree") {
317  switch ($a_version) {
318  case "5.1.0":
319  case "5.4.0":
320  // the order by lft is very important, this ensures that parent nodes are written before
321  // their childs and that the import can add nodes simply with a "add at last child" target
322  $q = "SELECT lm_tree.lm_id, child, parent, depth, type, title, short_title, public_access, active, layout, import_id" .
323  " FROM lm_tree JOIN lm_data ON (lm_tree.child = lm_data.obj_id)" .
324  " WHERE " . $ilDB->in("lm_tree.lm_id", $a_ids, false, "integer") .
325  " ORDER BY lft";
326 
327  $set = $ilDB->query($q);
328  $this->data = array();
329  $obj_ids = array();
330  while ($rec = $ilDB->fetchAssoc($set)) {
331  $set2 = $ilDB->query("SELECT for_translation FROM content_object WHERE id = " . $ilDB->quote($rec["lm_id"], "integer"));
332  $rec2 = $ilDB->fetchAssoc($set2);
333  if (!$rec2["for_translation"]) {
334  $rec["import_id"] = "il_" . IL_INST_ID . "_" . $rec["type"] . "_" . $rec["child"];
335  }
336  $tmp = array();
337  foreach ($rec as $k => $v) {
338  $tmp[$this->convertToLeadingUpper($k)]
339  = $v;
340  }
341  $rec = $tmp;
342  $obj_ids[] = $rec["Child"];
343  $this->data[] = $rec;
344  }
345 
346  // add free pages #18976
347  $set3 = $ilDB->query($q = "SELECT lm_id, type, title, short_title, public_access, active, layout, import_id, obj_id child FROM lm_data " .
348  "WHERE " . $ilDB->in("lm_id", $a_ids, false, "integer") .
349  " AND " . $ilDB->in("obj_id", $obj_ids, true, "integer") .
350  " AND type = " . $ilDB->quote("pg", "text"));
351  while ($rec3 = $ilDB->fetchAssoc($set3)) {
352  $set2 = $ilDB->query("SELECT for_translation FROM content_object WHERE id = " . $ilDB->quote($rec3["lm_id"], "integer"));
353  $rec2 = $ilDB->fetchAssoc($set2);
354  if (!$rec2["for_translation"]) {
355  $rec3["import_id"] = "il_" . IL_INST_ID . "_pg_" . $rec3["child"];
356  }
357  $rec3["type"] = "free_pg";
358  $rec3["depth"] = 0;
359  $rec3["parent"] = 0;
360  $tmp = array();
361  foreach ($rec3 as $k => $v) {
362  $tmp[$this->convertToLeadingUpper($k)]
363  = $v;
364  }
365  $this->data[] = $tmp;
366  }
367  break;
368  }
369  }
370 
371  if ($a_entity == "lm_menu") {
372  switch ($a_version) {
373  case "5.1.0":
374  case "5.4.0":
375  $this->getDirectDataFromQuery("SELECT lm_id, link_type, title, target, link_ref_id, active" .
376  " FROM lm_menu " .
377  " WHERE " . $ilDB->in("lm_id", $a_ids, false, "integer"));
378  break;
379  }
380  }
381 
382  if ($a_entity == "lm_data_transl") {
383  switch ($a_version) {
384  case "5.1.0":
385  case "5.4.0":
386  $this->getDirectDataFromQuery("SELECT id, lang, title, short_title" .
387  " FROM lm_data_transl " .
388  " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
389  break;
390  }
391  }
392  }
393 
397  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
398  {
399  switch ($a_entity) {
400  case "lm":
401  return array(
402  "lm_tree" => array("ids" => $a_rec["Id"]),
403  "lm_menu" => array("ids" => $a_rec["Id"])
404  );
405 
406  case "lm_tree":
407  if ($this->getMasterLanguageOnly()) {
408  return false;
409  } else {
410  return array(
411  "lm_data_transl" => array("ids" => $a_rec["Child"])
412  );
413  }
414  }
415 
416  return false;
417  }
418 
419 
426  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
427  {
428  //var_dump($a_rec);
429 
430  switch ($a_entity) {
431  case "lm":
432 
433  if ($this->getTranslationImportMode()) {
434  return;
435  }
436 
437  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
438  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
439  } else {
440  $newObj = new ilObjLearningModule();
441  $newObj->setType("lm");
442  $newObj->create(true);
443  $newObj->createLMTree();
444  }
445 
446  $newObj->setTitle($a_rec["Title"]);
447  $newObj->setDescription($a_rec["Description"]);
448  $newObj->setLayout($a_rec["DefaultLayout"]);
449  $newObj->setPageHeader($a_rec["PageHeader"]);
450  $newObj->setActiveTOC(ilUtil::yn2tf($a_rec["TocActive"]));
451  $newObj->setActiveLMMenu(ilUtil::yn2tf($a_rec["LmMenuActive"]));
452  $newObj->setTOCMode($a_rec["TocMode"]);
453  $newObj->setActivePrintView(ilUtil::yn2tf($a_rec["PrintViewActive"]));
454  $newObj->setActivePreventGlossaryAppendix(ilUtil::yn2tf($a_rec["NoGloAppendix"]));
455  $newObj->setActiveNumbering(ilUtil::yn2tf($a_rec["Numbering"]));
456  $newObj->setHistoryUserComments(ilUtil::yn2tf($a_rec["HistUserComments"]));
457  $newObj->setPublicAccessMode($a_rec["PublicAccessMode"]);
458  $newObj->setPublicNotes(ilUtil::yn2tf($a_rec["PubNotes"]));
459  // Header Page/ Footer Page ???
460  $newObj->setLayoutPerPage($a_rec["LayoutPerPage"]);
461  $newObj->setRating($a_rec["Rating"]);
462  $newObj->setHideHeaderFooterPrint($a_rec["HideHeadFootPrint"]);
463  $newObj->setDisableDefaultFeedback($a_rec["DisableDefFeedback"]);
464  $newObj->setRatingPages($a_rec["RatingPages"]);
465  $newObj->setForTranslation($a_rec["ForTranslation"]);
466  $newObj->setProgressIcons($a_rec["ProgrIcons"]);
467  $newObj->setStoreTries($a_rec["StoreTries"]);
468  $newObj->setRestrictForwardNavigation($a_rec["RestrictForwNav"]);
469  if ($a_rec["HeaderPage"] > 0) {
470  $a_mapping->addMapping("Modules/LearningModule", "lm_header_page", $a_rec["HeaderPage"], "-");
471  }
472  if ($a_rec["FooterPage"] > 0) {
473  $a_mapping->addMapping("Modules/LearningModule", "lm_footer_page", $a_rec["FooterPage"], "-");
474  }
475 
476  $newObj->update(true);
477  $this->current_obj = $newObj;
478 
479  // activated comments
480  ilNote::activateComments($newObj->getId(), 0, "lm", (int) $a_rec["Comments"]);
481 
482  $a_mapping->addMapping("Modules/LearningModule", "lm", $a_rec["Id"], $newObj->getId());
483  $a_mapping->addMapping("Modules/LearningModule", "lm_style", $newObj->getId(), $a_rec["StyleId"]);
484  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
485  $a_mapping->addMapping(
486  "Services/MetaData",
487  "md",
488  $a_rec["Id"] . ":0:lm",
489  $newObj->getId() . ":0:lm"
490  );
491  break;
492 
493  case "lm_tree":
494  if (!$this->getTranslationImportMode()) {
495  switch ($a_rec["Type"]) {
496  case "st":
497  $parent = (int) $a_mapping->getMapping("Modules/LearningModule", "lm_tree", $a_rec["Parent"]);
498  $st_obj = new ilStructureObject($this->current_obj);
499  $st_obj->setType("st");
500  $st_obj->setLMId($this->current_obj->getId());
501  $st_obj->setTitle($a_rec["Title"]);
502  $st_obj->setShortTitle($a_rec["ShortTitle"]);
503  $st_obj->setImportId($a_rec["ImportId"]);
504  $st_obj->create(true);
505  ilLMObject::putInTree($st_obj, $parent, IL_LAST_NODE);
506  $a_mapping->addMapping(
507  "Modules/LearningModule",
508  "lm_tree",
509  $a_rec["Child"],
510  $st_obj->getId()
511  );
512  $a_mapping->addMapping(
513  "Services/MetaData",
514  "md",
515  $a_rec["LmId"] . ":" . $a_rec["Child"] . ":st",
516  $this->current_obj->getId() . ":" . $st_obj->getId() . ":st"
517  );
518  break;
519 
520  case "pg":
521  $parent = (int) $a_mapping->getMapping("Modules/LearningModule", "lm_tree", $a_rec["Parent"]);
522  $pg_obj = new ilLMPageObject($this->current_obj);
523  $pg_obj->setType("pg");
524  $pg_obj->setLMId($this->current_obj->getId());
525  $pg_obj->setTitle($a_rec["Title"]);
526  $pg_obj->setShortTitle($a_rec["ShortTitle"]);
527  $pg_obj->setImportId($a_rec["ImportId"]);
528  $pg_obj->create(true, true);
529  ilLMObject::putInTree($pg_obj, $parent, IL_LAST_NODE);
530  $a_mapping->addMapping(
531  "Modules/LearningModule",
532  "lm_tree",
533  $a_rec["Child"],
534  $pg_obj->getId()
535  );
536  $a_mapping->addMapping("Modules/LearningModule", "pg", $a_rec["Child"], $pg_obj->getId());
537  $this->lm_log->debug("add pg map (1), old : " . $a_rec["Child"] . ", new: " . $pg_obj->getId());
538  $a_mapping->addMapping(
539  "Services/COPage",
540  "pg",
541  "lm:" . $a_rec["Child"],
542  "lm:" . $pg_obj->getId()
543  );
544  $a_mapping->addMapping(
545  "Services/MetaData",
546  "md",
547  $a_rec["LmId"] . ":" . $a_rec["Child"] . ":pg",
548  $this->current_obj->getId() . ":" . $pg_obj->getId() . ":pg"
549  );
550  break;
551 
552  // add free pages #18976
553  case "free_pg":
554  $pg_obj = new ilLMPageObject($this->current_obj);
555  $pg_obj->setType("pg");
556  $pg_obj->setLMId($this->current_obj->getId());
557  $pg_obj->setTitle($a_rec["Title"]);
558  $pg_obj->setShortTitle($a_rec["ShortTitle"]);
559  $pg_obj->setImportId($a_rec["ImportId"]);
560  $pg_obj->create(true, true);
561  $a_mapping->addMapping(
562  "Modules/LearningModule",
563  "lm_tree",
564  $a_rec["Child"],
565  $pg_obj->getId()
566  );
567  $a_mapping->addMapping("Modules/LearningModule", "pg", $a_rec["Child"], $pg_obj->getId());
568  $this->lm_log->debug("add pg map (2), old : " . $a_rec["Child"] . ", new: " . $pg_obj->getId());
569  $a_mapping->addMapping(
570  "Services/COPage",
571  "pg",
572  "lm:" . $a_rec["Child"],
573  "lm:" . $pg_obj->getId()
574  );
575  $a_mapping->addMapping(
576  "Services/MetaData",
577  "md",
578  $a_rec["LmId"] . ":" . $a_rec["Child"] . ":pg",
579  $this->current_obj->getId() . ":" . $pg_obj->getId() . ":pg"
580  );
581  break;
582  }
583  } else {
584  switch ($a_rec["Type"]) {
585  case "st":
586  //"il_inst_st_66"
587  $imp_id = explode("_", $a_rec["ImportId"]);
588  if ($imp_id[0] == "il" &&
589  (int) $imp_id[1] == (int) IL_INST_ID &&
590  $imp_id[2] == "st"
591  ) {
592  $st_id = $imp_id[3];
593  if (ilLMObject::_lookupContObjId($st_id) == $this->getTranslationLM()->getId()) {
594  $trans = new ilLMObjTranslation($st_id, $this->getTranslationLang());
595  $trans->setTitle($a_rec["Title"]);
596  $trans->save();
597  $a_mapping->addMapping(
598  "Modules/LearningModule",
599  "link",
600  "il_" . $this->getCurrentInstallationId() . "_" . $a_rec["Type"] . "_" . $a_rec["Child"],
601  $a_rec["ImportId"]
602  );
603  }
604  }
605  // no meta-data mapping, since we do not want to import metadata
606  break;
607 
608  case "pg":
609  //"il_inst_pg_66"
610  $imp_id = explode("_", $a_rec["ImportId"]);
611  if ($imp_id[0] == "il" &&
612  (int) $imp_id[1] == (int) IL_INST_ID &&
613  $imp_id[2] == "pg"
614  ) {
615  $pg_id = $imp_id[3];
616  if (ilLMObject::_lookupContObjId($pg_id) == $this->getTranslationLM()->getId()) {
617  $trans = new ilLMObjTranslation($pg_id, $this->getTranslationLang());
618  $trans->setTitle($a_rec["Title"]);
619  $trans->save();
620  $a_mapping->addMapping("Modules/LearningModule", "pg", $a_rec["Child"], $pg_id);
621  $this->lm_log->debug("add pg map (3), old : " . $a_rec["Child"] . ", new: " . $pg_id);
622  $a_mapping->addMapping(
623  "Modules/LearningModule",
624  "link",
625  "il_" . $this->getCurrentInstallationId() . "_" . $a_rec["Type"] . "_" . $a_rec["Child"],
626  $a_rec["ImportId"]
627  );
628  $a_mapping->addMapping(
629  "Services/COPage",
630  "pg",
631  "lm:" . $a_rec["Child"],
632  "lm:" . $pg_id
633  );
634  }
635  }
636  // no meta-data mapping, since we do not want to import metadata
637  break;
638  }
639  }
640  break;
641 
642  case "lm_data_transl":
643  if (!$this->getTranslationImportMode()) {
644  // save page/chapter title translation
645  $lm_obj_id = $a_mapping->getMapping("Modules/LearningModule", "lm_tree", $a_rec["Id"]);
646  if ($lm_obj_id > 0) {
647  $t = new ilLMObjTranslation($lm_obj_id, $a_rec["Lang"]);
648  $t->setTitle($a_rec["Title"]);
649  $t->setShortTitle($a_rec["ShortTitle"]);
650  $t->save();
651  }
652  }
653  break;
654 
655  case "lm_menu":
656  $lm_id = (int) $a_mapping->getMapping("Modules/LearningModule", "lm", $a_rec["LmId"]);
657  if ($lm_id > 0) {
658  $lm_menu_ed = new ilLMMenuEditor();
659  $lm_menu_ed->setObjId($lm_id);
660  $lm_menu_ed->setTitle($a_rec["Title"]);
661  $lm_menu_ed->setTarget($a_rec["Target"]);
662  $lm_menu_ed->setLinkType($a_rec["LinkType"]);
663  $lm_menu_ed->setLinkRefId($a_rec["LinkRefId"]);
664  $lm_menu_ed->setActive($a_rec["Active"]);
665  $lm_menu_ed->create();
666  }
667  break;
668 
669  }
670  }
671 }
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
Class ilObjLearningModule.
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_news_id=0)
Are comments activated for object?
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 ...
setTranslationImportMode($a_lm, $a_lang="")
Set translation import mode.
getTranslationLM()
Get translation lm (import.
convertToLeadingUpper($a_str)
Make xyz_abc a XyzAbc string.
getTypes($a_entity, $a_version)
Get field types for entity.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
Class ilLMPageObject.
static putInTree($a_obj, $a_parent_id="", $a_target_node_id="")
put this object into content object tree
setMasterLanguageOnly($a_val)
Set master language only (export)
class for editing lm menu
getCurrentInstallationId()
Get current installation id.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getSupportedVersions()
Get supported versions.
const IL_LAST_NODE
Definition: class.ilTree.php:4
getTranslationImportMode()
Get translation import mode.
Class ilStructreObject.
LearningModule Data set class.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
static activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate=true)
Activate notes feature.
__construct(Container $dic, ilPlugin $plugin)
global $ilDB
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
static getLogger($a_component_id)
Get component logger.
static yn2tf($a_yn)
convert "y"/"n" to true/false
A dataset contains in data in a common structure that can be shared and transformed for different pur...
Translation information on lm object.
getMasterLanguageOnly()
Get master language only (export)
getTranslationLang()
Get translation language (import.