ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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_element_handler($a_xml_parser, $this->handleBeginTag(...), $this->handleEndTag(...));
83  xml_set_character_data_handler($a_xml_parser, $this->handleCharacterData(...));
84  }
85 
86  public function handleBeginTag(
87  $parser,
88  string $name,
89  array $attributes
90  ): void {
91  $this->actual_name = $name;
92 
93  switch ($name) {
94  case Writer::TAG_LSO:
95  $this->object["ref_id"] = $attributes["ref_id"];
96  $this->settings["members_gallery"] = $attributes['members_gallery'];
97  break;
98  case Writer::TAG_LPSETTING:
99  $this->lp_settings["lp_type"] = $attributes['type'];
100  $this->lp_settings["lp_mode"] = $attributes['mode'];
101  $this->lp_settings["lp_item_ref_ids"] = [];
102  break;
103 
104  case Writer::TAG_LSITEM:
105  $this->counter = (int) $attributes["ref_id"];
106  $this->ls_item_data[$this->counter]["ref_id"] = $attributes["ref_id"];
107  break;
108 
109  case Writer::TAG_CONDITION:
110  $this->ls_item_data[$this->counter]["condition_type"] = $attributes["type"];
111  $this->ls_item_data[$this->counter]["condition_value"] = '';
112  break;
113 
114  case Writer::TAG_CONTAINERSETTING:
115  $this->current_container_setting = $attributes['id'];
116  break;
117 
118  default:
119  break;
120  }
121  }
122 
123  public function handleEndTag($parser, string $name): void
124  {
125  $this->cdata = trim($this->cdata);
126 
127  switch ($name) {
128  case Writer::TAG_LPREFID:
129  $this->lp_settings["lp_item_ref_ids"][] = trim($this->cdata);
130  break;
131  case Writer::TAG_CONTAINERSETTING:
132  if ($this->current_container_setting) {
134  $this->obj->getId(),
136  trim($this->cdata)
137  );
138  }
139  break;
140 
141  case Writer::TAG_TITLE:
142  $this->obj->setTitle(trim($this->cdata));
143  break;
144 
145  case Writer::TAG_DESCRIPTION:
146  $this->obj->setDescription(trim($this->cdata));
147  break;
148 
149  default:
150  break;
151  }
152 
153  $this->cdata = '';
154  }
155 
156  public function handleCharacterData($parser, $data): void
157  {
158  $this->cdata .= ($data ?? "");
159  }
160 }
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(protected ilObjLearningSequence $obj, string $xml)
handleBeginTag( $parser, string $name, array $attributes)
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
__construct(Container $dic, ilPlugin $plugin)
setXMLContent(string $a_xml_content)