ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilSCORMPackageParser Class Reference

SCORM Package Parser. More...

+ Inheritance diagram for ilSCORMPackageParser:
+ Collaboration diagram for ilSCORMPackageParser:

Public Member Functions

 __construct (object $a_slm_object, string $a_xml_file)
 Constructor. More...
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class More...
 
 startParsing ()
 
 getPackageTitle ()
 
 beginElement (string $a_name)
 update parsing status for a element begin More...
 
 endElement (string $a_name)
 update parsing status for an element ending More...
 
 getCurrentElement ()
 returns current element More...
 
 getAncestorElement (int $nr=1)
 
 buildTag (string $type, string $name, ?array $attr=null)
 generate a tag with given name and attributes More...
 
 getCurrentParent ()
 
 handlerBeginTag (XMLParser $a_xml_parser, string $a_name, array $a_attribs)
 handler for begin of element More...
 
 handlerEndTag (XMLParser $a_xml_parser, string $a_name)
 handler for end of element More...
 
 handlerCharacterData (XMLParser $a_xml_parser, ?string $a_data)
 handler for character data More...
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Data Fields

array $current_element
 
object $slm_object
 
array $parent_stack
 
bool $tree_created
 
object $scorm_tree
 
object $current_organization
 
object $current_resource
 
array $item_stack
 
string $package_title = ""
 
- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Private Attributes

ilSCORMTree $sc_tree
 

Additional Inherited Members

- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Detailed Description

SCORM Package Parser.

Author
Version
$Id$

\

Definition at line 28 of file class.ilSCORMPackageParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilSCORMPackageParser::__construct ( object  $a_slm_object,
string  $a_xml_file 
)

Constructor.

Parameters
object$a_lm_objectmust be of type ilObjLearningModule
string$a_xml_filexml file

Definition at line 47 of file class.ilSCORMPackageParser.php.

48 {
49 parent::__construct($a_xml_file);
50 // $this->cnt = array();
51 $this->current_element = array();
52 $this->slm_object = $a_slm_object;
53 $this->tree_created = false;
54 $this->parent_stack = array();
55 $this->item_stack = array();
56 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ beginElement()

ilSCORMPackageParser::beginElement ( string  $a_name)

update parsing status for a element begin

Definition at line 87 of file class.ilSCORMPackageParser.php.

87 : void
88 {
89 // if (!isset($this->status["$a_name"])) {
90 // $this->cnt[$a_name] == 1;
91 // } else {
92 // $this->cnt[$a_name]++;
93 // }
94 $this->current_element[count($this->current_element)] = $a_name;
95 }

Referenced by handlerBeginTag().

+ Here is the caller graph for this function:

◆ buildTag()

ilSCORMPackageParser::buildTag ( string  $type,
string  $name,
?array  $attr = null 
)

generate a tag with given name and attributes

Definition at line 134 of file class.ilSCORMPackageParser.php.

134 : string
135 {
136 $tag = "<";
137
138 if ($type === "end") {
139 $tag .= "/";
140 }
141
142 $tag .= $name;
143
144 if (is_array($attr)) {
145 foreach ($attr as $k => $v) {
146 $tag .= " " . $k . "=\"$v\"";
147 }
148 }
149
150 $tag .= ">";
151
152 return $tag;
153 }

◆ endElement()

ilSCORMPackageParser::endElement ( string  $a_name)

update parsing status for an element ending

Definition at line 100 of file class.ilSCORMPackageParser.php.

100 : void
101 {
102 // $this->cnt[$a_name]--;
103 unset($this->current_element[count($this->current_element) - 1]);
104 }

Referenced by handlerEndTag().

+ Here is the caller graph for this function:

◆ getAncestorElement()

ilSCORMPackageParser::getAncestorElement ( int  $nr = 1)

Definition at line 114 of file class.ilSCORMPackageParser.php.

114 : ?string
115 {
116 return ($this->current_element[count($this->current_element) - 1 - $nr]);
117 }

Referenced by handlerCharacterData().

+ Here is the caller graph for this function:

◆ getCurrentElement()

ilSCORMPackageParser::getCurrentElement ( )

returns current element

Definition at line 109 of file class.ilSCORMPackageParser.php.

109 : ?string
110 {
111 return ($this->current_element[count($this->current_element) - 1]);
112 }

Referenced by handlerCharacterData().

+ Here is the caller graph for this function:

◆ getCurrentParent()

ilSCORMPackageParser::getCurrentParent ( )

Definition at line 155 of file class.ilSCORMPackageParser.php.

155 : int
156 {
157 return $this->parent_stack[count($this->parent_stack) - 1];
158 }

◆ getPackageTitle()

ilSCORMPackageParser::getPackageTitle ( )

Definition at line 79 of file class.ilSCORMPackageParser.php.

79 : string
80 {
81 return ilUtil::stripSlashes($this->package_title);
82 }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")

References ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ handlerBeginTag()

ilSCORMPackageParser::handlerBeginTag ( XMLParser  $a_xml_parser,
string  $a_name,
array  $a_attribs 
)

handler for begin of element

Parameters
resource | XMLParser$a_xml_parser
string$a_name
array$a_attribs
Returns
void

Definition at line 167 of file class.ilSCORMPackageParser.php.

167 : void
168 {
169 //echo "<br>handlerBeginTag:".$a_name;
170 switch ($a_name) {
171 case "manifest":
172 $mVersion = "";
173 if (isset($a_attribs["version"])) {
174 $mVersion = $a_attribs["version"];
175 }
176 $manifest = new ilSCORMManifest();
177 $manifest->setSLMId($this->slm_object->getId());
178 $manifest->setImportId($a_attribs["identifier"]);
179 $manifest->setVersion($mVersion);
180 if (isset($a_attribs["xml:base"])) {
181 $manifest->setXmlBase($a_attribs["xml:base"]);
182 }
183 $manifest->create();
184 if (!$this->tree_created) {
185 $this->sc_tree = new ilSCORMTree($this->slm_object->getId());
186 $this->sc_tree->addTree($this->slm_object->getId(), $manifest->getId());
187 } else {
188 $this->sc_tree->insertNode($manifest->getId(), $this->getCurrentParent());
189 }
190 $this->parent_stack[] = $manifest->getId();
191 break;
192
193 case "organizations":
194 $organizations = new ilSCORMOrganizations();
195 $organizations->setSLMId($this->slm_object->getId());
196 if (isset($a_attribs["default"])) {
197 $organizations->setDefaultOrganization($a_attribs["default"]);
198 } else {
199 $organizations->setDefaultOrganization("");
200 }
201 $organizations->create();
202 $this->sc_tree->insertNode($organizations->getId(), $this->getCurrentParent());
203 $this->parent_stack[] = $organizations->getId();
204 break;
205
206 case "organization":
207 $organization = new ilSCORMOrganization();
208 $organization->setSLMId($this->slm_object->getId());
209 $organization->setImportId($a_attribs["identifier"]);
210 if (isset($a_attribs["structure"])) {
211 $organization->setStructure($a_attribs["structure"]);
212 }
213 $organization->create();
214 $this->current_organization = &$organization;
215 $this->sc_tree->insertNode($organization->getId(), $this->getCurrentParent());
216 $this->parent_stack[] = $organization->getId();
217 break;
218
219 case "item":
220 $item = new ilSCORMItem();
221 $item->setSLMId($this->slm_object->getId());
222 $item->setImportId($a_attribs["identifier"]);
223 $item->setIdentifierRef((string) $a_attribs["identifierref"]);
224 if (isset($a_attribs["isvisible"])) {
225 if (strtolower((string) $a_attribs["isvisible"]) !== "false") {
226 $item->setVisible(true);
227 } else {
228 $item->setVisible(false);
229 }
230 }
231 if (isset($a_attribs["parameters"])) {
232 $item->setParameters($a_attribs["parameters"]);
233 }
234 $item->create();
235 $this->sc_tree->insertNode($item->getId(), $this->getCurrentParent());
236 $this->parent_stack[] = $item->getId();
237 $this->item_stack[count($this->item_stack)] = &$item;
238 break;
239
240 case "adlcp:prerequisites":
241 $this->item_stack[count($this->item_stack) - 1]->setPrereqType($a_attribs["type"]);
242 break;
243
244 case "resources":
246 $resources->setSLMId($this->slm_object->getId());
247 if (isset($a_attribs["xml:base"])) {
248 $resources->setXmlBase($a_attribs["xml:base"]);
249 }
250 $resources->create();
251 $this->sc_tree->insertNode($resources->getId(), $this->getCurrentParent());
252 $this->parent_stack[] = $resources->getId();
253 break;
254
255 case "resource":
256 $resource = new ilSCORMResource();
257 $resource->setSLMId($this->slm_object->getId());
258 $resource->setImportId($a_attribs["identifier"]);
259 $resource->setResourceType($a_attribs["type"]);
260 if (isset($a_attribs["adlcp:scormtype"])) {
261 $resource->setScormType($a_attribs["adlcp:scormtype"]);
262 }
263 if (isset($a_attribs["xml:base"])) {
264 $resource->setXmlBase($a_attribs["xml:base"]);
265 }
266 if (isset($a_attribs["href"])) {
267 $resource->setHRef($a_attribs["href"]);
268 }
269 $resource->create();
270 $this->current_resource = &$resource;
271 $this->sc_tree->insertNode($resource->getId(), $this->getCurrentParent());
272 $this->parent_stack[] = $resource->getId();
273 break;
274
275 case "file":
276 $file = new ilSCORMResourceFile();
277 $file->setHRef($a_attribs["href"]);
278 $this->current_resource->addFile($file);
279 break;
280
281 case "dependency":
282 $dependency = new ilSCORMResourceDependency();
283 $dependency->setIdentifierRef($a_attribs["identifierref"]);
284 $this->current_resource->addDependency($dependency);
285 break;
286
287 }
288 $this->beginElement($a_name);
289 }
beginElement(string $a_name)
update parsing status for a element begin
SCORM Resource Dependency, DB accesses are done in ilSCORMResource.
SCORM Resource File, DB accesses are done in ilSCORMResource.
SCORM Resources Element.
SCORM Object Tree.
$resources
Definition: ltiservices.php:68

References $resources, and beginElement().

Referenced by setHandlers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handlerCharacterData()

ilSCORMPackageParser::handlerCharacterData ( XMLParser  $a_xml_parser,
?string  $a_data 
)

handler for character data

Parameters
resource | XMLParser$a_xml_parser
string | null$a_data
Returns
void

Definition at line 334 of file class.ilSCORMPackageParser.php.

334 : void
335 {
336 //echo "<br>handlerCharacterData:".$this->getCurrentElement().":".$a_data;
337 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
338 $a_data = preg_replace("/\n/", "", $a_data);
339 $a_data = preg_replace("/\t+/", "", $a_data);
340 if (!empty($a_data)) {
341 switch ($this->getCurrentElement()) {
342 case "title":
343 switch ($this->getAncestorElement(1)) {
344 case "organization":
345 $this->current_organization->setTitle(
346 ilUtil::stripSlashes($this->current_organization->getTitle() . $a_data)
347 );
348 $this->package_title = ilUtil::stripSlashes($this->current_organization->getTitle());
349 break;
350
351 case "item":
352 $this->item_stack[count($this->item_stack) - 1]->setTitle(
353 ilUtil::stripSlashes($this->item_stack[count($this->item_stack) - 1]->getTitle() . $a_data)
354 );
355 break;
356 }
357 break;
358
359 case "adlcp:prerequisites":
360 $this->item_stack[count($this->item_stack) - 1]->setPrerequisites($a_data);
361 break;
362
363 case "adlcp:maxtimeallowed":
364 $this->item_stack[count($this->item_stack) - 1]->setMaxTimeAllowed($a_data);
365 break;
366
367 case "adlcp:timelimitaction":
368 $this->item_stack[count($this->item_stack) - 1]->setTimeLimitAction($a_data);
369 break;
370
371 case "adlcp:datafromlms":
372 $this->item_stack[count($this->item_stack) - 1]->setDataFromLms($a_data);
373 break;
374
375 case "adlcp:masteryscore":
376 $this->item_stack[count($this->item_stack) - 1]->setMasteryScore($a_data);
377 break;
378
379 }
380 }
381 }
getCurrentElement()
returns current element

References getAncestorElement(), getCurrentElement(), ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), and ilUtil\stripSlashes().

Referenced by setHandlers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handlerEndTag()

ilSCORMPackageParser::handlerEndTag ( XMLParser  $a_xml_parser,
string  $a_name 
)

handler for end of element

Parameters
resource | XMLParser$a_xml_parser
string$a_name
Returns
void

Definition at line 297 of file class.ilSCORMPackageParser.php.

297 : void
298 {
299 //echo "<br>handlerEndTag:".$a_name;
300
301 switch ($a_name) {
302 case "manifest":
303 case "organizations":
304 case "resources":
305 array_pop($this->parent_stack);
306 break;
307
308 case "organization":
309 $this->current_organization->update();
310 array_pop($this->parent_stack);
311 break;
312
313 case "item":
314 $this->item_stack[count($this->item_stack) - 1]->update();
315 unset($this->item_stack[count($this->item_stack) - 1]);
316 array_pop($this->parent_stack);
317 break;
318
319 case "resource":
320 $this->current_resource->update();
321 array_pop($this->parent_stack);
322 break;
323
324 }
325 $this->endElement($a_name);
326 }
endElement(string $a_name)
update parsing status for an element ending

References endElement().

Referenced by setHandlers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilSCORMPackageParser::setHandlers (   $a_xml_parser)

set event handler should be overwritten by inherited class

Parameters
resource | XMLParser$a_xml_parser
Returns
void

Reimplemented from ilSaxParser.

Definition at line 65 of file class.ilSCORMPackageParser.php.

65 : void
66 {
67 xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
68 xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
69 }
handlerCharacterData(XMLParser $a_xml_parser, ?string $a_data)
handler for character data
handlerBeginTag(XMLParser $a_xml_parser, string $a_name, array $a_attribs)
handler for begin of element
handlerEndTag(XMLParser $a_xml_parser, string $a_name)
handler for end of element

References handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

+ Here is the call graph for this function:

◆ startParsing()

ilSCORMPackageParser::startParsing ( )
Exceptions
ilSaxParserException

Reimplemented from ilSaxParser.

Definition at line 74 of file class.ilSCORMPackageParser.php.

74 : void
75 {
76 parent::startParsing();
77 }

Field Documentation

◆ $current_element

array ilSCORMPackageParser::$current_element

Definition at line 32 of file class.ilSCORMPackageParser.php.

◆ $current_organization

object ilSCORMPackageParser::$current_organization

Definition at line 37 of file class.ilSCORMPackageParser.php.

◆ $current_resource

object ilSCORMPackageParser::$current_resource

Definition at line 38 of file class.ilSCORMPackageParser.php.

◆ $item_stack

array ilSCORMPackageParser::$item_stack

Definition at line 39 of file class.ilSCORMPackageParser.php.

◆ $package_title

string ilSCORMPackageParser::$package_title = ""

Definition at line 40 of file class.ilSCORMPackageParser.php.

◆ $parent_stack

array ilSCORMPackageParser::$parent_stack

Definition at line 34 of file class.ilSCORMPackageParser.php.

◆ $sc_tree

ilSCORMTree ilSCORMPackageParser::$sc_tree
private

Definition at line 30 of file class.ilSCORMPackageParser.php.

◆ $scorm_tree

object ilSCORMPackageParser::$scorm_tree

Definition at line 36 of file class.ilSCORMPackageParser.php.

◆ $slm_object

object ilSCORMPackageParser::$slm_object

Definition at line 33 of file class.ilSCORMPackageParser.php.

◆ $tree_created

bool ilSCORMPackageParser::$tree_created

Definition at line 35 of file class.ilSCORMPackageParser.php.


The documentation for this class was generated from the following file: