19 declare(strict_types=0);
40 $this->
logger = $DIC->logger()->crs();
62 $use_internal_errors = libxml_use_internal_errors(
true);
63 $root = simplexml_load_string(trim($this->xml));
64 libxml_use_internal_errors($use_internal_errors);
66 $this->
logger->debug(
'XML is: ' . $this->xml . $root);
70 $this->
logger->debug(
'Handling element: ' . $root->getName());
80 $use_internal_errors = libxml_use_internal_errors(
true);
81 $root = simplexml_load_string(trim($this->xml));
82 libxml_use_internal_errors($use_internal_errors);
84 $this->
logger->debug(
'XML is: ' . $this->xml . $root);
89 foreach ($root->Objective as $obj) {
90 $mapped_objective_id = $this->
getMapping()->getMapping(
91 'components/ILIAS/Course',
93 (
string) $obj->attributes()->id
95 if ($mapped_objective_id) {
97 $this->
parseTests($obj, (
int) $mapped_objective_id);
105 $this->
logger->debug(
': Handling element: ' . $root->Settings->getName());
106 foreach ($root->Settings as $set) {
107 $this->
logger->debug(
'Handling element: ' . $set->getName());
108 $settings->setInitialTestType((
int) (
string) $set->attributes()->initialTestType);
109 $settings->setInitialTestAsStart((
bool) (
string) $set->attributes()->initialTestStart);
110 $settings->setQualifyingTestType((
int) (
string) $set->attributes()->qualifyingTestType);
111 $settings->setQualifyingTestAsStart((
bool) (
string) $set->attributes()->qualifyingTestStart);
112 $settings->resetResults((
bool) (
string) $set->attributes()->resetResults);
113 $settings->setPassedObjectiveMode((
int) (
string) $set->attributes()->passedObjectivesMode);
117 $settings->setInitialTest($itest);
121 $settings->setQualifiedTest($qtest);
132 foreach ($root->Objective as $obj) {
134 $new_obj->setActive((
bool) (
string) $obj->attributes()->online);
135 $new_obj->setTitle((
string) $obj->Title);
136 $new_obj->setDescription((
string) $obj->Description);
137 $new_obj->setPosition((
int) (
string) $obj->attributes()->position);
138 $new_objective_id = $new_obj->add();
141 'components/ILIAS/Course',
143 (
string) $obj->attributes()->id,
144 (string) $new_objective_id
147 'components/ILIAS/COPage',
149 'lobj:' . $obj->attributes()->id,
150 'lobj:' . $new_objective_id
157 foreach ($obj->Material as $mat) {
158 $mat_ref_id = (string) $mat->attributes()->refId;
161 if ($mapping_ref_id) {
163 $new_mat->setLMRefId($mapping_ref_id);
165 $mat_type = (string) $mat->attributes()->type;
169 $mapped_chapter = $this->
getMapping()->getMapping(
170 'components/ILIAS/LearningModule',
172 (
string) $mat->attributes()->objId
174 if ($mapped_chapter) {
175 $obj_id = $mapped_chapter;
180 $mapped_page = $this->
getMapping()->getMapping(
181 'components/ILIAS/LearningModule',
183 (
string) $mat->attributes()->objId
186 $obj_id = $mapped_page;
195 $new_mat->setLMObjId($obj_id);
196 $new_mat->setType((
string) $mat->attributes()->type);
197 $new_id = $new_mat->add();
198 $new_mat->writePosition($new_id, (
int) (
string) $mat->attributes()->position);
206 $this->
logger->debug(
': Parsing ' . $obj->getName());
208 foreach ($obj->Test as $tst) {
209 $type = (
int) (
string) $tst->attributes()->type;
210 if ($type == self::TYPE_TST_PO) {
211 $tst_ref_id = (string) $tst->attributes()->refId;
213 $this->
logger->debug(
'Found test ref id ' . $tst_ref_id);
214 if (!$mapping_ref_id) {
219 $assignment->setTestRefId($mapping_ref_id);
220 $assignment->setObjectiveId($a_objective_id);
221 $assignment->setAssignmentType((
int) (
string) $tst->attributes()->testType);
223 } elseif ($type == self::TYPE_TST_RND) {
224 $tst_obj_id = (
int) (
string) $tst->attributes()->objId;
230 $new_qpl_id = $this->
getMappingForQpls((
int) (
string) $tst->attributes()->poolId);
238 (
int) (
string) $tst->attributes()->testType,
242 $rnd->setLimit((
int) $tst->attributes()->limit);
245 $tst_ref_id = (string) $tst->attributes()->refId;
247 if (!$mapping_ref_id) {
251 $quest->setTestRefId($mapping_ref_id);
253 $quest->setTestStatus((
int) $tst->attributes()->testType);
254 $quest->setTestSuggestedLimit((
int) $tst->attributes()->limit);
256 foreach ($tst->Question as $qst) {
257 $qid = (string) $qst->attributes()->id;
260 $quest->setQuestionId($mapping_qid);
270 $new_ref_id = $this->
getMapping()->getMapping(
'components/ILIAS/Container',
'refs', (
string) $a_ref_id);
271 $this->
logger->debug(
': Found new ref_id: ' . $new_ref_id .
' for ' . $a_ref_id);
272 return (
int) $new_ref_id;
277 $new_obj_id = $this->
getMapping()->getMapping(
'components/ILIAS/Container',
'objs', (
string) $a_obj_id);
278 $this->
logger->debug(
'Found new ref_id: ' . $new_obj_id .
' for ' . $a_obj_id);
279 return (
int) $new_obj_id;
284 $new_qid = $this->
getMapping()->getMapping(
'components/ILIAS/Test',
'quest', (
string) $qid);
285 $this->
logger->debug(
'Found new question_id: ' . $new_qid .
' for ' . $qid);
286 return (
int) $new_qid;
291 $new_id = $this->
getMapping()->getMapping(
'components/ILIAS/Test',
'rnd_src_pool_def', (
string) $a_id);
293 return (
int) $new_id;
304 foreach (libxml_get_errors() as $err) {
305 $errors .= $err->code .
'<br/>';
parseObjectives(SimpleXMLElement $root)
Parse objective.
parseSettings(SimpleXMLElement $root)
parseObjectDependencies()
Parse object dependencies (assigned strucure objects, page objects, fixed questions) ...
getMappingForQuestion(int $qid)
__construct(ilObjCourse $course, string $a_xml)
static _lookupObjId(int $ref_id)
parseTests(SimpleXMLElement $obj, int $a_objective_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
parseXmlErrors()
Parse xml errors from libxml_get_errors.
class ilCourseObjectiveMaterials
setMapping(ilImportMapping $mapping)
getMappingForQpls(int $a_id)
getMappingInfoForItem(int $a_ref_id)
getMappingInfoForItemObject(int $a_obj_id)
static getInstanceByObjId(int $a_obj_id)
parseMaterials(SimpleXMLElement $obj, int $a_objective_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...