ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilLearningSequenceXMLParser.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use 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 if (isset($attributes["position"])) {
108 $this->ls_item_data[$this->counter]["position"] = $attributes["position"];
109 }
110 break;
111
112 case Writer::TAG_CONDITION:
113 $this->ls_item_data[$this->counter]["condition_type"] = $attributes["type"];
114 $this->ls_item_data[$this->counter]["condition_value"] = '';
115 break;
116
117 case Writer::TAG_CONTAINERSETTING:
118 $this->current_container_setting = $attributes['id'];
119 break;
120
121 default:
122 break;
123 }
124 }
125
126 public function handleEndTag($parser, string $name): void
127 {
128 $this->cdata = trim($this->cdata);
129
130 switch ($name) {
131 case Writer::TAG_LPREFID:
132 $this->lp_settings["lp_item_ref_ids"][] = trim($this->cdata);
133 break;
134 case Writer::TAG_CONTAINERSETTING:
135 if ($this->current_container_setting) {
137 $this->obj->getId(),
138 $this->current_container_setting,
139 trim($this->cdata)
140 );
141 }
142 break;
143
144 case Writer::TAG_TITLE:
145 $this->obj->setTitle(trim($this->cdata));
146 break;
147
148 case Writer::TAG_DESCRIPTION:
149 $this->obj->setDescription(trim($this->cdata));
150 break;
151
152 default:
153 break;
154 }
155
156 $this->cdata = '';
157 }
158
159 public function handleCharacterData($parser, $data): void
160 {
161 $this->cdata .= ($data ?? "");
162 }
163}
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
handleBeginTag( $parser, string $name, array $attributes)
__construct(protected ilObjLearningSequence $obj, string $xml)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setXMLContent(string $a_xml_content)
startParsing()
stores xml data in array
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc