ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLearningSequenceXMLParser.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
24  protected bool $storing = false;
25 
29  protected array $object = [];
30 
34  protected array $ls_item_data = [];
35 
39  protected array $settings = [];
40 
41  protected array $lp_settings = [];
42  protected int $counter = 0;
43  protected string $actual_name;
44  protected string $cdata = '';
45 
46  public function __construct(ilObjLearningSequence $obj, string $xml)
47  {
49 
50  $this->obj = $obj;
51  $this->setXMLContent($xml);
52  $this->lp_settings["lp_item_ref_ids"] = [];
53  }
54 
58  public function start(): array
59  {
60  $this->startParsing();
61 
62  $ret = array();
63  $ret["object"] = $this->object;
64  $ret["item_data"] = $this->ls_item_data;
65  $ret["settings"] = $this->settings;
66  $ret["lp_settings"] = $this->lp_settings;
67 
68  return $ret;
69  }
70 
71  public function setHandlers($a_xml_parser): void
72  {
73  xml_set_object($a_xml_parser, $this);
74  xml_set_element_handler($a_xml_parser, "handleBeginTag", "handleEndTag");
75  xml_set_character_data_handler($a_xml_parser, 'handleCharacterData');
76  }
77 
78  public function handleBeginTag(
79  $parser,
80  string $name,
81  array $attributes
82  ): void {
83  $this->actual_name = $name;
84 
85  switch ($name) {
86  case "lso":
87  $this->object["ref_id"] = $attributes["ref_id"];
88  break;
89  case "ls_item":
90  $this->ls_item_data[$this->counter]["id"] = $attributes["id"];
91  $this->beginStoreCData();
92  break;
93  default:
94  break;
95  }
96  }
97 
98  public function handleEndTag($parser, string $name): void
99  {
100  $this->cdata = trim($this->cdata);
101 
102  switch ($name) {
103  case "title":
104  $this->obj->setTitle(trim($this->cdata));
105  break;
106  case "description":
107  $this->obj->setDescription(trim($this->cdata));
108  break;
109  case "ls_item":
110  $this->endStoreCData();
111  break;
112  case "ls_item_order_number":
113  $this->counter++;
114  break;
115  case "abstract":
116  $this->settings["abstract"] = base64_decode(trim($this->cdata));
117  break;
118  case "extro":
119  $this->settings["extro"] = base64_decode(trim($this->cdata));
120  break;
121  case "abstract_img":
122  $this->settings["abstract_img"] = trim($this->cdata);
123  break;
124  case "extro_img":
125  $this->settings["extro_img"] = trim($this->cdata);
126  break;
127  case "abstract_img_data":
128  $this->settings["abstract_img_data"] = trim($this->cdata);
129  break;
130  case "extro_img_data":
131  $this->settings["extro_img_data"] = trim($this->cdata);
132  break;
133  case "members_gallery":
134  $this->settings["members_gallery"] = trim($this->cdata);
135  break;
136  case "lp_item_ref_id":
137  $this->lp_settings["lp_item_ref_ids"][] = trim($this->cdata);
138  break;
139  case "lp_type":
140  $this->lp_settings["lp_type"] = trim($this->cdata);
141  break;
142  case "lp_mode":
143  $this->lp_settings["lp_mode"] = trim($this->cdata);
144  break;
145  default:
146  break;
147  }
148 
149  $this->cdata = '';
150  }
151 
152  public function handleCharacterData($parser, $data): void
153  {
154  $this->cdata .= ($data ?? "");
155  $this->storeData();
156  }
157 
158  protected function beginStoreCData(): void
159  {
160  $this->storing = true;
161  }
162 
163  protected function endStoreCData(): void
164  {
165  $this->storing = false;
166  }
167 
168  protected function storeData(): void
169  {
170  if ($this->storing) {
171  $this->ls_item_data[$this->counter][$this->actual_name] = $this->cdata;
172  }
173  }
174 }
$attributes
Definition: metadata.php:248
startParsing()
stores xml data in array
__construct(ilObjLearningSequence $obj, string $xml)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($format !==null) $name
Definition: metadata.php:247
$xml
Definition: metadata.php:351
handleBeginTag( $parser, string $name, array $attributes)
__construct(Container $dic, ilPlugin $plugin)
setXMLContent(string $a_xml_content)