ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLearningSequenceXMLParser.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
9{
13 protected $storing;
14
18 protected $counter;
19
20 public function __construct(ilObjLearningSequence $obj, string $xml)
21 {
22 parent::__construct();
23
24 $this->obj = $obj;
25 $this->storing = false;
26 $this->setXMLContent($xml);
27
28 $this->object = array();
29 $this->ls_item_data = array();
30 $this->settings = array();
31 $this->lp_settings = array();
32 $this->lp_settings["lp_item_ref_ids"] = array();
33 $this->counter = 0;
34 }
35
36 public function start() : array
37 {
38 $this->startParsing();
39
40 $ret = array();
41 $ret["object"] = $this->object;
42 $ret["item_data"] = $this->ls_item_data;
43 $ret["settings"] = $this->settings;
44 $ret["lp_settings"] = $this->lp_settings;
45
46 return $ret;
47 }
48
49 public function setHandlers($parser)
50 {
51 xml_set_object($parser, $this);
52 xml_set_element_handler($parser, "handleBeginTag", "handleEndTag");
53 xml_set_character_data_handler($parser, 'handleCharacterData');
54 }
55
56 public function handleBeginTag(
57 $parser,
58 string $name,
59 array $attributes
60 ) {
61 $this->actual_name = $name;
62
63 switch ($name) {
64 case "lso":
65 $this->object["ref_id"] = $attributes["ref_id"];
66 break;
67 case "ls_item":
68 $this->ls_item_data[$this->counter]["id"] = $attributes["id"];
69 $this->beginStoreCData();
70 break;
71 default:
72 break;
73 }
74 }
75
76 public function handleEndTag($parser, string $name)
77 {
78 switch ($name) {
79 case "title":
80 $this->obj->setTitle(trim($this->cdata));
81 break;
82 case "description":
83 $this->obj->setDescription(trim($this->cdata));
84 break;
85 case "ls_item":
86 $this->endStoreCData();
87 break;
88 case "ls_item_order_number":
89 $this->counter++;
90 break;
91 case "abstract":
92 $this->settings["abstract"] = base64_decode(trim($this->cdata));
93 break;
94 case "extro":
95 $this->settings["extro"] = base64_decode(trim($this->cdata));
96 break;
97 case "abstract_img":
98 $this->settings["abstract_img"] = trim($this->cdata);
99 break;
100 case "extro_img":
101 $this->settings["extro_img"] = trim($this->cdata);
102 break;
103 case "abstract_img_data":
104 $this->settings["abstract_img_data"] = trim($this->cdata);
105 break;
106 case "extro_img_data":
107 $this->settings["extro_img_data"] = trim($this->cdata);
108 break;
109 case "members_gallery":
110 $this->settings["members_gallery"] = trim($this->cdata);
111 break;
112 case "lp_item_ref_id":
113 $this->lp_settings["lp_item_ref_ids"][] = trim($this->cdata);
114 break;
115 case "lp_type":
116 $this->lp_settings["lp_type"] = trim($this->cdata);
117 break;
118 case "lp_mode":
119 $this->lp_settings["lp_mode"] = trim($this->cdata);
120 break;
121 default:
122 break;
123 }
124 }
125
127 {
128 $this->cdata = $data ?? "";
129 $this->storeData();
130 }
131
132 protected function beginStoreCData()
133 {
134 $this->storing = true;
135 }
136
137 protected function endStoreCData()
138 {
139 $this->storing = false;
140 }
141
142 protected function storeData()
143 {
144 if ($this->storing) {
145 $this->ls_item_data[$this->counter][$this->actual_name] = $this->cdata ?? "";
146 }
147 }
148}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
setHandlers($parser)
set event handler should be overwritten by inherited class @access private
__construct(ilObjLearningSequence $obj, string $xml)
handleBeginTag( $parser, string $name, array $attributes)
Class ilObjLearningSequence.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setXMLContent($a_xml_content)
startParsing()
stores xml data in array
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$ret
Definition: parser.php:6
settings()
Definition: settings.php:2
$data
Definition: bench.php:6