ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilLOXmlParser Class Reference

Class ilLOXmlWriter. More...

+ Collaboration diagram for ilLOXmlParser:

Public Member Functions

 __construct (ilObjCourse $course, $a_xml)
 Constructor. More...
 
 setMapping (ilImportMapping $mapping)
 Set import mapping. More...
 
 getMapping ()
 Get import mapping. More...
 
 parse ()
 Parse xml. More...
 
 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 ()
 Get course. More...
 
 parseSettings (SimpleXMLElement $root)
 
 parseObjectives (SimpleXMLElement $root)
 Parse objective. More...
 
 parseMaterials (SimpleXMLElement $obj, $a_objective_id)
 Parse assigned materials. More...
 
 parseTests (SimpleXMLElement $obj, $a_objective_id)
 Parse tests of objective. More...
 
 getMappingInfoForItem ($a_ref_id)
 Get mapping info. More...
 
 getMappingInfoForItemObject ($a_obj_id)
 Get obj_id mapping. More...
 
 getMappingForQuestion ($qid)
 
 getMappingForQpls ($a_id)
 
 parseXmlErrors ()
 Parse xml errors from libxml_get_errors. More...
 

Private Attributes

 $xml = ''
 
 $course = null
 
 $mapping = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Parameters
ilObjCourse$course
type$a_xml

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

29 {
30 $this->course = $course;
31 $this->xml = $a_xml;
32 }

References $course.

Member Function Documentation

◆ getCourse()

ilLOXmlParser::getCourse ( )
protected

Get course.

Returns
ilObjCourse

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

57 {
58 return $this->course;
59 }

References $course.

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

+ Here is the caller graph for this function:

◆ getMapping()

ilLOXmlParser::getMapping ( )

Get import mapping.

Returns
ilImportMapping

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

48 {
49 return $this->mapping;
50 }

References $mapping.

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

+ Here is the caller graph for this function:

◆ getMappingForQpls()

ilLOXmlParser::getMappingForQpls (   $a_id)
protected

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

340 {
341 $new_id = $this->getMapping()->getMapping('Modules/Test', 'rnd_src_pool_def', $a_id);
342 if($new_id)
343 {
344 return $new_id;
345 }
346 return 0;
347 }
getMapping()
Get import mapping.

References getMapping().

Referenced by parseTests().

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

◆ getMappingForQuestion()

ilLOXmlParser::getMappingForQuestion (   $qid)
protected

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

333 {
334 $new_qid = $this->getMapping()->getMapping('Modules/Test', 'quest', $qid);
335 $GLOBALS['ilLog']->write(__METHOD__.': Found new question_id: ' .$new_qid.' for '. $qid);
336 return $new_qid;
337 }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.

References $GLOBALS, and getMapping().

Referenced by parseTests().

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

◆ getMappingInfoForItem()

ilLOXmlParser::getMappingInfoForItem (   $a_ref_id)
protected

Get mapping info.

Parameters
type$a_ref_id
type$a_obj_id
Returns
int ref id of mapped item

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

314 {
315 $new_ref_id = $this->getMapping()->getMapping('Services/Container', 'refs', $a_ref_id);
316 $GLOBALS['ilLog']->write(__METHOD__.': Found new ref_id: ' .$new_ref_id.' for '. $a_ref_id);
317 return (int) $new_ref_id;
318 }

References $GLOBALS, and getMapping().

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 (   $a_obj_id)
protected

Get obj_id mapping.

Parameters
int$a_obj_id
Returns
int

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

326 {
327 $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', $a_obj_id);
328 $GLOBALS['ilLog']->write(__METHOD__.': Found new ref_id: ' .$new_obj_id.' for '. $a_obj_id);
329 return (int) $new_obj_id;
330 }

References $GLOBALS, and getMapping().

Referenced by parseTests().

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

◆ parse()

ilLOXmlParser::parse ( )

Parse xml.

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

65 {
66 libxml_use_internal_errors(true);
67 $root = simplexml_load_string(trim($this->xml));
68 if(!$root instanceof SimpleXMLElement)
69 {
70 $GLOBALS['ilLog']->write(__METHOD__.': XML is: '. $this->xml. (string) $root);
71 $GLOBALS['ilLog']->write(__METHOD__.': Error parsing objective xml: '.$this->parseXmlErrors());
72 return false;
73 }
74 $GLOBALS['ilLog']->write(__METHOD__.': Handling element: '. (string) $root->getName());
75 $this->parseSettings($root);
76 $this->parseObjectives($root);
77 }
parseObjectives(SimpleXMLElement $root)
Parse objective.
parseSettings(SimpleXMLElement $root)

References $GLOBALS, parseObjectives(), and parseSettings().

+ Here is the call graph for this function:

◆ parseMaterials()

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

Parse assigned materials.

Parameters
SimpleXMLElement$obj

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

166 {
167 foreach($obj->Material as $mat)
168 {
169 $mat_ref_id = (string) $mat->attributes()->refId;
170
171 $mapping_ref_id = $this->getMappingInfoForItem($mat_ref_id);
172 if($mapping_ref_id)
173 {
174 include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
175 $new_mat = new ilCourseObjectiveMaterials($a_objective_id);
176 $new_mat->setLMRefId($mapping_ref_id);
177
178 $mat_type = (string) $mat->attributes()->type;
179 $obj_id = 0;
180 switch($mat_type)
181 {
182 case 'st':
183 $mapped_chapter = $this->getMapping()->getMapping(
184 'Modules/LearningModule',
185 'lm_tree',
186 (int) (string) $mat->attributes()->objId
187 );
188 if($mapped_chapter)
189 {
190 $obj_id = $mapped_chapter;
191 }
192 break;
193
194 case 'pg':
195 $mapped_page = $this->getMapping()->getMapping(
196 'Modules/LearningModule',
197 'pg',
198 (int) (string) $mat->attributes()->objId
199 );
200 if($mapped_page)
201 {
202 $obj_id = $mapped_page;
203 }
204 break;
205
206 default:
207 $obj_id = ilObject::_lookupObjId($mapping_ref_id);
208 break;
209 }
210 if($obj_id)
211 {
212 $new_mat->setLMObjId($obj_id);
213 $new_mat->setType((string) $mat->attributes()->type);
214 $new_id = $new_mat->add();
215 $new_mat->writePosition($new_id, (int) (string) $mat->attributes()->position);
216 }
217 }
218 }
219 }
class ilCourseObjectiveMaterials
getMappingInfoForItem($a_ref_id)
Get mapping info.
static _lookupObjId($a_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 82 of file class.ilLOXmlParser.php.

83 {
84 libxml_use_internal_errors(true);
85 $root = simplexml_load_string(trim($this->xml));
86 if(!$root instanceof SimpleXMLElement)
87 {
88 $GLOBALS['ilLog']->write(__METHOD__.': XML is: '. $this->xml. (string) $root);
89 $GLOBALS['ilLog']->write(__METHOD__.': Error parsing objective xml: '.$this->parseXmlErrors());
90 return false;
91 }
92
93 foreach($root->Objective as $obj)
94 {
95 $mapped_objective_id = $this->getMapping()->getMapping('Modules/Course', 'objectives', (string) $obj->attributes()->id);
96 if($mapped_objective_id)
97 {
98 $this->parseMaterials($obj, $mapped_objective_id);
99 $this->parseTests($obj, $mapped_objective_id);
100 }
101 }
102 }
parseTests(SimpleXMLElement $obj, $a_objective_id)
Parse tests of objective.
parseMaterials(SimpleXMLElement $obj, $a_objective_id)
Parse assigned materials.

References $GLOBALS, getMapping(), parseMaterials(), and parseTests().

+ Here is the call graph for this function:

◆ parseObjectives()

ilLOXmlParser::parseObjectives ( SimpleXMLElement  $root)
protected

Parse objective.

Parameters
SimpleXMLElement$root

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

140 {
141 foreach($root->Objective as $obj)
142 {
143 include_once './Modules/Course/classes/class.ilCourseObjective.php';
144 $new_obj = new ilCourseObjective($this->getCourse());
145 $new_obj->setActive((bool) (string) $obj->attributes()->online);
146 $new_obj->setTitle((string) $obj->Title);
147 $new_obj->setDescription((string) $obj->Description);
148 $new_obj->setPosition((int) (string) $obj->attributes()->position);
149 $new_objective_id = $new_obj->add();
150
151 $this->getMapping()->addMapping('Modules/Course', 'objectives', (string) $obj->attributes()->id, $new_objective_id);
152 $this->getMapping()->addMapping('Services/COPage', 'pg', 'lobj:'.(string) $obj->attributes()->id, 'lobj:'.$new_objective_id);
153
154 // done after container import complete
155 //$this->parseMaterials($obj,$new_objective_id);
156 //$this->parseTests($obj, $new_objective_id);
157
158 }
159 }
class ilcourseobjective
getCourse()
Get course.

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
Parameters
SimpleXMLElement$root

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

109 {
110 include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
111 $settings = ilLOSettings::getInstanceByObjId($this->getCourse()->getId());
112 $GLOBALS['ilLog']->write(__METHOD__.': Handling element: '. (string) $root->Settings->getName());
113 foreach($root->Settings as $set)
114 {
115 $GLOBALS['ilLog']->write(__METHOD__.': Handling element: '. (string) $set->getName());
116 $settings->setInitialTestType((int) (string) $set->attributes()->initialTestType);
117 $settings->setInitialTestAsStart((bool) (string) $set->attributes()->initialTestStart);
118 $settings->setQualifyingTestType((int) (string) $set->attributes()->qualifyingTestType);
119 $settings->setQualifyingTestAsStart((bool) (string) $set->attributes()->qualifyingTestStart);
120 $settings->resetResults((bool) (string) $set->attributes()->resetResults);
121 $settings->setPassedObjectiveMode((int) (string) $set->attributes()->passedObjectivesMode);
122
123 // itest
124 $itest = (int) $this->getMappingInfoForItem((int) (string) $set->attributes()->iTest);
125 $settings->setInitialTest($itest);
126
127 // qtest
128 $qtest = (int) $this->getMappingInfoForItem((int) (string) $set->attributes()->qTest);
129 $settings->setQualifiedTest($qtest);
130
131 $settings->update();
132 }
133 }
static getInstanceByObjId($a_obj_id)
get singleton instance

References $GLOBALS, getCourse(), ilLOSettings\getInstanceByObjId(), and getMappingInfoForItem().

Referenced by parse().

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

◆ parseTests()

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

Parse tests of objective.

Parameters
SimpleXMLElement$obj
type$a_objective_id

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

227 {
228 $GLOBALS['ilLog']->write(__METHOD__.': Parsing ' . (string) $obj->getName());
229
230 foreach($obj->Test as $tst)
231 {
232 $type = (int) (string) $tst->attributes()->type;
233
234
235 if($type == self::TYPE_TST_PO)
236 {
237 $tst_ref_id = (string) $tst->attributes()->refId;
238 $mapping_ref_id = $this->getMappingInfoForItem($tst_ref_id);
239 $GLOBALS['ilLog']->write(__METHOD__.': Found test ref id ' . (string) $tst_ref_id);
240 if(!$mapping_ref_id)
241 {
242 continue;
243 }
244 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignment.php';
245 $assignment = new ilLOTestAssignment();
246 $assignment->setContainerId($this->getCourse()->getId());
247 $assignment->setTestRefId($mapping_ref_id);
248 $assignment->setObjectiveId($a_objective_id);
249 $assignment->setAssignmentType((int) (string) $tst->attributes()->testType);
250 $assignment->save();
251 }
252 elseif($type == self::TYPE_TST_RND)
253 {
254 $tst_obj_id = (int) (string) $tst->attributes()->objId;
255 $mapping_id = $this->getMappingInfoForItemObject($tst_obj_id);
256 if(!$mapping_id)
257 {
258 continue;
259 }
260
261 $new_qpl_id = $this->getMappingForQpls((int) (string) $tst->attributes()->poolId);
262 if(!$new_qpl_id)
263 {
264 continue;
265 }
266
267 include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
269 $this->getCourse()->getId(),
270 $a_objective_id,
271 (int) (string) $tst->attributes()->testType
272 );
273 $rnd->setTestId($mapping_id);
274 $rnd->setLimit((string) $tst->attributes()->limit);
275 $rnd->setQplSequence($new_qpl_id);
276 $rnd->create();
277 }
278 else
279 {
280 $tst_ref_id = (string) $tst->attributes()->refId;
281 $mapping_ref_id = $this->getMappingInfoForItem($tst_ref_id);
282 if(!$mapping_ref_id)
283 {
284 continue;
285 }
286 include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
287 $quest = new ilCourseObjectiveQuestion($a_objective_id);
288 $quest->setTestRefId($mapping_ref_id);
289 $quest->setTestObjId(ilObject::_lookupObjId($mapping_ref_id));
290 $quest->setTestStatus((string) $tst->attributes()->testType);
291 $quest->setTestSuggestedLimit((string) $tst->attributes()->limit);
292
293 foreach($tst->Question as $qst)
294 {
295 $qid = (string) $qst->attributes()->id;
296 $mapping_qid = $this->getMappingForQuestion($qid);
297 if($mapping_qid)
298 {
299 $quest->setQuestionId($mapping_qid);
300 $quest->add();
301 }
302 }
303 }
304 }
305 }
class ilcourseobjectiveQuestion
Settings for LO courses.
getMappingInfoForItemObject($a_obj_id)
Get obj_id mapping.

References $GLOBALS, ilObject\_lookupObjId(), getCourse(), getMappingForQpls(), getMappingForQuestion(), getMappingInfoForItem(), and getMappingInfoForItemObject().

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.

Returns
string

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

362 {
363 $errors = '';
364 foreach(libxml_get_errors() as $err)
365 {
366 $errors .= $err->code.'<br/>';
367 }
368 return $errors;
369 }
$errors

References $errors.

◆ setMapping()

ilLOXmlParser::setMapping ( ilImportMapping  $mapping)

Set import mapping.

Parameters
ilImportMapping$mapping

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

39 {
40 $this->mapping = $mapping;
41 }

References $mapping.

Field Documentation

◆ $course

ilLOXmlParser::$course = null
private

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

Referenced by __construct(), and getCourse().

◆ $mapping

ilLOXmlParser::$mapping = null
private

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

Referenced by getMapping(), and setMapping().

◆ $xml

ilLOXmlParser::$xml = ''
private

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

◆ TYPE_TST_ALL

const ilLOXmlParser::TYPE_TST_ALL = 2

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

◆ TYPE_TST_PO

const ilLOXmlParser::TYPE_TST_PO = 1

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

◆ TYPE_TST_RND

const ilLOXmlParser::TYPE_TST_RND = 3

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


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