ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseExporter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
26{
27 public const string ENTITY_OBJECTIVE = 'objectives';
28 public const string ENTITY_MAIN = 'crs';
29
31 protected ilLogger $logger;
32
33 public function __construct()
34 {
35 global $DIC;
36 $this->logger = $DIC->logger()->crs();
37 }
38
39 public function init(): void
40 {
41 }
42
46 public function getXmlExportHeadDependencies(string $a_entity, string $a_target_release, array $a_ids): array
47 {
48 if ($a_entity != self::ENTITY_MAIN) {
49 return array();
50 }
51
52 // always trigger container because of co-page(s)
53 return array(
54 array(
55 'component' => 'components/ILIAS/Container',
56 'entity' => 'struct',
57 'ids' => $a_ids
58 )
59 );
60 }
61
62 protected function getActiveAdvMDRecords(int $a_id): array
63 {
64 $active = [];
65 foreach (ilAdvancedMDRecord::_getActivatedRecordsByObjectType('crs') as $record_obj) {
66 foreach ($record_obj->getAssignedObjectTypes() as $obj_info) {
67 if ($obj_info['obj_type'] == 'crs' && $obj_info['optional'] == 0) {
68 $active[] = $record_obj->getRecordId();
69 }
70 // local activation
71 if (
72 $obj_info['obj_type'] == 'crs' &&
73 $obj_info['optional'] == 1 &&
74 $a_id == $record_obj->getParentObject()
75 ) {
76 $active[] = $record_obj->getRecordId();
77 }
78 }
79 }
80 return $active;
81 }
82
83
84 public function getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids): array
85 {
86 if ($a_entity !== self::ENTITY_MAIN) {
87 return [];
88 }
89
90 $dependencies = [];
91 $obj_id = 0;
92 foreach ($a_ids as $id) {
93 $obj_id = $id;
94 }
95
96 $dependencies[] = [
97 'component' => 'components/ILIAS/Course',
98 'entity' => self::ENTITY_OBJECTIVE,
99 'ids' => $obj_id
100 ];
101
102 $page_ids = [];
103 foreach (ilCourseObjective::_getObjectiveIds($obj_id) as $objective_id) {
104 foreach (ilLOPage::getAllPages('lobj', $objective_id) as $page_id) {
105 $page_ids[] = ('lobj:' . $page_id['id']);
106 }
107 }
108
109 if ($page_ids !== []) {
110 $dependencies[] = [
111 'component' => 'components/ILIAS/COPage',
112 'entity' => 'pg',
113 'ids' => $page_ids
114 ];
115 }
116
117 $advmd_ids = [];
118 foreach ($a_ids as $id) {
119 $rec_ids = $this->getActiveAdvMDRecords($id);
120 foreach ($rec_ids as $rec_id) {
121 $advmd_ids[] = $id . ":" . $rec_id;
122 }
123 }
124
125 if ($advmd_ids !== []) {
126 $dependencies[] = [
127 "component" => "components/ILIAS/AdvancedMetaData",
128 "entity" => "advmd",
129 "ids" => $advmd_ids
130 ];
131 }
132
133 $md_ids = [];
134 foreach ($a_ids as $crs_id) {
135 $md_ids[] = $crs_id . ":0:crs";
136 }
137 if ($md_ids !== []) {
138 $dependencies[] = [
139 "component" => "components/ILIAS/MetaData",
140 "entity" => "md",
141 "ids" => $md_ids
142 ];
143 }
144 return $dependencies;
145 }
146
147 public function getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id): string
148 {
149 $refs = ilObject::_getAllReferences((int) $a_id);
150 $course_ref_id = end($refs);
151 $course = ilObjectFactory::getInstanceByRefId($course_ref_id, false);
152
153 // begin-patch optes_lok_export
154 if ($a_entity == self::ENTITY_OBJECTIVE) {
155 try {
156 $writer = new ilLOXmlWriter($course_ref_id);
157 $writer->write();
158 return $writer->getXml();
159 } catch (Exception $ex) {
160 $this->logger->error('Export failed with message: ' . $ex->getMessage());
161 // and throw
162 throw $ex;
163 }
164 }
165 // end-patch optes_lok_export
166
167 if (!$course instanceof ilObjCourse) {
168 $this->logger->warning($a_id . ' is not id of course instance.');
169 return '';
170 }
171
172 $this->writer = new ilCourseXMLWriter($course);
173 $this->writer->setMode(ilCourseXMLWriter::MODE_EXPORT);
174 $this->writer->start();
175 return $this->writer->xmlDumpMem(false);
176 }
177
178 public function getValidSchemaVersions(string $a_entity): array
179 {
180 return [
181 "11.0" => [
182 "namespace" => 'http://www.ilias.de/Modules/Course/crs/11',
183 "xsd_file" => 'ilias_crs_11_0.xsd',
184 "uses_dataset" => false,
185 "min" => "11.0",
186 "max" => ""
187 ],
188 "10.0" => [
189 "namespace" => 'http://www.ilias.de/Modules/Course/crs/10',
190 "xsd_file" => 'ilias_crs_10_0.xsd',
191 "uses_dataset" => false,
192 "min" => "10.0",
193 "max" => "10.999"
194 ],
195 "9.0" => [
196 "namespace" => 'http://www.ilias.de/Modules/Course/crs/9',
197 "xsd_file" => 'ilias_crs_9_0.xsd',
198 "uses_dataset" => false,
199 "min" => "9.0",
200 "max" => "9.999"
201 ],
202 "4.1.0" => [
203 "namespace" => "http://www.ilias.de/Modules/Course/crs/4_1",
204 "xsd_file" => "ilias_course_4_1.xsd",
205 "uses_dataset" => false,
206 "min" => "4.1.0",
207 "max" => "4.4.999"
208 ],
209 "5.0.0" => [
210 "namespace" => "http://www.ilias.de/Modules/Course/crs/5_0",
211 "xsd_file" => "ilias_crs_5_0.xsd",
212 "uses_dataset" => false,
213 "min" => "5.0.0",
214 "max" => "8.999"
215 ]
216 ];
217 }
218}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _getActivatedRecordsByObjectType(string $a_obj_type, string $a_sub_type="", bool $a_only_optional=false)
Get activated records by object type.
getValidSchemaVersions(string $a_entity)
Returns schema versions that the component can export to.
getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id)
getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids)
Get tail dependencies.
getXmlExportHeadDependencies(string $a_entity, string $a_target_release, array $a_ids)
Get head dependencies.
static _getObjectiveIds(int $course_id, bool $a_activated_only=false)
XML writer class Class to simplify manual writing of xml documents.
Class ilLOXmlWriter.
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences(int $id)
get all reference ids for object ID
static getAllPages(string $a_parent_type, int $a_parent_id, string $a_lang="-")
Get all pages for parent object.
Xml Exporter class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26