Collaboration diagram for ilSCORM13Package:Public Member Functions | |
| __construct ($packageId=null) | |
| load ($packageId) | |
| rollback () | |
| exportZIP () | |
| exportXML () | |
| Export as internal XML. | |
| removeCMIData () | |
| il_import ($packageFolder, $packageId, $ilias, $validate) | |
| Imports an extracted SCORM 2004 module from ilias-data dir into database. | |
| jsonNode ($node, &$sink) | |
| Helper for UploadAndImport Recursively copies values from XML into PHP array for export as json Elements are translated into sub array, attributes into literals. | |
| dbImport ($node, &$lft=1, $depth=1, $parent=0) | |
| dbAddNew () | |
| add new sahs and package record | |
| dbRemoveAll () | |
| transform ($inputdoc, $xslfile, $outputpath=null) | |
| validate ($doc, $schema) | |
Data Fields | |
| const | DB_ENCODE_XSL = './Modules/Scorm2004/templates/xsl/op/op-scorm13.xsl' |
| const | CONVERT_XSL = './Modules/Scorm2004/templates/xsl/op/scorm12To2004.xsl' |
| const | DB_DECODE_XSL = './Modules/Scorm2004/templates/xsl/op/op-scorm13-revert.xsl' |
| const | VALIDATE_XSD = './Modules/Scorm2004/templates/xsd/op/op-scorm13.xsd' |
| const | WRAPPER_HTML = './Modules/Scorm2004/scripts/converter/GenericRunTimeWrapper1.0_aadlc/GenericRunTimeWrapper.htm' |
| const | WRAPPER_JS = './Modules/Scorm2004/scripts/converter/GenericRunTimeWrapper1.0_aadlc/SCOPlayerWrapper.js' |
| $imsmanifest | |
| $manifest | |
| $diagnostic | |
| $status | |
| $packageId | |
| $packageName | |
| $packageHash | |
| $userId | |
Private Member Functions | |
| setProgress ($progress, $msg= '') | |
Private Attributes | |
| $packageFile | |
| $packageFolder | |
| $packagesFolder | |
| $packageData | |
| $idmap = array() | |
| $progress = 0.0 | |
Static Private Attributes | |
| static | $elements |
Definition at line 34 of file ilSCORM13Package.php.
| ilSCORM13Package::__construct | ( | $ | packageId = null |
) |
Definition at line 88 of file ilSCORM13Package.php.
References $GLOBALS, $packageId, and load().
{
$this->packagesFolder = IL_OP_PACKAGES_FOLDER;
$this->load($packageId);
$this->userId = $GLOBALS['USER']['usr_id'];
}
Here is the call graph for this function:| ilSCORM13Package::dbAddNew | ( | ) |
add new sahs and package record
Definition at line 437 of file ilSCORM13Package.php.
References $x.
{
global $ilDB;
//$this->packageId = 100;
//return true;
//ilSCORM13DB::getRecord('sahs_lm', array());
// $this->packageId = ilSCORM13DB::getRecord('sahs_lm', array());
/* ilSCORM13DB::setRecord('cp_package', array(
'obj_id' => $this->packageId,
'xmldata' => $x->asXML(),
'jsdata' => json_encode($j),
), 'obj_id');
*/
$ilDB->query("INSERT INTO cp_package ".
"(obj_id, xmldata, jsdata) VALUES ".
"(".
$ilDB->quote($this->packageId).",".
$ilDB->quote($x->asXML()).",".
$ilDB->quote(json_encode($j)).")");
return true;
}
| ilSCORM13Package::dbImport | ( | $ | node, | |
| &$ | lft = 1, |
|||
| $ | depth = 1, |
|||
| $ | parent = 0 | |||
| ) |
Definition at line 332 of file ilSCORM13Package.php.
Referenced by il_import().
{
global $ilDB;
switch ($node->nodeType)
{
case XML_DOCUMENT_NODE:
// insert into cp_package
/*ilSCORM13DB::setRecord('cp_package', array(
'obj_id' => $this->packageId,
'identifier' => $this->packageName,
'persistPreviousAttempts' => 0,
'settings' => '',
));*/
$ilDB->query("INSERT INTO cp_package ".
"(obj_id, identifier, persistPreviousAttempts, settings) VALUES ".
"(".$ilDB->quote($this->packageId).",".
$ilDB->quote($this->packageName).",".
$ilDB->quote(0).",".
$ilDB->quote("").
")");
// run sub nodes
$this->dbImport($node->documentElement); // RECURSION
break;
case XML_ELEMENT_NODE:
if ($node->nodeName==='manifest')
{
if ($node->getAttribute('uri')=="")
{
// default URI is md5 hash of zip file, i.e. packageHash
$node->setAttribute('uri', 'md5:' . $this->packageHash);
}
}
// insert into cp_node
/*$cp_node_id = ilSCORM13DB::setRecord('cp_node', array(
'slm_id' => $this->packageId,
'nodeName' => $node->nodeName,
), 'cp_node_id');*/
$ilDB->query("INSERT INTO cp_node ".
"(slm_id, nodeName) VALUES ".
"(".$ilDB->quote($this->packageId).",".
$ilDB->quote($node->nodeName).
")");
$cp_node_id = $ilDB->getLastInsertId();
// insert into cp_tree
/*
ilSCORM13DB::setRecord('cp_tree', array(
'child' => $cp_node_id,
'depth' => $depth,
'lft' => $lft++,
'obj_id' => $this->packageId,
'parent' => $parent,
'rgt' => 0,
));*/
$ilDB->query("INSERT INTO cp_tree ".
"(child, depth, lft, obj_id, parent, rgt) VALUES ".
"(".
$ilDB->quote($cp_node_id).",".
$ilDB->quote($depth).",".
$ilDB->quote($lft++).",".
$ilDB->quote($this->packageId).",".
$ilDB->quote($parent).",".
$ilDB->quote(0).
")");
// insert into cp_*
//$a = array('cp_node_id' => $cp_node_id);
$names = array('cp_node_id');
$values = array($ilDB->quote($cp_node_id));
foreach ($node->attributes as $attr)
{
//$a[$attr->name] = $attr->value;
$names[] = "`".$attr->name."`";
$values[] = $ilDB->quote($attr->value);
}
//ilSCORM13DB::setRecord('cp_' . $node->nodeName, $a);
$ilDB->query("INSERT INTO cp_".strtolower($node->nodeName).
" (".implode($names, ",").") VALUES ".
"(".implode($values, ",").
")");
$node->setAttribute('foreignId', $cp_node_id);
$this->idmap[$node->getAttribute('id')] = $cp_node_id;
// run sub nodes
foreach($node->childNodes as $child)
{
$this->dbImport($child, $lft, $depth+1, $cp_node_id); // RECURSION
}
// update cp_tree (rgt value for pre order walk in sql tree)
$ilDB->query('UPDATE cp_tree SET rgt='.$ilDB->quote($lft++).
' WHERE child = '.$ilDB->quote($cp_node_id));
//ilSCORM13DB::exec($q);
break;
}
}
Here is the caller graph for this function:| ilSCORM13Package::dbRemoveAll | ( | ) |
Definition at line 464 of file ilSCORM13Package.php.
References $t.
Referenced by rollback().
{
global $ilDB;
// remove CP element entries
foreach (self::$elements['cp'] as $t)
{
$t = 'cp_' . $t;
$ilDB->query("DELETE FROM $t WHERE $t.cp_node_id IN (SELECT cp_node.cp_node_id FROM cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId));
}
// remove CMI entries
$ilDB->query("DELETE FROM cmi_correct_response WHERE cmi_correct_response.cmi_interaction_id IN (SELECT cmi_interaction.cmi_interaction_id FROM cmi_interaction, cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId));
$ilDB->query("DELETE FROM cmi_objective WHERE cmi_objective.cmi_interaction_id IN (SELECT cmi_interaction.cmi_interaction_id FROM cmi_interaction, cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId));
$ilDB->query("DELETE FROM cmi_objective WHERE cmi_objective.cmi_node_id IN (SELECT cmi_node.cmi_node_id FROM cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId));
$ilDB->query("DELETE FROM cmi_interaction WHERE cmi_interaction.cmi_node_id IN (SELECT cmi_node.cmi_node_id FROM cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId));
$ilDB->query("DELETE FROM cmi_comment WHERE cmi_comment.cmi_node_id IN (SELECT cmi_node.cmi_node_id FROM cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId));
$ilDB->query("DELETE FROM cmi_node WHERE cmi_node.cmi_node_id IN (SELECT cmi_node.cmi_node_id FROM cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId));
// remove CP structure entries in tree and node
$ilDB->query("DELETE FROM cp_tree WHERE cp_tree.obj_id=".
$ilDB->quote($this->packageId));
$ilDB->query("DELETE FROM cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId));
// remove general package entry
$ilDB->query("DELETE FROM cp_package WHERE cp_package.obj_id=".
$ilDB->quote($this->packageId));
}
Here is the caller graph for this function:| ilSCORM13Package::exportXML | ( | ) |
Export as internal XML.
Definition at line 138 of file ilSCORM13Package.php.
{
global $ilDB;
header('content-type: text/xml');
header('content-disposition: attachment; filename="manifest.xml"');
//$row = ilSCORM13DB::getRecord("cp_package", "obj_id",$this->packageId);
$set = $ilDB->query("SELECT * FROM cp_package WHERE obj_id = ".$ilDB->quote($this->$packageId));
$row = $set->fetchRow(DB_FETCHMODE_ASSOC);
print($row["xmldata"]);
}
| ilSCORM13Package::exportZIP | ( | ) |
Definition at line 128 of file ilSCORM13Package.php.
{
header('content-type: application/zip');
header('content-disposition: attachment; filename="' . basename($this->packageFile) . '"');
readfile($this->packageFile);
}
| ilSCORM13Package::il_import | ( | $ | packageFolder, | |
| $ | packageId, | |||
| $ | ilias, | |||
| $ | validate | |||
| ) |
Imports an extracted SCORM 2004 module from ilias-data dir into database.
public
Definition at line 179 of file ilSCORM13Package.php.
References $ilias, $ilLog, $packageFolder, $packageId, $x, dbImport(), jsonNode(), transform(), and validate().
{
global $ilDB, $ilLog;
//$ilLog->write("SCORM: il_import");
$this->packageFolder=$packageFolder;
$this->packageId=$packageId;
$this->imsmanifestFile = $this->packageFolder . '/' . 'imsmanifest.xml';
//step 1 - parse Manifest-File and validate
$this->imsmanifest = new DOMDocument;
$this->imsmanifest->async = false;
if (!@$this->imsmanifest->load($this->imsmanifestFile))
{
$this->diagnostic[] = 'XML not wellformed';
return false;
}
// $ilLog->write("SCORM: parse");
//step 2 tranform
$this->manifest = $this->transform($this->imsmanifest, self::DB_ENCODE_XSL);
if (!$this->manifest)
{
$this->diagnostic[] = 'Cannot transform into normalized manifest';
return false;
}
// $ilLog->write("SCORM: normalize");
//step 3 validation -just for normalized XML
if ($validate=="y") {
if (!$this->validate($this->manifest, self::VALIDATE_XSD))
{
$ilias->raiseError("<b>The uploaded SCORM 1.2 / SCORM 2004 is not valid. You can try to import the package without the validation option checked on your own risk. </b><br><br>Validation Error(s):</b><br> Normalized XML is not conform to ". self::VALIDATE_XSD,
$ilias->error_obj->WARNING);
//
//$this->diagnostic[] = 'normalized XML is not conform to ' . self::VALIDATE_XSD;
// return false;
}
}
// $ilLog->write("SCORM: validate");
// ilSCORM13DB::begin();
$this->dbImport($this->manifest);
// $ilLog->write("SCORM: import new");
// ilSCORM13DB::commit();
//step 5
$x = simplexml_load_string($this->manifest->saveXML());
// add database values from package and sahs_lm records as defaults
$x['persistPreviousAttempts'] = $this->packageData['persistPreviousAttempts'];
$x['online'] = $this->packageData['online'];
$x['defaultLessonMode'] = $this->packageData['default_lesson_mode'];
$x['credit'] = $this->packageData['credit'];
$x['autoReview'] = $this->packageData['auto_review'];
$j = array();
// first read resources into flat array to resolve item/identifierref later
$r = array();
foreach ($x->resource as $xe)
{
$r[strval($xe['id'])] = $xe;
unset($xe);
}
// iterate through items and set href and scoType as activity attributes
foreach ($x->xpath('//*[local-name()="item"]') as $xe)
{
// get reference to resource and set href accordingly
if ($b = $r[strval($xe['resourceId'])])
{
$xe['href'] = strval($b['base']) . strval($b['href']);
unset($xe['resourceId']);
if (strval($b['scormType'])=='sco') $xe['sco'] = true;
}
}
// iterate recursivly through activities and build up simple php object
// with items and associated sequencings
// top node is the default organization which is handled as an item
self::jsonNode($x->organization, $j['item']);
foreach($x->sequencing as $s)
{
self::jsonNode($s, $j['sequencing'][]);
}
// combined manifest+resources xml:base is set as organization base
$j['item']['base'] = strval($x['base']);
// package folder is base to whole playing process
$j['base'] = $packageFolder . '/';
$j['foreignId'] = floatval($x['foreignId']); // manifest cp_node_id for associating global (package wide) objectives
$j['id'] = strval($x['id']); // manifest id for associating global (package wide) objectives
//last step - build ADL Activity tree
$act = new SeqTreeBuilder();
$adl_tree = $act->buildNodeSeqTree($this->imsmanifestFile);
/*$ilDB->query("INSERT INTO cp_package ".
"(obj_id, xmldata, jsdata, activitytree) VALUES ".
"(".$ilDB->quote($this->packageId).",".
$ilDB->quote($x->asXML()).",".
$ilDB->quote(json_encode($j)).",".
$ilDB->quote(json_encode($adl_tree)).")";*/
$ilDB->query("UPDATE cp_package SET ".
" xmldata = ".$ilDB->quote($x->asXML()).",".
" jsdata = ".$ilDB->quote(json_encode($j)).",".
" activitytree = ".$ilDB->quote(json_encode($adl_tree['tree'])).",".
" global_to_system = ".$ilDB->quote($adl_tree['global']).
" WHERE obj_id = ".$ilDB->quote($this->packageId));
/*ilSCORM13DB::setRecord(
'cp_package', array(
'obj_id' => $this->packageId,
'xmldata' => $x->asXML(),
'jsdata' => json_encode($j),
'activitytree' => json_encode($adl_tree)
), 'obj_id');*/
// $ilLog->write("SCORM: import update");
return $j['item']['title'];
}
Here is the call graph for this function:| ilSCORM13Package::jsonNode | ( | $ | node, | |
| &$ | sink | |||
| ) |
Helper for UploadAndImport Recursively copies values from XML into PHP array for export as json Elements are translated into sub array, attributes into literals.
| xml | element to process | |
| reference | to array object where to copy values |
Definition at line 315 of file ilSCORM13Package.php.
Referenced by il_import().
{
foreach ($node->attributes() as $k => $v)
{
// cast to boolean and number if possible
$v = strval($v);
if ($v==="true") $v = true;
else if ($v==="false") $v = false;
else if (is_numeric($v)) $v = (float) $v;
$sink[$k] = $v;
}
foreach ($node->children() as $name => $child)
{
self::jsonNode($child, $sink[$name][]); // RECURSION
}
}
Here is the caller graph for this function:| ilSCORM13Package::load | ( | $ | packageId | ) |
Definition at line 95 of file ilSCORM13Package.php.
References $packageId.
Referenced by __construct().
{
global $ilDB;
if (!is_numeric($packageId))
{
return false;
}
$set = $ilDB->query("SELECT * FROM sahs_lm WHERE id = ".$ilDB->quote($packageId));
$lm_data = $set->fetchRow(DB_FETCHMODE_ASSOC);
$set = $ilDB->query("SELECT * FROM cp_package WHERE obj_id = ".$ilDB->quote($packageId));
$pg_data = $set->fetchRow(DB_FETCHMODE_ASSOC);
$this->packageData = array_merge($lm_data, $pg_data);
$this->packageId = $packageId;
$this->packageFolder = $this->packagesFolder . '/' . $packageId;
$this->packageFile = $this->packageFolder . '.zip';
$this->imsmanifestFile = $this->packageFolder . '/' . 'imsmanifest.xml';
return true;
}
Here is the caller graph for this function:| ilSCORM13Package::removeCMIData | ( | ) |
Definition at line 152 of file ilSCORM13Package.php.
{
global $ilDB;
$ilDB->query("DELETE FROM cmi_correct_response WHERE cmi_correct_response.cmi_interaction_id IN (SELECT cmi_interaction.cmi_interaction_id FROM cmi_interaction, cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId).")");
$ilDB->query("DELETE FROM cmi_objective WHERE cmi_objective.cmi_interaction_id IN (SELECT cmi_interaction.cmi_interaction_id FROM cmi_interaction, cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId).")");
$ilDB->query("DELETE FROM cmi_objective WHERE cmi_objective.cmi_node_id IN (SELECT cmi_node.cmi_node_id FROM cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId).")");
$ilDB->query("DELETE FROM cmi_interaction WHERE cmi_interaction.cmi_node_id IN (SELECT cmi_node.cmi_node_id FROM cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId).")");
$ilDB->query("DELETE FROM cmi_comment WHERE cmi_comment.cmi_node_id IN (SELECT cmi_node.cmi_node_id FROM cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId).")");
$ilDB->query("DELETE FROM cmi_node WHERE cmi_node.cmi_node_id IN (SELECT cmi_node.cmi_node_id FROM cmi_node, cp_node WHERE cp_node.slm_id=".
$ilDB->quote($this->packageId).")");
$set = $ilDB->query("SELECT * FROM cp_package WHERE obj_id = ".$ilDB->quote($this->$packageId));
$row = $set->fetchRow(DB_FETCHMODE_ASSOC);
return $row["xmldata"];
}
| ilSCORM13Package::rollback | ( | ) |
Definition at line 117 of file ilSCORM13Package.php.
References dbRemoveAll(), and setProgress().
{
$this->setProgress(0, 'Rolling back...');
$this->dbRemoveAll();
if (is_dir($this->packageFolder))
dir_delete($this->packageFolder);
if (is_file($this->packageFile))
@unlink($this->packageFile);
$this->setProgress(0, 'Roll back finished: Ok. ');
}
Here is the call graph for this function:| ilSCORM13Package::setProgress | ( | $ | progress, | |
| $ | msg = '' | |||
| ) | [private] |
Definition at line 301 of file ilSCORM13Package.php.
References $progress.
Referenced by rollback().
{
$this->progress = $progress;
$this->diagnostic[] = $msg;
}
Here is the caller graph for this function:| ilSCORM13Package::transform | ( | $ | inputdoc, | |
| $ | xslfile, | |||
| $ | outputpath = null | |||
| ) |
Definition at line 498 of file ilSCORM13Package.php.
Referenced by il_import().
{
$xsl = new DOMDocument;
$xsl->async = false;
if (!@$xsl->load($xslfile))
{
die('ERROR: load StyleSheet ' . $xslfile);
}
$prc = new XSLTProcessor;
$r = @$prc->importStyleSheet($xsl);
if (false===@$prc->importStyleSheet($xsl))
{
die('ERROR: importStyleSheet ' . $xslfile);
}
if ($outputpath)
{
file_put_contents($outputpath, $prc->transformToXML($inputdoc));
}
else
{
return $prc->transformToDoc($inputdoc);
}
}
Here is the caller graph for this function:| ilSCORM13Package::validate | ( | $ | doc, | |
| $ | schema | |||
| ) |
Definition at line 522 of file ilSCORM13Package.php.
Referenced by il_import().
{
libxml_use_internal_errors(true);
$return = @$doc->schemaValidate($schema);
if (!$return)
{
$levels = array(
LIBXML_ERR_ERROR => 'Error',
LIBXML_ERR_FATAL => 'Fatal Error'
);
foreach (libxml_get_errors() as $error)
{
$level = $levels[$error->level];
if (isset($level))
{
$message = trim($error->message);
//$file = $error->file ? 'in <b>' . $error->file . '</b>' : '';
// $error->code:
$this->diagnostic[] = "XSLT $level (Line $error->line) $message";
}
}
libxml_clear_errors();
}
libxml_use_internal_errors(false);
return $return;
}
Here is the caller graph for this function:| ilSCORM13Package::$diagnostic |
Definition at line 53 of file ilSCORM13Package.php.
ilSCORM13Package::$elements [static, private] |
array(
'cp' => array(
'manifest',
'organization',
'item',
'hideLMSUI',
'resource',
'file',
'dependency',
'sequencing',
'rule',
'auxilaryResource',
'condition',
'mapinfo',
'objective',
),
'cmi' => array(
'comment',
'correct_response',
'interaction',
'node',
'objective',
),
)
Definition at line 63 of file ilSCORM13Package.php.
ilSCORM13Package::$idmap = array() [private] |
Definition at line 60 of file ilSCORM13Package.php.
| ilSCORM13Package::$imsmanifest |
Definition at line 51 of file ilSCORM13Package.php.
| ilSCORM13Package::$manifest |
Definition at line 52 of file ilSCORM13Package.php.
ilSCORM13Package::$packageData [private] |
Definition at line 49 of file ilSCORM13Package.php.
ilSCORM13Package::$packageFile [private] |
Definition at line 46 of file ilSCORM13Package.php.
ilSCORM13Package::$packageFolder [private] |
Definition at line 47 of file ilSCORM13Package.php.
Referenced by il_import().
| ilSCORM13Package::$packageHash |
Definition at line 57 of file ilSCORM13Package.php.
| ilSCORM13Package::$packageId |
Definition at line 55 of file ilSCORM13Package.php.
Referenced by __construct(), il_import(), and load().
| ilSCORM13Package::$packageName |
Definition at line 56 of file ilSCORM13Package.php.
ilSCORM13Package::$packagesFolder [private] |
Definition at line 48 of file ilSCORM13Package.php.
ilSCORM13Package::$progress = 0.0 [private] |
Definition at line 61 of file ilSCORM13Package.php.
Referenced by setProgress().
| ilSCORM13Package::$status |
Definition at line 54 of file ilSCORM13Package.php.
| ilSCORM13Package::$userId |
Definition at line 58 of file ilSCORM13Package.php.
| const ilSCORM13Package::CONVERT_XSL = './Modules/Scorm2004/templates/xsl/op/scorm12To2004.xsl' |
Definition at line 38 of file ilSCORM13Package.php.
| const ilSCORM13Package::DB_DECODE_XSL = './Modules/Scorm2004/templates/xsl/op/op-scorm13-revert.xsl' |
Definition at line 39 of file ilSCORM13Package.php.
| const ilSCORM13Package::DB_ENCODE_XSL = './Modules/Scorm2004/templates/xsl/op/op-scorm13.xsl' |
Definition at line 37 of file ilSCORM13Package.php.
| const ilSCORM13Package::VALIDATE_XSD = './Modules/Scorm2004/templates/xsd/op/op-scorm13.xsd' |
Definition at line 40 of file ilSCORM13Package.php.
| const ilSCORM13Package::WRAPPER_HTML = './Modules/Scorm2004/scripts/converter/GenericRunTimeWrapper1.0_aadlc/GenericRunTimeWrapper.htm' |
Definition at line 42 of file ilSCORM13Package.php.
| const ilSCORM13Package::WRAPPER_JS = './Modules/Scorm2004/scripts/converter/GenericRunTimeWrapper1.0_aadlc/SCOPlayerWrapper.js' |
Definition at line 43 of file ilSCORM13Package.php.
1.7.1