You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
5.2 KiB
135 lines
5.2 KiB
|
15 years ago
|
<?php
|
||
|
|
/* For licensing terms, see /license.txt */
|
||
|
15 years ago
|
|
||
|
16 years ago
|
/**
|
||
|
8 years ago
|
* Container for the scormResource class.
|
||
|
|
*
|
||
|
16 years ago
|
* @author Yannick Warnier <ywarnier@beeznest.org>
|
||
|
|
*/
|
||
|
15 years ago
|
|
||
|
16 years ago
|
/**
|
||
|
8 years ago
|
* Class defining the <resource> tag in an imsmanifest.xml file.
|
||
|
16 years ago
|
*/
|
||
|
11 years ago
|
class scormResource
|
||
|
|
{
|
||
|
15 years ago
|
public $identifier = '';
|
||
|
|
public $type = 'webcontent';
|
||
|
|
//public $identifierref = '';
|
||
|
|
public $scormtype = 'sco'; // Fix problems with ENI content where asset is not defined.
|
||
|
|
public $base = '';
|
||
|
|
public $href = '';
|
||
|
|
public $metadata;
|
||
|
|
//public $file_href;
|
||
|
|
//public $file_metadata;
|
||
|
8 years ago
|
public $files = [];
|
||
|
|
public $dependencies = [];
|
||
|
16 years ago
|
|
||
|
15 years ago
|
/**
|
||
|
|
* Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
|
||
|
8 years ago
|
* object from database records or from the DOM element given as parameter.
|
||
|
|
*
|
||
|
8 years ago
|
* @param string Type of construction needed ('db' or 'manifest', default = 'manifest')
|
||
|
|
* @param mixed Depending on the type given, DB id for the lp_item or reference to the DOM element
|
||
|
15 years ago
|
*/
|
||
|
11 years ago
|
public function __construct($type = 'manifest', &$element)
|
||
|
|
{
|
||
|
15 years ago
|
if (isset($element)) {
|
||
|
|
// Parsing using PHP5 DOMXML methods.
|
||
|
|
switch ($type) {
|
||
|
|
case 'db':
|
||
|
|
// TODO: Implement this way of metadata object creation.
|
||
|
|
return false;
|
||
|
|
case 'manifest': // Do the same as the default.
|
||
|
|
default:
|
||
|
|
//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
|
||
|
|
$children = $element->childNodes;
|
||
|
|
if (is_array($children)) {
|
||
|
|
foreach ($children as $child) {
|
||
|
|
switch ($child->nodeType) {
|
||
|
|
case XML_ELEMENT_NODE:
|
||
|
|
switch ($child->tagName) {
|
||
|
|
case 'file':
|
||
|
|
//echo "Child is a file tag<br />\n";
|
||
|
|
$this->files[] = $child->getAttribute('href');
|
||
|
|
break;
|
||
|
|
case 'metadata':
|
||
|
|
//echo "Child is a metadata tag<br />\n";
|
||
|
|
$this->metadata = new scormMetadata('manifest', $child);
|
||
|
|
break;
|
||
|
|
case 'dependency':
|
||
|
|
// Need to get identifierref attribute inside dependency node.
|
||
|
|
// dependencies[] array represents all <dependency identifierref='x'> tags united.
|
||
|
|
$this->dependencies[] = $child->getAttribute('identifierref');
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//$keep_href = '';
|
||
|
9 years ago
|
if ($element->hasAttributes()) { //in some cases we get here with an empty attributes array
|
||
|
11 years ago
|
// TODO: Find when and why we get such a case (empty array).
|
||
|
15 years ago
|
$attributes = $element->attributes;
|
||
|
|
foreach ($attributes as $attrib) {
|
||
|
|
switch ($attrib->name) {
|
||
|
|
case 'identifier':
|
||
|
|
$this->identifier = $attrib->value;
|
||
|
|
break;
|
||
|
|
case 'type':
|
||
|
|
if (!empty($attrib->value)) {
|
||
|
|
$this->type = $attrib->value;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case 'scormtype':
|
||
|
|
if (!empty($attrib->value)) {
|
||
|
|
$this->scormtype = $attrib->value;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case 'base':
|
||
|
|
$this->base = $attrib->value;
|
||
|
|
break;
|
||
|
|
case 'href':
|
||
|
|
$this->href = $attrib->value;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
8 years ago
|
|
||
|
15 years ago
|
return true;
|
||
|
|
}
|
||
|
15 years ago
|
|
||
|
15 years ago
|
// End parsing using PHP5 DOMXML methods.
|
||
|
|
}
|
||
|
11 years ago
|
|
||
|
15 years ago
|
return false;
|
||
|
|
}
|
||
|
15 years ago
|
|
||
|
15 years ago
|
/**
|
||
|
8 years ago
|
* Path getter.
|
||
|
|
*
|
||
|
|
* @return string Path for this resource
|
||
|
15 years ago
|
*/
|
||
|
11 years ago
|
public function get_path()
|
||
|
|
{
|
||
|
11 years ago
|
if (!empty($this->href)) {
|
||
|
13 years ago
|
return Database::escape_string($this->href);
|
||
|
15 years ago
|
} else {
|
||
|
|
return '';
|
||
|
|
}
|
||
|
|
}
|
||
|
15 years ago
|
|
||
|
15 years ago
|
/**
|
||
|
8 years ago
|
* Scorm type getter.
|
||
|
|
*
|
||
|
|
* @return string generally 'asset' or 'sco' as these are the only two values defined in SCORM 1.2
|
||
|
15 years ago
|
*/
|
||
|
11 years ago
|
public function get_scorm_type()
|
||
|
|
{
|
||
|
11 years ago
|
if (!empty($this->scormtype)) {
|
||
|
13 years ago
|
return Database::escape_string($this->scormtype);
|
||
|
15 years ago
|
} else {
|
||
|
|
return '';
|
||
|
|
}
|
||
|
|
}
|
||
|
15 years ago
|
}
|