ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLearningModuleDataSet.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 {
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  {
36  parent::__construct();
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");
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  }
171 
172  if ($a_entity == "lm_tree") {
173  switch ($a_version) {
174  case "5.1.0":
175  return array(
176  "LmId" => "integer",
177  "Child" => "integer",
178  "Parent" => "integer",
179  "Depth" => "integer",
180  "Type" => "text",
181  "Title" => "text",
182  "ShortTitle" => "text",
183  "PublicAccess" => "text",
184  "Active" => "text",
185  "Layout" => "text",
186  "ImportId" => "text"
187  );
188  }
189  }
190 
191  if ($a_entity == "lm_menu") {
192  switch ($a_version) {
193  case "5.1.0":
194  return array(
195  "LmId" => "integer",
196  "LinkType" => "text",
197  "Title" => "text",
198  "Target" => "text",
199  "LinkRefId" => "text",
200  "Active" => "text"
201  );
202  }
203  }
204 
205  if ($a_entity == "lm_data_transl") {
206  switch ($a_version) {
207  case "5.1.0":
208  return array(
209  "Id" => "integer",
210  "Lang" => "text",
211  "Title" => "text",
212  "ShortTitle" => "text"
213  );
214  }
215  }
216  }
217 
224  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
225  {
226  $ilDB = $this->db;
227 
228  if (!is_array($a_ids)) {
229  $a_ids = array($a_ids);
230  }
231 
232  if ($a_entity == "lm") {
233  switch ($a_version) {
234  case "5.1.0":
235  $q = "SELECT id, title, description," .
236  " default_layout, page_header, toc_active, lm_menu_active, toc_mode, print_view_active, numbering," .
237  " hist_user_comments, public_access_mode, header_page, footer_page, layout_per_page, rating, " .
238  " hide_head_foot_print, disable_def_feedback, rating_pages, store_tries, restrict_forw_nav, progr_icons, stylesheet style_id" .
239  " FROM content_object JOIN object_data ON (content_object.id = object_data.obj_id)" .
240  " WHERE " . $ilDB->in("id", $a_ids, false, "integer");
241 
242  $set = $ilDB->query($q);
243  $this->data = array();
244  while ($rec = $ilDB->fetchAssoc($set)) {
245  // comments activated?
246  include_once("./Services/Notes/classes/class.ilNote.php");
247  $rec["comments"] = ilNote::commentsActivated($rec["id"], 0, "lm");
248 
249  if ($this->getMasterLanguageOnly()) {
250  $rec["for_translation"] = 1;
251  }
252  $tmp = array();
253  foreach ($rec as $k => $v) {
254  $tmp[$this->convertToLeadingUpper($k)]
255  = $v;
256  }
257  $rec = $tmp;
258 
259  $this->data[] = $rec;
260  }
261  break;
262 
263 
264  break;
265  }
266  }
267 
268  if ($a_entity == "lm_tree") {
269  switch ($a_version) {
270  case "5.1.0":
271  // the order by lft is very important, this ensures that parent nodes are written before
272  // their childs and that the import can add nodes simply with a "add at last child" target
273  $q = "SELECT lm_tree.lm_id, child, parent, depth, type, title, short_title, public_access, active, layout, import_id" .
274  " FROM lm_tree JOIN lm_data ON (lm_tree.child = lm_data.obj_id)" .
275  " WHERE " . $ilDB->in("lm_tree.lm_id", $a_ids, false, "integer") .
276  " ORDER BY lft";
277 
278  $set = $ilDB->query($q);
279  $this->data = array();
280  $obj_ids = array();
281  while ($rec = $ilDB->fetchAssoc($set)) {
282  $set2 = $ilDB->query("SELECT for_translation FROM content_object WHERE id = " . $ilDB->quote($rec["lm_id"], "integer"));
283  $rec2 = $ilDB->fetchAssoc($set2);
284  if (!$rec2["for_translation"]) {
285  $rec["import_id"] = "il_" . IL_INST_ID . "_" . $rec["type"] . "_" . $rec["child"];
286  }
287  $tmp = array();
288  foreach ($rec as $k => $v) {
289  $tmp[$this->convertToLeadingUpper($k)]
290  = $v;
291  }
292  $rec = $tmp;
293  $obj_ids[] = $rec["Child"];
294  $this->data[] = $rec;
295  }
296 
297  // add free pages #18976
298  $set3 = $ilDB->query($q = "SELECT lm_id, type, title, short_title, public_access, active, layout, import_id, obj_id child FROM lm_data " .
299  "WHERE " . $ilDB->in("lm_id", $a_ids, false, "integer") .
300  " AND " . $ilDB->in("obj_id", $obj_ids, true, "integer") .
301  " AND type = " . $ilDB->quote("pg", "text"));
302  while ($rec3 = $ilDB->fetchAssoc($set3)) {
303  $set2 = $ilDB->query("SELECT for_translation FROM content_object WHERE id = " . $ilDB->quote($rec3["lm_id"], "integer"));
304  $rec2 = $ilDB->fetchAssoc($set2);
305  if (!$rec2["for_translation"]) {
306  $rec3["import_id"] = "il_" . IL_INST_ID . "_pg_" . $rec3["child"];
307  }
308  $rec3["type"] = "free_pg";
309  $rec3["depth"] = 0;
310  $rec3["parent"] = 0;
311  $tmp = array();
312  foreach ($rec3 as $k => $v) {
313  $tmp[$this->convertToLeadingUpper($k)]
314  = $v;
315  }
316  $this->data[] = $tmp;
317  }
318  break;
319  }
320  }
321 
322  if ($a_entity == "lm_menu") {
323  switch ($a_version) {
324  case "5.1.0":
325  $this->getDirectDataFromQuery("SELECT lm_id, link_type, title, target, link_ref_id, active" .
326  " FROM lm_menu " .
327  " WHERE " . $ilDB->in("lm_id", $a_ids, false, "integer"));
328  break;
329  }
330  }
331 
332  if ($a_entity == "lm_data_transl") {
333  switch ($a_version) {
334  case "5.1.0":
335  $this->getDirectDataFromQuery("SELECT id, lang, title, short_title" .
336  " FROM lm_data_transl " .
337  " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
338  break;
339  }
340  }
341  }
342 
346  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
347  {
348  switch ($a_entity) {
349  case "lm":
350  return array(
351  "lm_tree" => array("ids" => $a_rec["Id"]),
352  "lm_menu" => array("ids" => $a_rec["Id"])
353  );
354 
355  case "lm_tree":
356  if ($this->getMasterLanguageOnly()) {
357  return false;
358  } else {
359  return array(
360  "lm_data_transl" => array("ids" => $a_rec["Child"])
361  );
362  }
363  }
364 
365  return false;
366  }
367 
368 
375  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
376  {
377  //var_dump($a_rec);
378 
379  switch ($a_entity) {
380  case "lm":
381 
382  if ($this->getTranslationImportMode()) {
383  return;
384  }
385 
386  include_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
387  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
388  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
389  } else {
390  $newObj = new ilObjLearningModule();
391  $newObj->setType("lm");
392  $newObj->create(true);
393  $newObj->createLMTree();
394  }
395 
396  $newObj->setTitle($a_rec["Title"]);
397  $newObj->setDescription($a_rec["Description"]);
398  $newObj->setLayout($a_rec["DefaultLayout"]);
399  $newObj->setPageHeader($a_rec["PageHeader"]);
400  $newObj->setActiveTOC(ilUtil::yn2tf($a_rec["TocActive"]));
401  $newObj->setActiveLMMenu(ilUtil::yn2tf($a_rec["LmMenuActive"]));
402  $newObj->setTOCMode($a_rec["TocMode"]);
403  $newObj->setActivePrintView(ilUtil::yn2tf($a_rec["PrintViewActive"]));
404  $newObj->setActiveNumbering(ilUtil::yn2tf($a_rec["Numbering"]));
405  $newObj->setHistoryUserComments(ilUtil::yn2tf($a_rec["HistUserComments"]));
406  $newObj->setPublicAccessMode($a_rec["PublicAccessMode"]);
407  $newObj->setPublicNotes(ilUtil::yn2tf($a_rec["PubNotes"]));
408  // Header Page/ Footer Page ???
409  $newObj->setLayoutPerPage($a_rec["LayoutPerPage"]);
410  $newObj->setRating($a_rec["Rating"]);
411  $newObj->setHideHeaderFooterPrint($a_rec["HideHeadFootPrint"]);
412  $newObj->setDisableDefaultFeedback($a_rec["DisableDefFeedback"]);
413  $newObj->setRatingPages($a_rec["RatingPages"]);
414  $newObj->setForTranslation($a_rec["ForTranslation"]);
415  $newObj->setProgressIcons($a_rec["ProgrIcons"]);
416  $newObj->setStoreTries($a_rec["StoreTries"]);
417  $newObj->setRestrictForwardNavigation($a_rec["RestrictForwNav"]);
418  if ($a_rec["HeaderPage"] > 0) {
419  $a_mapping->addMapping("Modules/LearningModule", "lm_header_page", $a_rec["HeaderPage"], "-");
420  }
421  if ($a_rec["FooterPage"] > 0) {
422  $a_mapping->addMapping("Modules/LearningModule", "lm_footer_page", $a_rec["FooterPage"], "-");
423  }
424 
425  $newObj->update(true);
426  $this->current_obj = $newObj;
427 
428  // activated comments
429  include_once("./Services/Notes/classes/class.ilNote.php");
430  ilNote::activateComments($newObj->getId(), 0, "lm", (int) $a_rec["Comments"]);
431 
432  $a_mapping->addMapping("Modules/LearningModule", "lm", $a_rec["Id"], $newObj->getId());
433  $a_mapping->addMapping("Modules/LearningModule", "lm_style", $newObj->getId(), $a_rec["StyleId"]);
434  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
435  $a_mapping->addMapping(
436  "Services/MetaData",
437  "md",
438  $a_rec["Id"] . ":0:lm",
439  $newObj->getId() . ":0:lm"
440  );
441  break;
442 
443  case "lm_tree":
444  if (!$this->getTranslationImportMode()) {
445  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
446  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
447  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
448  switch ($a_rec["Type"]) {
449  case "st":
450  $parent = (int) $a_mapping->getMapping("Modules/LearningModule", "lm_tree", $a_rec["Parent"]);
451  $st_obj = new ilStructureObject($this->current_obj);
452  $st_obj->setType("st");
453  $st_obj->setLMId($this->current_obj->getId());
454  $st_obj->setTitle($a_rec["Title"]);
455  $st_obj->setShortTitle($a_rec["ShortTitle"]);
456  $st_obj->setImportId($a_rec["ImportId"]);
457  $st_obj->create(true);
458  ilLMObject::putInTree($st_obj, $parent, IL_LAST_NODE);
459  $a_mapping->addMapping(
460  "Modules/LearningModule",
461  "lm_tree",
462  $a_rec["Child"],
463  $st_obj->getId()
464  );
465  $a_mapping->addMapping(
466  "Services/MetaData",
467  "md",
468  $a_rec["LmId"] . ":" . $a_rec["Child"] . ":st",
469  $this->current_obj->getId() . ":" . $st_obj->getId() . ":st"
470  );
471  break;
472 
473  case "pg":
474  $parent = (int) $a_mapping->getMapping("Modules/LearningModule", "lm_tree", $a_rec["Parent"]);
475  $pg_obj = new ilLMPageObject($this->current_obj);
476  $pg_obj->setType("pg");
477  $pg_obj->setLMId($this->current_obj->getId());
478  $pg_obj->setTitle($a_rec["Title"]);
479  $pg_obj->setShortTitle($a_rec["ShortTitle"]);
480  $pg_obj->setImportId($a_rec["ImportId"]);
481  $pg_obj->create(true, true);
482  ilLMObject::putInTree($pg_obj, $parent, IL_LAST_NODE);
483  $a_mapping->addMapping(
484  "Modules/LearningModule",
485  "lm_tree",
486  $a_rec["Child"],
487  $pg_obj->getId()
488  );
489  $a_mapping->addMapping("Modules/LearningModule", "pg", $a_rec["Child"], $pg_obj->getId());
490  $this->lm_log->debug("add pg map (1), old : " . $a_rec["Child"] . ", new: " . $pg_obj->getId());
491  $a_mapping->addMapping(
492  "Services/COPage",
493  "pg",
494  "lm:" . $a_rec["Child"],
495  "lm:" . $pg_obj->getId()
496  );
497  $a_mapping->addMapping(
498  "Services/MetaData",
499  "md",
500  $a_rec["LmId"] . ":" . $a_rec["Child"] . ":pg",
501  $this->current_obj->getId() . ":" . $pg_obj->getId() . ":pg"
502  );
503  break;
504 
505  // add free pages #18976
506  case "free_pg":
507  $pg_obj = new ilLMPageObject($this->current_obj);
508  $pg_obj->setType("pg");
509  $pg_obj->setLMId($this->current_obj->getId());
510  $pg_obj->setTitle($a_rec["Title"]);
511  $pg_obj->setShortTitle($a_rec["ShortTitle"]);
512  $pg_obj->setImportId($a_rec["ImportId"]);
513  $pg_obj->create(true, true);
514  $a_mapping->addMapping(
515  "Modules/LearningModule",
516  "lm_tree",
517  $a_rec["Child"],
518  $pg_obj->getId()
519  );
520  $a_mapping->addMapping("Modules/LearningModule", "pg", $a_rec["Child"], $pg_obj->getId());
521  $this->lm_log->debug("add pg map (2), old : " . $a_rec["Child"] . ", new: " . $pg_obj->getId());
522  $a_mapping->addMapping(
523  "Services/COPage",
524  "pg",
525  "lm:" . $a_rec["Child"],
526  "lm:" . $pg_obj->getId()
527  );
528  $a_mapping->addMapping(
529  "Services/MetaData",
530  "md",
531  $a_rec["LmId"] . ":" . $a_rec["Child"] . ":pg",
532  $this->current_obj->getId() . ":" . $pg_obj->getId() . ":pg"
533  );
534  break;
535  }
536  } else {
537  include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
538  switch ($a_rec["Type"]) {
539  case "st":
540  //"il_inst_st_66"
541  $imp_id = explode("_", $a_rec["ImportId"]);
542  if ($imp_id[0] == "il" &&
543  (int) $imp_id[1] == (int) IL_INST_ID &&
544  $imp_id[2] == "st"
545  ) {
546  $st_id = $imp_id[3];
547  if (ilLMObject::_lookupContObjId($st_id) == $this->getTranslationLM()->getId()) {
548  $trans = new ilLMObjTranslation($st_id, $this->getTranslationLang());
549  $trans->setTitle($a_rec["Title"]);
550  $trans->save();
551  $a_mapping->addMapping(
552  "Modules/LearningModule",
553  "link",
554  "il_" . $this->getCurrentInstallationId() . "_" . $a_rec["Type"] . "_" . $a_rec["Child"],
555  $a_rec["ImportId"]
556  );
557  }
558  }
559  // no meta-data mapping, since we do not want to import metadata
560  break;
561 
562  case "pg":
563  //"il_inst_pg_66"
564  $imp_id = explode("_", $a_rec["ImportId"]);
565  if ($imp_id[0] == "il" &&
566  (int) $imp_id[1] == (int) IL_INST_ID &&
567  $imp_id[2] == "pg"
568  ) {
569  $pg_id = $imp_id[3];
570  if (ilLMObject::_lookupContObjId($pg_id) == $this->getTranslationLM()->getId()) {
571  $trans = new ilLMObjTranslation($pg_id, $this->getTranslationLang());
572  $trans->setTitle($a_rec["Title"]);
573  $trans->save();
574  $a_mapping->addMapping("Modules/LearningModule", "pg", $a_rec["Child"], $pg_id);
575  $this->lm_log->debug("add pg map (3), old : " . $a_rec["Child"] . ", new: " . $pg_id);
576  $a_mapping->addMapping(
577  "Modules/LearningModule",
578  "link",
579  "il_" . $this->getCurrentInstallationId() . "_" . $a_rec["Type"] . "_" . $a_rec["Child"],
580  $a_rec["ImportId"]
581  );
582  $a_mapping->addMapping(
583  "Services/COPage",
584  "pg",
585  "lm:" . $a_rec["Child"],
586  "lm:" . $pg_id
587  );
588  }
589  }
590  // no meta-data mapping, since we do not want to import metadata
591  break;
592  }
593  }
594  break;
595 
596  case "lm_data_transl":
597  include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
598  if (!$this->getTranslationImportMode()) {
599  // save page/chapter title translation
600  $lm_obj_id = $a_mapping->getMapping("Modules/LearningModule", "lm_tree", $a_rec["Id"]);
601  if ($lm_obj_id > 0) {
602  $t = new ilLMObjTranslation($lm_obj_id, $a_rec["Lang"]);
603  $t->setTitle($a_rec["Title"]);
604  $t->setShortTitle($a_rec["ShortTitle"]);
605  $t->save();
606  }
607  }
608  break;
609 
610  case "lm_menu":
611  $lm_id = (int) $a_mapping->getMapping("Modules/LearningModule", "lm", $a_rec["LmId"]);
612  if ($lm_id > 0) {
613  $lm_menu_ed = new ilLMMenuEditor();
614  $lm_menu_ed->setObjId($lm_id);
615  $lm_menu_ed->setTitle($a_rec["Title"]);
616  $lm_menu_ed->setTarget($a_rec["Target"]);
617  $lm_menu_ed->setLinkType($a_rec["LinkType"]);
618  $lm_menu_ed->setLinkRefId($a_rec["LinkRefId"]);
619  $lm_menu_ed->setActive($a_rec["Active"]);
620  $lm_menu_ed->create();
621  }
622  break;
623 
624  }
625  }
626 }
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
Add some data
Class ilObjLearningModule.
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
Create styles array
The data for the language used.
getSupportedVersions()
Get supported versions.
const IL_LAST_NODE
Definition: class.ilTree.php:4
getTranslationImportMode()
Get translation import mode.
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type)
Are comments activated for object?
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.
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.