ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilLearningSequenceXMLParser.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ilLearningSequenceXMLWriter as Writer;
22 
24 {
28  protected array $object;
29 
33  protected array $ls_item_data;
34 
38  protected array $settings;
39 
43  protected array $lp_settings;
44  protected int $counter;
45  protected string $actual_name;
46  protected string $cdata = '';
47  protected string $current_container_setting = '';
48 
49  public function __construct(
50  protected ilObjLearningSequence $obj,
51  string $xml
52  ) {
54 
55  $this->setXMLContent($xml);
56 
57  $this->object = [];
58  $this->ls_item_data = [];
59  $this->settings = [];
60  $this->lp_settings = [];
61  $this->lp_settings["lp_item_ref_ids"] = [];
62  $this->counter = 0;
63  }
64 
68  public function start(): array
69  {
70  $this->startParsing();
71  $ret = [];
72  $ret["object"] = $this->object;
73  $ret["item_data"] = $this->ls_item_data;
74  $ret["settings"] = $this->settings;
75  $ret["lp_settings"] = $this->lp_settings;
76 
77  return $ret;
78  }
79 
80  public function setHandlers($a_xml_parser): void
81  {
82  xml_set_object($a_xml_parser, $this);
83  xml_set_element_handler($a_xml_parser, "handleBeginTag", "handleEndTag");
84  xml_set_character_data_handler($a_xml_parser, 'handleCharacterData');
85  }
86 
87  public function handleBeginTag(
88  $parser,
89  string $name,
90  array $attributes
91  ): void {
92  $this->actual_name = $name;
93 
94  switch ($name) {
95  case Writer::TAG_LSO:
96  $this->object["ref_id"] = $attributes["ref_id"];
97  $this->settings["members_gallery"] = $attributes['members_gallery'];
98  break;
99  case Writer::TAG_LPSETTING:
100  $this->lp_settings["lp_type"] = $attributes['type'];
101  $this->lp_settings["lp_mode"] = $attributes['mode'];
102  $this->lp_settings["lp_item_ref_ids"] = [];
103  break;
104 
105  case Writer::TAG_LSITEM:
106  $this->counter = (int)$attributes["ref_id"];
107  $this->ls_item_data[$this->counter]["ref_id"] = $attributes["ref_id"];
108  break;
109 
110  case Writer::TAG_CONDITION:
111  $this->ls_item_data[$this->counter]["condition_type"] = $attributes["type"];
112  $this->ls_item_data[$this->counter]["condition_value"] = '';
113  break;
114 
115  case Writer::TAG_CONTAINERSETTING:
116  $this->current_container_setting = $attributes['id'];
117  break;
118 
119  default:
120  break;
121  }
122  }
123 
124  public function handleEndTag($parser, string $name): void
125  {
126  $this->cdata = trim($this->cdata);
127 
128  switch ($name) {
129  case Writer::TAG_LPREFID:
130  $this->lp_settings["lp_item_ref_ids"][] = trim($this->cdata);
131  break;
132  case Writer::TAG_CONTAINERSETTING:
133  if ($this->current_container_setting) {
135  $this->obj->getId(),
137  trim($this->cdata)
138  );
139  }
140  break;
141 
142  case Writer::TAG_TITLE:
143  $this->obj->setTitle(trim($this->cdata));
144  break;
145 
146  case Writer::TAG_DESCRIPTION:
147  $this->obj->setDescription(trim($this->cdata));
148  break;
149 
150  default:
151  break;
152  }
153 
154  $this->cdata = '';
155  }
156 
157  public function handleCharacterData($parser, $data): void
158  {
159  $this->cdata .= ($data ?? "");
160  }
161 }
startParsing()
stores xml data in array
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(VocabulariesInterface $vocabularies)
__construct(protected ilObjLearningSequence $obj, string $xml)
handleBeginTag( $parser, string $name, array $attributes)
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
setXMLContent(string $a_xml_content)