ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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.

References $course.

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

Member Function Documentation

◆ getCourse()

ilLOXmlParser::getCourse ( )
protected

Get course.

Returns
ilObjCourse

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

References $course.

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

57  {
58  return $this->course;
59  }
+ 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.

References $mapping.

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

48  {
49  return $this->mapping;
50  }
+ Here is the caller graph for this function:

◆ getMappingForQpls()

ilLOXmlParser::getMappingForQpls (   $a_id)
protected

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

References getMapping().

Referenced by parseTests().

314  {
315  $new_id = $this->getMapping()->getMapping('Modules/Test', 'rnd_src_pool_def', $a_id);
316  if ($new_id) {
317  return $new_id;
318  }
319  return 0;
320  }
getMapping()
Get import mapping.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMappingForQuestion()

ilLOXmlParser::getMappingForQuestion (   $qid)
protected

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

References $GLOBALS, and getMapping().

Referenced by parseTests().

307  {
308  $new_qid = $this->getMapping()->getMapping('Modules/Test', 'quest', $qid);
309  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Found new question_id: ' . $new_qid . ' for ' . $qid);
310  return $new_qid;
311  }
getMapping()
Get import mapping.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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 287 of file class.ilLOXmlParser.php.

References $GLOBALS, and getMapping().

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

288  {
289  $new_ref_id = $this->getMapping()->getMapping('Services/Container', 'refs', $a_ref_id);
290  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Found new ref_id: ' . $new_ref_id . ' for ' . $a_ref_id);
291  return (int) $new_ref_id;
292  }
getMapping()
Get import mapping.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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 299 of file class.ilLOXmlParser.php.

References $GLOBALS, and getMapping().

Referenced by parseTests().

300  {
301  $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', $a_obj_id);
302  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Found new ref_id: ' . $new_obj_id . ' for ' . $a_obj_id);
303  return (int) $new_obj_id;
304  }
getMapping()
Get import mapping.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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.

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

65  {
66  libxml_use_internal_errors(true);
67  $root = simplexml_load_string(trim($this->xml));
68  if (!$root instanceof SimpleXMLElement) {
69  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': XML is: ' . $this->xml . (string) $root);
70  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Error parsing objective xml: ' . $this->parseXmlErrors());
71  return false;
72  }
73  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Handling element: ' . (string) $root->getName());
74  $this->parseSettings($root);
75  $this->parseObjectives($root);
76  }
parseObjectives(SimpleXMLElement $root)
Parse objective.
parseSettings(SimpleXMLElement $root)
parseXmlErrors()
Parse xml errors from libxml_get_errors.
$root
Definition: sabredav.php:45
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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 158 of file class.ilLOXmlParser.php.

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

Referenced by parseObjectDependencies().

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

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

82  {
83  libxml_use_internal_errors(true);
84  $root = simplexml_load_string(trim($this->xml));
85  if (!$root instanceof SimpleXMLElement) {
86  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': XML is: ' . $this->xml . (string) $root);
87  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Error parsing objective xml: ' . $this->parseXmlErrors());
88  return false;
89  }
90 
91  foreach ($root->Objective as $obj) {
92  $mapped_objective_id = $this->getMapping()->getMapping('Modules/Course', 'objectives', (string) $obj->attributes()->id);
93  if ($mapped_objective_id) {
94  $this->parseMaterials($obj, $mapped_objective_id);
95  $this->parseTests($obj, $mapped_objective_id);
96  }
97  }
98  }
getMapping()
Get import mapping.
parseXmlErrors()
Parse xml errors from libxml_get_errors.
parseMaterials(SimpleXMLElement $obj, $a_objective_id)
Parse assigned materials.
$root
Definition: sabredav.php:45
parseTests(SimpleXMLElement $obj, $a_objective_id)
Parse tests of objective.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:

◆ parseObjectives()

ilLOXmlParser::parseObjectives ( SimpleXMLElement  $root)
protected

Parse objective.

Parameters
SimpleXMLElement$root

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

References getCourse(), and getMapping().

Referenced by parse().

135  {
136  foreach ($root->Objective as $obj) {
137  include_once './Modules/Course/classes/class.ilCourseObjective.php';
138  $new_obj = new ilCourseObjective($this->getCourse());
139  $new_obj->setActive((bool) (string) $obj->attributes()->online);
140  $new_obj->setTitle((string) $obj->Title);
141  $new_obj->setDescription((string) $obj->Description);
142  $new_obj->setPosition((int) (string) $obj->attributes()->position);
143  $new_objective_id = $new_obj->add();
144 
145  $this->getMapping()->addMapping('Modules/Course', 'objectives', (string) $obj->attributes()->id, $new_objective_id);
146  $this->getMapping()->addMapping('Services/COPage', 'pg', 'lobj:' . (string) $obj->attributes()->id, 'lobj:' . $new_objective_id);
147 
148  // done after container import complete
149  //$this->parseMaterials($obj,$new_objective_id);
150  //$this->parseTests($obj, $new_objective_id);
151  }
152  }
getMapping()
Get import mapping.
getCourse()
Get course.
class ilcourseobjective
$root
Definition: sabredav.php:45
+ 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 104 of file class.ilLOXmlParser.php.

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

Referenced by parse().

105  {
106  include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
107  $settings = ilLOSettings::getInstanceByObjId($this->getCourse()->getId());
108  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Handling element: ' . (string) $root->Settings->getName());
109  foreach ($root->Settings as $set) {
110  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Handling element: ' . (string) $set->getName());
111  $settings->setInitialTestType((int) (string) $set->attributes()->initialTestType);
112  $settings->setInitialTestAsStart((bool) (string) $set->attributes()->initialTestStart);
113  $settings->setQualifyingTestType((int) (string) $set->attributes()->qualifyingTestType);
114  $settings->setQualifyingTestAsStart((bool) (string) $set->attributes()->qualifyingTestStart);
115  $settings->resetResults((bool) (string) $set->attributes()->resetResults);
116  $settings->setPassedObjectiveMode((int) (string) $set->attributes()->passedObjectivesMode);
117 
118  // itest
119  $itest = (int) $this->getMappingInfoForItem((int) (string) $set->attributes()->iTest);
120  $settings->setInitialTest($itest);
121 
122  // qtest
123  $qtest = (int) $this->getMappingInfoForItem((int) (string) $set->attributes()->qTest);
124  $settings->setQualifiedTest($qtest);
125 
126  $settings->update();
127  }
128  }
static getInstanceByObjId($a_obj_id)
get singleton instance
getCourse()
Get course.
getMappingInfoForItem($a_ref_id)
Get mapping info.
$root
Definition: sabredav.php:45
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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 213 of file class.ilLOXmlParser.php.

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

Referenced by parseObjectDependencies().

214  {
215  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Parsing ' . (string) $obj->getName());
216 
217  foreach ($obj->Test as $tst) {
218  $type = (int) (string) $tst->attributes()->type;
219 
220 
221  if ($type == self::TYPE_TST_PO) {
222  $tst_ref_id = (string) $tst->attributes()->refId;
223  $mapping_ref_id = $this->getMappingInfoForItem($tst_ref_id);
224  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Found test ref id ' . (string) $tst_ref_id);
225  if (!$mapping_ref_id) {
226  continue;
227  }
228  include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignment.php';
229  $assignment = new ilLOTestAssignment();
230  $assignment->setContainerId($this->getCourse()->getId());
231  $assignment->setTestRefId($mapping_ref_id);
232  $assignment->setObjectiveId($a_objective_id);
233  $assignment->setAssignmentType((int) (string) $tst->attributes()->testType);
234  $assignment->save();
235  } elseif ($type == self::TYPE_TST_RND) {
236  $tst_obj_id = (int) (string) $tst->attributes()->objId;
237  $mapping_id = $this->getMappingInfoForItemObject($tst_obj_id);
238  if (!$mapping_id) {
239  continue;
240  }
241 
242  $new_qpl_id = $this->getMappingForQpls((int) (string) $tst->attributes()->poolId);
243  if (!$new_qpl_id) {
244  continue;
245  }
246 
247  $rnd = new ilLORandomTestQuestionPools(
248  $this->getCourse()->getId(),
249  $a_objective_id,
250  (int) (string) $tst->attributes()->testType,
251  (string) $new_qpl_id
252  );
253  $rnd->setTestId($mapping_id);
254  $rnd->setLimit((string) $tst->attributes()->limit);
255  $rnd->create();
256  } else {
257  $tst_ref_id = (string) $tst->attributes()->refId;
258  $mapping_ref_id = $this->getMappingInfoForItem($tst_ref_id);
259  if (!$mapping_ref_id) {
260  continue;
261  }
262  include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
263  $quest = new ilCourseObjectiveQuestion($a_objective_id);
264  $quest->setTestRefId($mapping_ref_id);
265  $quest->setTestObjId(ilObject::_lookupObjId($mapping_ref_id));
266  $quest->setTestStatus((string) $tst->attributes()->testType);
267  $quest->setTestSuggestedLimit((string) $tst->attributes()->limit);
268 
269  foreach ($tst->Question as $qst) {
270  $qid = (string) $qst->attributes()->id;
271  $mapping_qid = $this->getMappingForQuestion($qid);
272  if ($mapping_qid) {
273  $quest->setQuestionId($mapping_qid);
274  $quest->add();
275  }
276  }
277  }
278  }
279  }
$type
getCourse()
Get course.
getMappingInfoForItemObject($a_obj_id)
Get obj_id mapping.
getMappingInfoForItem($a_ref_id)
Get mapping info.
static _lookupObjId($a_id)
Settings for LO courses.
class ilcourseobjectiveQuestion
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ 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 334 of file class.ilLOXmlParser.php.

References $errors.

Referenced by parse(), and parseObjectDependencies().

335  {
336  $errors = '';
337  foreach (libxml_get_errors() as $err) {
338  $errors .= $err->code . '<br/>';
339  }
340  return $errors;
341  }
$errors
Definition: index.php:6
+ Here is the caller graph for this function:

◆ setMapping()

ilLOXmlParser::setMapping ( ilImportMapping  $mapping)

Set import mapping.

Parameters
ilImportMapping$mapping

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

References $mapping.

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

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: