ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLearningModuleImporter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Export/classes/class.ilXmlImporter.php");
5 
14 {
15  protected $config;
16 
20  protected $log;
21 
25  function init()
26  {
27  include_once("./Modules/LearningModule/classes/class.ilLearningModuleDataSet.php");
28  $this->ds = new ilLearningModuleDataSet();
29  $this->ds->setDSPrefix("ds");
30 
31  $this->log = ilLoggerFactory::getLogger('lm');
32 
33  $this->config = $this->getImport()->getConfig("Modules/LearningModule");
34  if ($this->config->getTranslationImportMode())
35  {
36  $this->ds->setTranslationImportMode(
37  $this->config->getTranslationLM(),
38  $this->config->getTranslationLang());
39  $cop_config = $this->getImport()->getConfig("Services/COPage");
40  $cop_config->setUpdateIfExists(true);
41  $cop_config->setForceLanguage($this->config->getTranslationLang());
42  $cop_config->setReuseOriginallyExportedMedia(true);
43  $cop_config->setSkipInternalLinkResolve(true);
44 
45  $mob_config = $this->getImport()->getConfig("Services/MediaObjects");
46  $mob_config->setUsePreviousImportIds(true);
47  }
48  }
49 
50 
57  function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
58  {
59  include_once './Modules/File/classes/class.ilObjFile.php';
60 
61  $this->log->debug("import XML Representation");
62 
63  // case i container
64  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
65  {
66  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
67  $newObj->createLMTree();
68  $this->log->debug("got mapping, new id is: ".$new_id);
69  }
70 
71  // in the new version (5.1) we are also here, but the following file should not exist
72  // if being exported with 5.1 or higher
73  $xml_file = $this->getImportDirectory().'/'.basename($this->getImportDirectory()).'.xml';
74 
75  // old school import
76  // currently this means we got a container and mapping, too, since
77  // for single lms the processing in ilObjContentObjectGUI->importFileObject is used
78  // (this should be streamlined, see glossary)
79  if (file_exists($xml_file))
80  {
81  $newObj->setImportDirectory(dirname(rtrim($this->getImportDirectory(), '/')));
82  $mess = $newObj->importFromDirectory($this->getImportDirectory(), true, $a_mapping);
83  $this->log->debug("imported from directory ($mess)");
84  $a_mapping->addMapping("Modules/LearningModule", "lm", $a_id, $newObj->getId());
85  $a_mapping->addMapping("Services/Object", "obj", $a_id, $newObj->getId());
86  }
87  else // new import version (does mapping, too)
88  {
89  $this->log->debug("create ilDataSetIportParser instance");
90  include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
91  $parser = new ilDataSetImportParser($a_entity, $this->getSchemaVersion(),
92  $a_xml, $this->ds, $a_mapping);
93  }
94 
95  // import qti stuff
96  $this->log->debug("import qti data");
97  $qti_file = $this->getImportDirectory().'/qti.xml';
98  $this->qtis = array();
99  if (is_file($qti_file))
100  {
101  include_once "./Services/QTI/classes/class.ilQTIParser.php";
102  include_once("./Modules/Test/classes/class.ilObjTest.php");
103  $qtiParser = new ilQTIParser ($qti_file,
104  IL_MO_VERIFY_QTI, 0, "");
105  $result = $qtiParser->startParsing ();
106  $founditems = & $qtiParser->getFoundItems ();
107  $testObj = new ilObjTest(0, true);
108  if (count($founditems) > 0)
109  {
110  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, 0, "");
111  $qtiParser->setTestObject($testObj);
112  $result = $qtiParser->startParsing();
113  $this->qtis = array_merge($this->qtis, $qtiParser->getImportMapping());
114  }
115  }
116  }
117 
123  function finalProcessing($a_mapping)
124  {
125  $pg_map = $a_mapping->getMappingsOfEntity("Modules/LearningModule", "pg");
126 
127  include_once("./Modules/LearningModule/classes/class.ilLMPage.php");
128  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
129  $this->log->debug("pg map entries: ".count($pg_map));
130  foreach ($pg_map as $pg_id)
131  {
132  $lm_id = ilLMPageObject::_lookupContObjID($pg_id);
133  ilLMPage::_writeParentId("lm", $pg_id, $lm_id);
134  $this->log->debug("write parent id, pg id: ".$pg_id.", lm id: ".$lm_id);
135  }
136 
137  // header footer page
138  foreach ($a_mapping->getMappingsOfEntity("Modules/LearningModule", "lm_header_page") as $old_id => $dummy)
139  {
140  $new_page_id = (int) $a_mapping->getMapping("Modules/LearningModule", "pg", $old_id);
141  if ($new_page_id > 0)
142  {
143  $lm_id = ilLMPageObject::_lookupContObjID($new_page_id);
144  ilObjLearningModule::writeHeaderPage($lm_id, $new_page_id);
145  }
146  }
147  foreach ($a_mapping->getMappingsOfEntity("Modules/LearningModule", "lm_footer_page") as $old_id => $dummy)
148  {
149  $new_page_id = (int) $a_mapping->getMapping("Modules/LearningModule", "pg", $old_id);
150  if ($new_page_id > 0)
151  {
152  $lm_id = ilLMPageObject::_lookupContObjID($new_page_id);
153  ilObjLearningModule::writeFooterPage($lm_id, $new_page_id);
154  }
155  }
156 
157 
158  $link_map = $a_mapping->getMappingsOfEntity("Modules/LearningModule", "link");
159  $pages = $a_mapping->getMappingsOfEntity("Services/COPage", "pgl");
160  foreach ($pages as $p)
161  {
162  $id = explode(":", $p);
163  if (count($id) == 3)
164  {
165  include_once("./Services/COPage/classes/class.ilPageObject.php");
166  if (ilPageObject::_exists($id[0], $id[1], $id[2], true))
167  {
168  include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
169  $new_page = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $id[2]);
170  $new_page->buildDom();
171 
172  // fix question references
173  $updated = $new_page->resolveQuestionReferences($this->qtis);
174 
175  // in translation mode use link mapping to fix internal links
176  //$a_mapping->addMapping("Modules/LearningModule", "link",
177  if ($this->config->getTranslationImportMode())
178  {
179  $il = $new_page->resolveIntLinks($link_map);
180  if ($il)
181  {
182  $updated = true;
183  }
184  }
185 
186  if ($updated)
187  {
188  $new_page->update(false, true);
189  }
190  }
191  }
192  }
193 
194  // assign style
195  $alls_map = $a_mapping->getMappingsOfEntity("Modules/LearningModule", "lm_style");
196  foreach ($alls_map as $new_lm_id => $old_style_id)
197  {
198  $new_style_id = (int) $a_mapping->getMapping("Services/Style", "sty", $old_style_id);
199  if ($new_lm_id > 0 && $new_style_id > 0)
200  {
201  include_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
202  $lm = new ilObjLearningModule($new_lm_id, false);
203  $lm->writeStyleSheetId($new_style_id);
204  }
205  }
206  }
207 }
208 
209 ?>
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
getSchemaVersion()
Get schema version.
Class ilObjLearningModule.
$result
getImportDirectory()
Get import directory.
static writeHeaderPage($a_lm_id, $a_page_id)
Write header page.
static writeFooterPage($a_lm_id, $a_page_id)
Write footer page.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
Manifest parser for ILIAS standard export files.
static _writeParentId($a_parent_type, $a_pg_id, $a_par_id)
Write parent id.
const IL_MO_PARSE_QTI
getImport()
Get import.
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.
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
$parser
Definition: BPMN2Parser.php:24
LearningModule Data set class.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
static getLogger($a_component_id)
Get component logger.
const IL_MO_VERIFY_QTI
finalProcessing($a_mapping)
Final processing.
Xml importer class.