ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCourseImporter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=0);
25 {
26  public const ENTITY_MAIN = 'crs';
27  public const ENTITY_OBJECTIVE = 'objectives';
28 
29  private ?ilObjCourse $course = null;
30  private array $final_processing_info = [];
31 
32  protected ilLogger $logger;
33 
34  public function __construct()
35  {
36  global $DIC;
37 
38  $this->logger = $DIC->logger()->crs();
39  }
40 
41  public function init(): void
42  {
43  }
44 
46  public function importXmlRepresentation(
47  string $a_entity,
48  string $a_id,
49  string $a_xml,
50  ilImportMapping $a_mapping
51  ): void {
52  if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_id)) {
53  $refs = ilObject::_getAllReferences((int) $new_id);
54  $this->course = ilObjectFactory::getInstanceByRefId((int) end($refs), false);
55  } // Mapping for containers without subitems
56  elseif ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'refs', '0')) {
57  $this->course = ilObjectFactory::getInstanceByRefId((int) $new_id, false);
58  } elseif (!$this->course instanceof ilObjCourse) {
59  $this->course = new ilObjCourse();
60  $this->course->create();
61  }
62 
63  if ($a_entity == self::ENTITY_OBJECTIVE) {
64  $this->addFinalProcessingInfo($this->course, $a_entity, $a_xml);
65 
66  // import learning objectives => without materials and fixed questions.
67  // These are handled in afterContainerImportProcessing
68  $parser = new ilLOXmlParser($this->course, $a_xml);
69  $parser->setMapping($a_mapping);
70  $parser->parse();
71  return;
72  }
73 
74  try {
75  $parser = new ilCourseXMLParser($this->course);
76  $parser->setXMLContent($a_xml);
77  $parser->startParsing();
78 
79  // set course offline
80  $this->course->setOfflineStatus(true);
81  $this->course->update();
82 
83  $a_mapping->addMapping('components/ILIAS/Course', 'crs', $a_id, (string) $this->course->getId());
84  $a_mapping->addMapping('components/ILIAS/AdvancedMetaData', 'parent', $a_id, (string) $this->course->getId());
85 
86  // workaround for ilImportContainer::createDummy which creates Metadata via create(true)
87  $this->course->deleteMetaData();
88  $a_mapping->addMapping(
89  'components/ILIAS/MetaData',
90  'md',
91  $a_id . ':0:crs',
92  $this->course->getId() . ':0:crs'
93  );
95  $this->logger->error('Parsing failed with message, "' . $e->getMessage() . '".');
96  }
97  }
98 
99  public function afterContainerImportProcessing(\ilImportMapping $mapping): void
100  {
101  foreach ($this->final_processing_info as $info) {
102  // import learning objectives
103  $parser = new ilLOXmlParser($info['course'], $info['xml']);
104  $parser->setMapping($mapping);
105  $parser->parseObjectDependencies();
106  return;
107  }
108  }
109 
110  protected function addFinalProcessingInfo($a_course, $a_entity, $a_xml): void
111  {
112  $this->final_processing_info[] = array(
113  'course' => $a_course,
114  'entity' => $a_entity,
115  'xml' => $a_xml
116  );
117  }
118 }
afterContainerImportProcessing(\ilImportMapping $mapping)
static _getAllReferences(int $id)
get all reference ids for object ID
addFinalProcessingInfo($a_course, $a_entity, $a_xml)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
PhpFieldAssignmentTypeMismatchInspection
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getMapping(string $a_comp, string $a_entity, string $a_old_id)
Class ilLOXmlWriter.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
global $DIC
Definition: shib_login.php:22
Xml importer class.