ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
55  xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
56  }
57 
58  public function handlerBeginTag($xmlParser, $tagName, $tagAttributes): void
59  {
60  switch ($tagName) {
61  case 'MetaData':
62  $this->inMetaDataTag = true;
63  break;
64 
65  case 'General':
66  if ($this->inMetaDataTag) {
67  $this->inMdGeneralTag = true;
68  }
69  break;
70 
71  case 'Title':
72  case 'Description':
73  $this->cdata = '';
74  break;
75 
76  case 'Settings':
77  $this->inSettingsTag = true;
78  break;
79 
80  case 'NavTaxonomy':
81  case 'SkillService':
82  if ($this->inSettingsTag) {
83  $this->cdata = '';
84  }
85  break;
86  }
87  }
88 
89  public function handlerEndTag($xmlParser, $tagName): void
90  {
91  switch ($tagName) {
92  case 'MetaData':
93  $this->inMetaDataTag = false;
94  break;
95 
96  case 'General':
97  if ($this->inMetaDataTag) {
98  $this->inMdGeneralTag = false;
99  }
100  break;
101 
102  case 'Title':
103  if (!$this->title_processed) {
104  $this->poolOBJ->setTitle($this->cdata);
105  $this->title_processed = true;
106  $this->cdata = '';
107  }
108  break;
109 
110  case 'Description':
111  if (!$this->description_processed) {
112  $this->poolOBJ->setDescription($this->cdata);
113  $this->description_processed = true;
114  $this->cdata = '';
115  }
116  break;
117 
118  case 'Settings':
119  $this->inSettingsTag = false;
120  break;
121 
122  case 'SkillService':
123  $this->poolOBJ->setSkillServiceEnabled((bool) $this->cdata);
124  $this->cdata = '';
125  break;
126  }
127  }
128 
129  public function handlerCharacterData($xmlParser, $charData): void
130  {
131  if ($charData != "\n") {
132  // Replace multiple tabs with one space
133  $charData = preg_replace("/\t+/", " ", $charData);
134 
135  $this->cdata .= $charData;
136  }
137  }
138 }
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)