ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCourseImporter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Export/classes/class.ilXmlImporter.php");
5 
16 {
17  const ENTITY_MAIN = 'crs';
18  const ENTITY_OBJECTIVE = 'objectives';
19 
20  private $course = null;
21 
22  private $final_processing_info = array();
23 
24 
25  public function init()
26  {
27  }
28 
35  public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
36  {
37  include_once './Modules/Course/classes/class.ilCourseXMLParser.php';
38  include_once './Modules/Course/classes/class.ilObjCourse.php';
39 
40 
41  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
42  $refs = ilObject::_getAllReferences($new_id);
43  $this->course = ilObjectFactory::getInstanceByRefId(end($refs), false);
44  #$this->course = ilObjectFactory::getInstanceByObjId($new_id,false);
45  }
46  // Mapping for containers without subitems
47  elseif ($new_id = $a_mapping->getMapping('Services/Container', 'refs', 0)) {
48  $this->course = ilObjectFactory::getInstanceByRefId($new_id, false);
49  } elseif (!$this->course instanceof ilObjCourse) {
50  $this->course = new ilObjCourse();
51  $this->course->create(true);
52  }
53 
54  if ($a_entity == self::ENTITY_OBJECTIVE) {
55  $this->addFinalProcessingInfo($this->course, $a_entity, $a_xml);
56 
57  // import learning objectives => without materials and fixed questions.
58  // These are handled in afterContainerImportProcessing
59  include_once './Modules/Course/classes/Objectives/class.ilLOXmlParser.php';
60  $parser = new ilLOXmlParser($this->course, $a_xml);
61  $parser->setMapping($a_mapping);
62  $parser->parse();
63  return;
64  }
65 
66  try {
67  $parser = new ilCourseXMLParser($this->course);
68  $parser->setXMLContent($a_xml);
69  $parser->startParsing();
70 
71  // set course offline
72  $this->course->setOfflineStatus(true);
73  $this->course->update();
74 
75  $a_mapping->addMapping('Modules/Course', 'crs', $a_id, $this->course->getId());
76  } catch (ilSaxParserException $e) {
77  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Parsing failed with message, "' . $e->getMessage() . '".');
78  } catch (Exception $e) {
79  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Parsing failed with message, "' . $e->getMessage() . '".');
80  }
81  }
82 
83 
84 
90  {
91  foreach ($this->final_processing_info as $info) {
92  // import learning objectives
93  include_once './Modules/Course/classes/Objectives/class.ilLOXmlParser.php';
94  $parser = new ilLOXmlParser($info['course'], $info['xml']);
95  $parser->setMapping($mapping);
96  $parser->parseObjectDependencies();
97  return;
98  }
99  }
100 
104  protected function addFinalProcessingInfo($a_course, $a_entity, $a_xml)
105  {
106  $this->final_processing_info[] = array(
107  'course' => $a_course,
108  'entity' => $a_entity,
109  'xml' => $a_xml
110  );
111  }
112 }
afterContainerImportProcessing(\ilImportMapping $mapping)
addFinalProcessingInfo($a_course, $a_entity, $a_xml)
Add information for final processing.
folder xml importer
SaxParserException thrown by ilSaxParser if property throwException is set.
static _getAllReferences($a_id)
get all reference ids of object
Class ilLOXmlWriter.
Class ilObjCourse.
$parser
Definition: BPMN2Parser.php:23
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
$info
Definition: index.php:5
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
Xml importer class.