ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
21 private $cdata = '';
22
23 public function __construct(ilObjLearningSequence $obj, string $xml)
24 {
26
27 $this->obj = $obj;
28 $this->storing = false;
29 $this->setXMLContent($xml);
30
31 $this->object = array();
32 $this->ls_item_data = array();
33 $this->settings = array();
34 $this->lp_settings = array();
35 $this->lp_settings["lp_item_ref_ids"] = array();
36 $this->counter = 0;
37 }
38
39 public function start() : array
40 {
41 $this->startParsing();
42
43 $ret = array();
44 $ret["object"] = $this->object;
45 $ret["item_data"] = $this->ls_item_data;
46 $ret["settings"] = $this->settings;
47 $ret["lp_settings"] = $this->lp_settings;
48
49 return $ret;
50 }
51
52 public function setHandlers($parser)
53 {
54 xml_set_object($parser, $this);
55 xml_set_element_handler($parser, "handleBeginTag", "handleEndTag");
56 xml_set_character_data_handler($parser, 'handleCharacterData');
57 }
58
59 public function handleBeginTag(
60 $parser,
61 string $name,
62 array $attributes
63 ) {
64 $this->actual_name = $name;
65
66 switch ($name) {
67 case "lso":
68 $this->object["ref_id"] = $attributes["ref_id"];
69 break;
70 case "ls_item":
71 $this->ls_item_data[$this->counter]["id"] = $attributes["id"];
72 $this->beginStoreCData();
73 break;
74 default:
75 break;
76 }
77 }
78
79 public function handleEndTag($parser, string $name)
80 {
81 $this->cdata = trim($this->cdata);
82
83 switch ($name) {
84 case "title":
85 $this->obj->setTitle(trim($this->cdata));
86 break;
87 case "description":
88 $this->obj->setDescription(trim($this->cdata));
89 break;
90 case "ls_item":
91 $this->endStoreCData();
92 break;
93 case "ls_item_order_number":
94 $this->counter++;
95 break;
96 case "abstract":
97 $this->settings["abstract"] = base64_decode(trim($this->cdata));
98 break;
99 case "extro":
100 $this->settings["extro"] = base64_decode(trim($this->cdata));
101 break;
102 case "abstract_img":
103 $this->settings["abstract_img"] = trim($this->cdata);
104 break;
105 case "extro_img":
106 $this->settings["extro_img"] = trim($this->cdata);
107 break;
108 case "abstract_img_data":
109 $this->settings["abstract_img_data"] = trim($this->cdata);
110 break;
111 case "extro_img_data":
112 $this->settings["extro_img_data"] = trim($this->cdata);
113 break;
114 case "members_gallery":
115 $this->settings["members_gallery"] = trim($this->cdata);
116 break;
117 case "lp_item_ref_id":
118 $this->lp_settings["lp_item_ref_ids"][] = trim($this->cdata);
119 break;
120 case "lp_type":
121 $this->lp_settings["lp_type"] = trim($this->cdata);
122 break;
123 case "lp_mode":
124 $this->lp_settings["lp_mode"] = trim($this->cdata);
125 break;
126 default:
127 break;
128 }
129
130 $this->cdata = '';
131 }
132
134 {
135 $this->cdata .= ($data ?? "");
136 $this->storeData();
137 }
138
139 protected function beginStoreCData()
140 {
141 $this->storing = true;
142 }
143
144 protected function endStoreCData()
145 {
146 $this->storing = false;
147 }
148
149 protected function storeData()
150 {
151 if ($this->storing) {
152 $this->ls_item_data[$this->counter][$this->actual_name] = $this->cdata ?? "";
153 }
154 }
155}
$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($format !==null) $name
Definition: metadata.php:230
$attributes
Definition: metadata.php:231
$xml
Definition: metadata.php:332
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
settings()
Definition: settings.php:2
$data
Definition: storeScorm.php:23