ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilObjQuestionPoolXMLParser.php
Go to the documentation of this file.
1<?php
2
23{
24 private \ilObjQuestionPool $poolOBJ;
25
27
30 private bool $title_processed = false;
31 private bool $description_processed = false;
32 private string $cdata = "";
33
38 public function __construct(ilObjQuestionPool $poolOBJ, ?string $xmlFile)
39 {
40 $this->poolOBJ = $poolOBJ;
41
42 $this->inSettingsTag = false;
43 $this->inMetaDataTag = false;
44 $this->inMdGeneralTag = false;
45
46 parent::__construct($xmlFile);
47 }
48
49 public function setHandlers($a_xml_parser): void
50 {
51 xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
52 xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
53 }
54
55 public function handlerBeginTag($xmlParser, $tagName, $tagAttributes): void
56 {
57 switch ($tagName) {
58 case 'MetaData':
59 $this->inMetaDataTag = true;
60 break;
61
62 case 'General':
63 if ($this->inMetaDataTag) {
64 $this->inMdGeneralTag = true;
65 }
66 break;
67
68 case 'Title':
69 case 'Description':
70 $this->cdata = '';
71 break;
72
73 case 'Settings':
74 $this->inSettingsTag = true;
75 break;
76
77 case 'NavTaxonomy':
78 case 'SkillService':
79 if ($this->inSettingsTag) {
80 $this->cdata = '';
81 }
82 break;
83 }
84 }
85
86 public function handlerEndTag($xmlParser, $tagName): void
87 {
88 switch ($tagName) {
89 case 'MetaData':
90 $this->inMetaDataTag = false;
91 break;
92
93 case 'General':
94 if ($this->inMetaDataTag) {
95 $this->inMdGeneralTag = false;
96 }
97 break;
98
99 case 'Title':
100 if (!$this->title_processed) {
101 $this->poolOBJ->setTitle($this->cdata);
102 $this->title_processed = true;
103 $this->cdata = '';
104 }
105 break;
106
107 case 'Description':
108 if (!$this->description_processed) {
109 $this->poolOBJ->setDescription($this->cdata);
110 $this->description_processed = true;
111 $this->cdata = '';
112 }
113 break;
114
115 case 'Settings':
116 $this->inSettingsTag = false;
117 break;
118
119 case 'SkillService':
120 $this->poolOBJ->setSkillServiceEnabled((bool) $this->cdata);
121 $this->cdata = '';
122 break;
123 }
124 }
125
126 public function handlerCharacterData($xmlParser, $charData): void
127 {
128 if ($charData != "\n") {
129 // Replace multiple tabs with one space
130 $charData = preg_replace("/\t+/", " ", $charData);
131
132 $this->cdata .= $charData;
133 }
134 }
135}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjQuestionPool $poolOBJ, ?string $xmlFile)
handlerBeginTag($xmlParser, $tagName, $tagAttributes)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc