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