ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilLOXmlParser Class Reference

Class ilLOXmlWriter. More...

+ Collaboration diagram for ilLOXmlParser:

Public Member Functions

 __construct (ilObjCourse $course, string $a_xml)
 
 setMapping (ilImportMapping $mapping)
 
 getMapping ()
 
 parse ()
 
 parseObjectDependencies ()
 Parse object dependencies (assigned strucure objects, page objects, fixed questions) More...
 

Data Fields

const TYPE_TST_PO = 1
 
const TYPE_TST_ALL = 2
 
const TYPE_TST_RND = 3
 

Protected Member Functions

 getCourse ()
 
 parseSettings (SimpleXMLElement $root)
 
 parseObjectives (SimpleXMLElement $root)
 Parse objective. More...
 
 parseMaterials (SimpleXMLElement $obj, int $a_objective_id)
 
 parseTests (SimpleXMLElement $obj, int $a_objective_id)
 
 getMappingInfoForItem (int $a_ref_id)
 
 getMappingInfoForItemObject (int $a_obj_id)
 
 getMappingForQuestion (int $qid)
 
 getMappingForQpls (int $a_id)
 
 parseXmlErrors ()
 Parse xml errors from libxml_get_errors. More...
 

Private Attributes

string $xml = ''
 
ilObjCourse $course
 
ilImportMapping $mapping = null
 
ilLogger $logger
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilLOXmlParser::__construct ( ilObjCourse  $course,
string  $a_xml 
)

Definition at line 36 of file class.ilLOXmlParser.php.

37 {
38 global $DIC;
39
40 $this->logger = $DIC->logger()->crs();
41 $this->course = $course;
42 $this->xml = $a_xml;
43 }
global $DIC
Definition: shib_login.php:26

References $course, $DIC, and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ getCourse()

ilLOXmlParser::getCourse ( )
protected

Definition at line 55 of file class.ilLOXmlParser.php.

56 {
57 return $this->course;
58 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $course.

Referenced by parseObjectives(), parseSettings(), and parseTests().

+ Here is the caller graph for this function:

◆ getMapping()

ilLOXmlParser::getMapping ( )

Definition at line 50 of file class.ilLOXmlParser.php.

51 {
52 return $this->mapping;
53 }
ilImportMapping $mapping

References $mapping.

Referenced by getMappingForQpls(), getMappingForQuestion(), getMappingInfoForItem(), getMappingInfoForItemObject(), parseMaterials(), parseObjectDependencies(), and parseObjectives().

+ Here is the caller graph for this function:

◆ getMappingForQpls()

ilLOXmlParser::getMappingForQpls ( int  $a_id)
protected

Definition at line 289 of file class.ilLOXmlParser.php.

289 : int
290 {
291 $new_id = $this->getMapping()->getMapping('components/ILIAS/Test', 'rnd_src_pool_def', (string) $a_id);
292 if ($new_id) {
293 return (int) $new_id;
294 }
295 return 0;
296 }

References getMapping().

Referenced by parseTests().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMappingForQuestion()

ilLOXmlParser::getMappingForQuestion ( int  $qid)
protected

Definition at line 282 of file class.ilLOXmlParser.php.

282 : int
283 {
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;
287 }

References getMapping(), and ILIAS\Repository\logger().

Referenced by parseTests().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMappingInfoForItem()

ilLOXmlParser::getMappingInfoForItem ( int  $a_ref_id)
protected

Definition at line 268 of file class.ilLOXmlParser.php.

268 : int
269 {
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;
273 }

References getMapping(), and ILIAS\Repository\logger().

Referenced by parseMaterials(), parseSettings(), and parseTests().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMappingInfoForItemObject()

ilLOXmlParser::getMappingInfoForItemObject ( int  $a_obj_id)
protected

Definition at line 275 of file class.ilLOXmlParser.php.

275 : int
276 {
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;
280 }

References getMapping(), and ILIAS\Repository\logger().

Referenced by parseTests().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

ilLOXmlParser::parse ( )

Definition at line 60 of file class.ilLOXmlParser.php.

60 : void
61 {
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);
65 if (!$root instanceof SimpleXMLElement) {
66 $this->logger->debug('XML is: ' . $this->xml . $root);
67 $this->logger->debug('Error parsing objective xml: ' . $this->parseXmlErrors());
68 return;
69 }
70 $this->logger->debug('Handling element: ' . $root->getName());
71 $this->parseSettings($root);
72 $this->parseObjectives($root);
73 }
parseXmlErrors()
Parse xml errors from libxml_get_errors.
parseObjectives(SimpleXMLElement $root)
Parse objective.
parseSettings(SimpleXMLElement $root)

References ILIAS\Repository\logger(), parseObjectives(), parseSettings(), and parseXmlErrors().

+ Here is the call graph for this function:

◆ parseMaterials()

ilLOXmlParser::parseMaterials ( SimpleXMLElement  $obj,
int  $a_objective_id 
)
protected

Definition at line 155 of file class.ilLOXmlParser.php.

155 : void
156 {
157 foreach ($obj->Material as $mat) {
158 $mat_ref_id = (string) $mat->attributes()->refId;
159
160 $mapping_ref_id = $this->getMappingInfoForItem((int) $mat_ref_id);
161 if ($mapping_ref_id) {
162 $new_mat = new ilCourseObjectiveMaterials($a_objective_id);
163 $new_mat->setLMRefId($mapping_ref_id);
164
165 $mat_type = (string) $mat->attributes()->type;
166 $obj_id = 0;
167 switch ($mat_type) {
168 case 'st':
169 $mapped_chapter = $this->getMapping()->getMapping(
170 'components/ILIAS/LearningModule',
171 'lm_tree',
172 (string) $mat->attributes()->objId
173 );
174 if ($mapped_chapter) {
175 $obj_id = $mapped_chapter;
176 }
177 break;
178
179 case 'pg':
180 $mapped_page = $this->getMapping()->getMapping(
181 'components/ILIAS/LearningModule',
182 'pg',
183 (string) $mat->attributes()->objId
184 );
185 if ($mapped_page) {
186 $obj_id = $mapped_page;
187 }
188 break;
189
190 default:
191 $obj_id = ilObject::_lookupObjId($mapping_ref_id);
192 break;
193 }
194 if ($obj_id) {
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);
199 }
200 }
201 }
202 }
class ilCourseObjectiveMaterials
getMappingInfoForItem(int $a_ref_id)
static _lookupObjId(int $ref_id)

References ilObject\_lookupObjId(), getMapping(), and getMappingInfoForItem().

Referenced by parseObjectDependencies().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseObjectDependencies()

ilLOXmlParser::parseObjectDependencies ( )

Parse object dependencies (assigned strucure objects, page objects, fixed questions)

Definition at line 78 of file class.ilLOXmlParser.php.

78 : void
79 {
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);
83 if (!$root instanceof SimpleXMLElement) {
84 $this->logger->debug('XML is: ' . $this->xml . $root);
85 $this->logger->debug('Error parsing objective xml: ' . $this->parseXmlErrors());
86 return;
87 }
88
89 foreach ($root->Objective as $obj) {
90 $mapped_objective_id = $this->getMapping()->getMapping(
91 'components/ILIAS/Course',
92 'objectives',
93 (string) $obj->attributes()->id
94 );
95 if ($mapped_objective_id) {
96 $this->parseMaterials($obj, (int) $mapped_objective_id);
97 $this->parseTests($obj, (int) $mapped_objective_id);
98 }
99 }
100 }
parseTests(SimpleXMLElement $obj, int $a_objective_id)
parseMaterials(SimpleXMLElement $obj, int $a_objective_id)

References getMapping(), ILIAS\Repository\logger(), parseMaterials(), parseTests(), and parseXmlErrors().

+ Here is the call graph for this function:

◆ parseObjectives()

ilLOXmlParser::parseObjectives ( SimpleXMLElement  $root)
protected

Parse objective.

Definition at line 130 of file class.ilLOXmlParser.php.

130 : void
131 {
132 foreach ($root->Objective as $obj) {
133 $new_obj = new ilCourseObjective($this->getCourse());
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();
139
140 $this->getMapping()->addMapping(
141 'components/ILIAS/Course',
142 'objectives',
143 (string) $obj->attributes()->id,
144 (string) $new_objective_id
145 );
146 $this->getMapping()->addMapping(
147 'components/ILIAS/COPage',
148 'pg',
149 'lobj:' . $obj->attributes()->id,
150 'lobj:' . $new_objective_id
151 );
152 }
153 }
class ilcourseobjective

References getCourse(), and getMapping().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseSettings()

ilLOXmlParser::parseSettings ( SimpleXMLElement  $root)
protected

Definition at line 102 of file class.ilLOXmlParser.php.

102 : void
103 {
104 $settings = ilLOSettings::getInstanceByObjId($this->getCourse()->getId());
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);
114
115 // itest
116 $itest = $this->getMappingInfoForItem((int) (string) $set->attributes()->iTest);
117 $settings->setInitialTest($itest);
118
119 // qtest
120 $qtest = $this->getMappingInfoForItem((int) (string) $set->attributes()->qTest);
121 $settings->setQualifiedTest($qtest);
122
123 $settings->update();
124 }
125 }
static getInstanceByObjId(int $a_obj_id)

References getCourse(), ILIAS\Survey\Mode\getId(), ilLOSettings\getInstanceByObjId(), getMappingInfoForItem(), and ILIAS\Repository\logger().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseTests()

ilLOXmlParser::parseTests ( SimpleXMLElement  $obj,
int  $a_objective_id 
)
protected

Definition at line 204 of file class.ilLOXmlParser.php.

204 : void
205 {
206 $this->logger->debug(': Parsing ' . $obj->getName());
207
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;
212 $mapping_ref_id = $this->getMappingInfoForItem((int) $tst_ref_id);
213 $this->logger->debug('Found test ref id ' . $tst_ref_id);
214 if (!$mapping_ref_id) {
215 continue;
216 }
217 $assignment = new ilLOTestAssignment();
218 $assignment->setContainerId($this->getCourse()->getId());
219 $assignment->setTestRefId($mapping_ref_id);
220 $assignment->setObjectiveId($a_objective_id);
221 $assignment->setAssignmentType((int) (string) $tst->attributes()->testType);
222 $assignment->save();
223 } elseif ($type == self::TYPE_TST_RND) {
224 $tst_obj_id = (int) (string) $tst->attributes()->objId;
225 $mapping_id = $this->getMappingInfoForItemObject($tst_obj_id);
226 if (!$mapping_id) {
227 continue;
228 }
229
230 $new_qpl_id = $this->getMappingForQpls((int) (string) $tst->attributes()->poolId);
231 if (!$new_qpl_id) {
232 continue;
233 }
234
236 $this->getCourse()->getId(),
237 $a_objective_id,
238 (int) (string) $tst->attributes()->testType,
239 $new_qpl_id
240 );
241 $rnd->setTestId($mapping_id);
242 $rnd->setLimit((int) $tst->attributes()->limit);
243 $rnd->create();
244 } else {
245 $tst_ref_id = (string) $tst->attributes()->refId;
246 $mapping_ref_id = $this->getMappingInfoForItem((int) $tst_ref_id);
247 if (!$mapping_ref_id) {
248 continue;
249 }
250 $quest = new ilCourseObjectiveQuestion($a_objective_id);
251 $quest->setTestRefId($mapping_ref_id);
252 $quest->setTestObjId(ilObject::_lookupObjId($mapping_ref_id));
253 $quest->setTestStatus((int) $tst->attributes()->testType);
254 $quest->setTestSuggestedLimit((int) $tst->attributes()->limit);
255
256 foreach ($tst->Question as $qst) {
257 $qid = (string) $qst->attributes()->id;
258 $mapping_qid = $this->getMappingForQuestion((int) $qid);
259 if ($mapping_qid) {
260 $quest->setQuestionId($mapping_qid);
261 $quest->add();
262 }
263 }
264 }
265 }
266 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Settings for LO courses.
getMappingInfoForItemObject(int $a_obj_id)
getMappingForQpls(int $a_id)
getMappingForQuestion(int $qid)

References ilObject\_lookupObjId(), getCourse(), ILIAS\Survey\Mode\getId(), getMappingForQpls(), getMappingForQuestion(), getMappingInfoForItem(), getMappingInfoForItemObject(), ILIAS\Repository\int(), and ILIAS\Repository\logger().

Referenced by parseObjectDependencies().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseXmlErrors()

ilLOXmlParser::parseXmlErrors ( )
protected

Parse xml errors from libxml_get_errors.

Definition at line 301 of file class.ilLOXmlParser.php.

301 : string
302 {
303 $errors = '';
304 foreach (libxml_get_errors() as $err) {
305 $errors .= $err->code . '<br/>';
306 }
307 return $errors;
308 }

Referenced by parse(), and parseObjectDependencies().

+ Here is the caller graph for this function:

◆ setMapping()

ilLOXmlParser::setMapping ( ilImportMapping  $mapping)

Definition at line 45 of file class.ilLOXmlParser.php.

45 : void
46 {
47 $this->mapping = $mapping;
48 }

References $mapping.

Field Documentation

◆ $course

ilObjCourse ilLOXmlParser::$course
private

Definition at line 31 of file class.ilLOXmlParser.php.

Referenced by __construct(), and getCourse().

◆ $logger

ilLogger ilLOXmlParser::$logger
private

Definition at line 34 of file class.ilLOXmlParser.php.

◆ $mapping

ilImportMapping ilLOXmlParser::$mapping = null
private

Definition at line 32 of file class.ilLOXmlParser.php.

Referenced by getMapping(), and setMapping().

◆ $xml

string ilLOXmlParser::$xml = ''
private

Definition at line 30 of file class.ilLOXmlParser.php.

◆ TYPE_TST_ALL

const ilLOXmlParser::TYPE_TST_ALL = 2

Definition at line 27 of file class.ilLOXmlParser.php.

◆ TYPE_TST_PO

const ilLOXmlParser::TYPE_TST_PO = 1

Definition at line 26 of file class.ilLOXmlParser.php.

◆ TYPE_TST_RND

const ilLOXmlParser::TYPE_TST_RND = 3

Definition at line 28 of file class.ilLOXmlParser.php.


The documentation for this class was generated from the following file: