ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
26
32 function setMasterLanguageOnly($a_val)
33 {
34 $this->master_lang_only = $a_val;
35 }
36
43 {
45 }
46
53 function setTranslationImportMode($a_lm, $a_lang = "")
54 {
55 if ($a_lm != null)
56 {
57 $this->transl_into = true;
58 $this->transl_into_lm = $a_lm;
59 $this->transl_lang = $a_lang;
60 }
61 else
62 {
63 $this->transl_into = false;
64 }
65 }
66
73 {
74 return $this->transl_into;
75 }
76
83 {
85 }
86
93 {
94 return $this->transl_lang;
95 }
96
103 public function getSupportedVersions()
104 {
105 return array("5.1.0");
106 }
107
114 function getXmlNamespace($a_entity, $a_schema_version)
115 {
116 return "http://www.ilias.de/xml/Modules/LearningModule/".$a_entity;
117 }
118
126 protected function getTypes($a_entity, $a_version)
127 {
128 if ($a_entity == "lm")
129 {
130 switch ($a_version)
131 {
132 case "5.1.0":
133 return array(
134 "Id" => "integer",
135 "Title" => "text",
136 "Description" => "text",
137 "DefaultLayout" => "text",
138 "PageHeader" => "text",
139 "TocActive" => "text",
140 "LMMenuActive" => "text",
141 "TOCMode" => "text",
142 "PrintViewActive" => "text",
143 "Numbering" => "text",
144 "HistUserComments" => "text",
145 "PublicAccessMode" => "text",
146 "PubNotes" => "text",
147 "HeaderPage" => "integer",
148 "FooterPage" => "integer",
149 "LayoutPerPage" => "integer",
150 "Rating" => "integer",
151 "HideHeadFootPrint" => "integer",
152 "DisableDefFeedback" => "integer",
153 "RatingPages" => "integer",
154 "ProgrIcons" => "integer",
155 "StoreTries" => "integer",
156 "RestrictForwNav" => "integer",
157 "Comments" => "integer",
158 "ForTranslation" => "integer",
159 "StyleId" => "integer"
160 );
161 }
162 }
163
164 if ($a_entity == "lm_tree")
165 {
166 switch ($a_version)
167 {
168 case "5.1.0":
169 return array(
170 "LmId" => "integer",
171 "Child" => "integer",
172 "Parent" => "integer",
173 "Depth" => "integer",
174 "Type" => "text",
175 "Title" => "text",
176 "PublicAccess" => "text",
177 "Active" => "text",
178 "Layout" => "text",
179 "ImportId" => "text"
180 );
181 }
182 }
183
184 if ($a_entity == "lm_menu")
185 {
186 switch ($a_version)
187 {
188 case "5.1.0":
189 return array(
190 "LmId" => "integer",
191 "LinkType" => "text",
192 "Title" => "text",
193 "Target" => "text",
194 "LinkRefId" => "text",
195 "Active" => "text"
196 );
197 }
198 }
199
200 if ($a_entity == "lm_data_transl")
201 {
202 switch ($a_version)
203 {
204 case "5.1.0":
205 return array(
206 "Id" => "integer",
207 "Lang" => "text",
208 "Title" => "text"
209 );
210 }
211 }
212
213 }
214
221 function readData($a_entity, $a_version, $a_ids, $a_field = "")
222 {
223 global $ilDB;
224
225 if (!is_array($a_ids))
226 {
227 $a_ids = array($a_ids);
228 }
229
230 if ($a_entity == "lm")
231 {
232 switch ($a_version)
233 {
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 {
246 // comments activated?
247 include_once("./Services/Notes/classes/class.ilNote.php");
248 $rec["comments"] = ilNote::commentsActivated($rec["id"], 0, "lm");
249
250 if ($this->getMasterLanguageOnly())
251 {
252 $rec["for_translation"] = 1;
253 }
254 $tmp = array();
255 foreach ($rec as $k => $v)
256 {
257 $tmp[$this->convertToLeadingUpper($k)]
258 = $v;
259 }
260 $rec = $tmp;
261
262 $this->data[] = $rec;
263 }
264 break;
265
266
267 break;
268 }
269 }
270
271 if ($a_entity == "lm_tree")
272 {
273 switch ($a_version)
274 {
275 case "5.1.0":
276 // the order by lft is very important, this ensures that parent nodes are written before
277 // their childs and that the import can add nodes simply with a "add at last child" target
278 $q = "SELECT lm_tree.lm_id, child, parent, depth, type, title, public_access, active, layout, import_id".
279 " FROM lm_tree JOIN lm_data ON (lm_tree.child = lm_data.obj_id)".
280 " WHERE ".$ilDB->in("lm_tree.lm_id", $a_ids, false, "integer").
281 " ORDER BY lft";
282
283 $set = $ilDB->query($q);
284 $this->data = array();
285 $obj_ids = array();
286 while ($rec = $ilDB->fetchAssoc($set))
287 {
288 $set2 = $ilDB->query("SELECT for_translation FROM content_object WHERE id = ".$ilDB->quote($rec["lm_id"], "integer"));
289 $rec2 = $ilDB->fetchAssoc($set2);
290 if (!$rec2["for_translation"])
291 {
292 $rec["import_id"] = "il_".IL_INST_ID."_".$rec["type"]."_".$rec["child"];
293 }
294 $tmp = array();
295 foreach ($rec as $k => $v)
296 {
297 $tmp[$this->convertToLeadingUpper($k)]
298 = $v;
299 }
300 $rec = $tmp;
301 $obj_ids[] = $rec["Child"];
302 $this->data[] = $rec;
303 }
304
305 // add free pages #18976
306 $set3 = $ilDB->query($q = "SELECT lm_id, type, title, public_access, active, layout, import_id, obj_id child FROM lm_data ".
307 "WHERE ".$ilDB->in("lm_id", $a_ids, false, "integer").
308 " AND ".$ilDB->in("obj_id", $obj_ids, true, "integer").
309 " AND type = ".$ilDB->quote("pg", "text"));
310 while ($rec3 = $ilDB->fetchAssoc($set3))
311 {
312 $set2 = $ilDB->query("SELECT for_translation FROM content_object WHERE id = ".$ilDB->quote($rec3["lm_id"], "integer"));
313 $rec2 = $ilDB->fetchAssoc($set2);
314 if (!$rec2["for_translation"])
315 {
316 $rec3["import_id"] = "il_".IL_INST_ID."_pg_".$rec3["child"];
317 }
318 $rec3["type"] = "free_pg";
319 $rec3["depth"] = 0;
320 $rec3["parent"] = 0;
321 $tmp = array();
322 foreach ($rec3 as $k => $v)
323 {
324 $tmp[$this->convertToLeadingUpper($k)]
325 = $v;
326 }
327 $this->data[] = $tmp;
328 }
329 break;
330 }
331 }
332
333 if ($a_entity == "lm_menu")
334 {
335 switch ($a_version)
336 {
337 case "5.1.0":
338 $this->getDirectDataFromQuery("SELECT lm_id, link_type, title, target, link_ref_id, active".
339 " FROM lm_menu ".
340 " WHERE ".$ilDB->in("lm_id", $a_ids, false, "integer"));
341 break;
342 }
343 }
344
345 if ($a_entity == "lm_data_transl")
346 {
347 switch ($a_version)
348 {
349 case "5.1.0":
350 $this->getDirectDataFromQuery("SELECT id, lang, title".
351 " FROM lm_data_transl ".
352 " WHERE ".$ilDB->in("id", $a_ids, false, "integer"));
353 break;
354 }
355 }
356
357
358 }
359
363 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
364 {
365 switch ($a_entity)
366 {
367 case "lm":
368 return array (
369 "lm_tree" => array("ids" => $a_rec["Id"]),
370 "lm_menu" => array("ids" => $a_rec["Id"])
371 );
372
373 case "lm_tree":
374 if ($this->getMasterLanguageOnly())
375 {
376 return false;
377 }
378 else
379 {
380 return array (
381 "lm_data_transl" => array("ids" => $a_rec["Child"])
382 );
383 }
384 }
385
386 return false;
387 }
388
389
396 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
397 {
398//var_dump($a_rec);
399
400 switch ($a_entity)
401 {
402 case "lm":
403
404 if ($this->getTranslationImportMode())
405 {
406 return;
407 }
408
409 include_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
410 if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
411 {
412 $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
413 }
414 else
415 {
416 $newObj = new ilObjLearningModule();
417 $newObj->setType("lm");
418 $newObj->create(true);
419 $newObj->createLMTree();
420 }
421
422 $newObj->setTitle($a_rec["Title"]);
423 $newObj->setDescription($a_rec["Description"]);
424 $newObj->setLayout($a_rec["DefaultLayout"]);
425 $newObj->setPageHeader($a_rec["PageHeader"]);
426 $newObj->setActiveTOC(ilUtil::yn2tf($a_rec["TocActive"]));
427 $newObj->setActiveLMMenu(ilUtil::yn2tf($a_rec["LmMenuActive"]));
428 $newObj->setTOCMode($a_rec["TOCMode"]);
429 $newObj->setActivePrintView(ilUtil::yn2tf($a_rec["PrintViewActive"]));
430 $newObj->setActiveNumbering(ilUtil::yn2tf($a_rec["Numbering"]));
431 $newObj->setHistoryUserComments(ilUtil::yn2tf($a_rec["HistUserComments"]));
432 $newObj->setPublicAccessMode($a_rec["PublicAccessMode"]);
433 $newObj->setPublicNotes(ilUtil::yn2tf($a_rec["PubNotes"]));
434 // Header Page/ Footer Page ???
435 $newObj->setLayoutPerPage($a_rec["LayoutPerPage"]);
436 $newObj->setRating($a_rec["Rating"]);
437 $newObj->setHideHeaderFooterPrint($a_rec["HideHeadFootPrint"]);
438 $newObj->setDisableDefaultFeedback($a_rec["DisableDefFeedback"]);
439 $newObj->setRatingPages($a_rec["RatingPages"]);
440 $newObj->setForTranslation($a_rec["ForTranslation"]);
441 $newObj->setProgressIcons($a_rec["ProgrIcons"]);
442 $newObj->setStoreTries($a_rec["StoreTries"]);
443 $newObj->setRestrictForwardNavigation($a_rec["RestrictForwNav"]);
444 if ($a_rec["HeaderPage"] > 0)
445 {
446 $a_mapping->addMapping("Modules/LearningModule", "lm_header_page", $a_rec["HeaderPage"], "-");
447 }
448 if ($a_rec["FooterPage"] > 0)
449 {
450 $a_mapping->addMapping("Modules/LearningModule", "lm_footer_page", $a_rec["FooterPage"], "-");
451 }
452
453 $newObj->update(true);
454 $this->current_obj = $newObj;
455
456 // activated comments
457 include_once("./Services/Notes/classes/class.ilNote.php");
458 ilNote::activateComments($newObj->getId(), 0, "lm", (int) $a_rec["Comments"]);
459
460 $a_mapping->addMapping("Modules/LearningModule", "lm", $a_rec["Id"], $newObj->getId());
461 $a_mapping->addMapping("Modules/LearningModule", "lm_style", $newObj->getId(), $a_rec["StyleId"]);
462 $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
463 $a_mapping->addMapping("Services/MetaData", "md",
464 $a_rec["Id"].":0:lm", $newObj->getId().":0:lm");
465 break;
466
467 case "lm_tree":
468 if (!$this->getTranslationImportMode())
469 {
470 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
471 include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
472 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
473 switch ($a_rec["Type"])
474 {
475 case "st":
476 $parent = (int) $a_mapping->getMapping("Modules/LearningModule", "lm_tree", $a_rec["Parent"]);
477 $st_obj = new ilStructureObject($this->current_obj);
478 $st_obj->setType("st");
479 $st_obj->setLMId($this->current_obj->getId());
480 $st_obj->setTitle($a_rec["Title"]);
481 $st_obj->setImportId($a_rec["ImportId"]);
482 $st_obj->create(true);
483 ilLMObject::putInTree($st_obj, $parent, IL_LAST_NODE);
484 $a_mapping->addMapping("Modules/LearningModule", "lm_tree", $a_rec["Child"],
485 $st_obj->getId());
486 $a_mapping->addMapping("Services/MetaData", "md",
487 $a_rec["LmId"].":".$a_rec["Child"].":st", $this->current_obj->getId().":".$st_obj->getId().":st");
488 break;
489
490 case "pg":
491 $parent = (int) $a_mapping->getMapping("Modules/LearningModule", "lm_tree", $a_rec["Parent"]);
492 $pg_obj = new ilLMPageObject($this->current_obj);
493 $pg_obj->setType("pg");
494 $pg_obj->setLMId($this->current_obj->getId());
495 $pg_obj->setTitle($a_rec["Title"]);
496 $pg_obj->setImportId($a_rec["ImportId"]);
497 $pg_obj->create(true, true);
498 ilLMObject::putInTree($pg_obj, $parent, IL_LAST_NODE);
499 $a_mapping->addMapping("Modules/LearningModule", "lm_tree", $a_rec["Child"],
500 $pg_obj->getId());
501 $a_mapping->addMapping("Modules/LearningModule", "pg", $a_rec["Child"], $pg_obj->getId());
502 $a_mapping->addMapping("Services/COPage", "pg", "lm:".$a_rec["Child"],
503 "lm:".$pg_obj->getId());
504 $a_mapping->addMapping("Services/MetaData", "md",
505 $a_rec["LmId"].":".$a_rec["Child"].":pg", $this->current_obj->getId().":".$pg_obj->getId().":pg");
506 break;
507
508 // add free pages #18976
509 case "free_pg":
510 $pg_obj = new ilLMPageObject($this->current_obj);
511 $pg_obj->setType("pg");
512 $pg_obj->setLMId($this->current_obj->getId());
513 $pg_obj->setTitle($a_rec["Title"]);
514 $pg_obj->setImportId($a_rec["ImportId"]);
515 $pg_obj->create(true, true);
516 $a_mapping->addMapping("Modules/LearningModule", "lm_tree", $a_rec["Child"],
517 $pg_obj->getId());
518 $a_mapping->addMapping("Modules/LearningModule", "pg", $a_rec["Child"], $pg_obj->getId());
519 $a_mapping->addMapping("Services/COPage", "pg", "lm:".$a_rec["Child"],
520 "lm:".$pg_obj->getId());
521 $a_mapping->addMapping("Services/MetaData", "md",
522 $a_rec["LmId"].":".$a_rec["Child"].":pg", $this->current_obj->getId().":".$pg_obj->getId().":pg");
523 break;
524 }
525 }
526 else
527 {
528 include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
529 switch ($a_rec["Type"])
530 {
531 case "st":
532 //"il_inst_st_66"
533 $imp_id = explode("_", $a_rec["ImportId"]);
534 if ($imp_id[0] == "il" &&
535 (int) $imp_id[1] == (int) IL_INST_ID &&
536 $imp_id[2] == "st"
537 )
538 {
539 $st_id = $imp_id[3];
540 if (ilLMObject::_lookupContObjId($st_id) == $this->getTranslationLM()->getId())
541 {
542 $trans = new ilLMObjTranslation($st_id, $this->getTranslationLang());
543 $trans->setTitle($a_rec["Title"]);
544 $trans->save();
545 $a_mapping->addMapping("Modules/LearningModule", "link",
546 "il_".$this->getCurrentInstallationId()."_".$a_rec["Type"]."_".$a_rec["Child"], $a_rec["ImportId"]);
547 }
548 }
549 // no meta-data mapping, since we do not want to import metadata
550 break;
551
552 case "pg":
553 //"il_inst_pg_66"
554 $imp_id = explode("_", $a_rec["ImportId"]);
555 if ($imp_id[0] == "il" &&
556 (int) $imp_id[1] == (int) IL_INST_ID &&
557 $imp_id[2] == "pg"
558 )
559 {
560 $pg_id = $imp_id[3];
561 if (ilLMObject::_lookupContObjId($pg_id) == $this->getTranslationLM()->getId())
562 {
563 $trans = new ilLMObjTranslation($pg_id, $this->getTranslationLang());
564 $trans->setTitle($a_rec["Title"]);
565 $trans->save();
566 $a_mapping->addMapping("Modules/LearningModule", "pg", $a_rec["Child"], $pg_id);
567 $a_mapping->addMapping("Modules/LearningModule", "link",
568 "il_".$this->getCurrentInstallationId()."_".$a_rec["Type"]."_".$a_rec["Child"], $a_rec["ImportId"]);
569 $a_mapping->addMapping("Services/COPage", "pg", "lm:".$a_rec["Child"],
570 "lm:".$pg_id);
571 }
572 }
573 // no meta-data mapping, since we do not want to import metadata
574 break;
575 }
576 }
577 break;
578
579 case "lm_data_transl":
580 include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
581 if (!$this->getTranslationImportMode())
582 {
583 // save page/chapter title translation
584 $lm_obj_id = $a_mapping->getMapping("Modules/LearningModule", "lm_tree", $a_rec["Id"]);
585 if ($lm_obj_id > 0)
586 {
587 $t = new ilLMObjTranslation($lm_obj_id, $a_rec["Lang"]);
588 $t->setTitle($a_rec["Title"]);
589 $t->save();
590 }
591 }
592 break;
593 }
594 }
595}
596?>
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)
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 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.
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