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