Permalink
Browse files

Fixed a problem during scorm update.

Now tracks are deleted only if the scoes are really changed
  • Loading branch information...
bobopinna
bobopinna committed Aug 11, 2006
1 parent f5c2ff5 commit 0fc250371841ddd40f15022966af270469c21204
Showing with 235 additions and 111 deletions.
  1. +25 −66 mod/scorm/lib.php
  2. +5 −2 mod/scorm/loadSCO.php
  3. +127 −19 mod/scorm/locallib.php
  4. +33 −12 mod/scorm/mod.html
  5. +45 −12 mod/scorm/validate.php
View
@@ -47,6 +47,12 @@
set_config('scorm_framewidth','100%');
}
//
// Repository configurations
//
$repositoryconfigfile = $CFG->dirroot.'/mod/resource/type/ims/repository_config.php';
$repositorybrowser = '/mod/resource/type/ims/finder.php';
/**
* Given an object containing all the necessary data,
* (defined by the form in mod.html) this function
@@ -73,14 +79,14 @@ function scorm_add_instance($scorm) {
$id = insert_record('scorm', $scorm);
if (basename($scorm->reference) != 'imsmanifest.xml') {
if ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) {
// Rename temp scorm dir to scorm id
$scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id);
}
// Parse scorm manifest
if ($scorm->launch == 0) {
if ($scorm->parse == 1) {
require_once('locallib.php');
$scorm->id = $id;
$scorm->launch = scorm_parse($scorm);
@@ -111,18 +117,17 @@ function scorm_update_instance($scorm) {
$scorm->height = str_replace('%','',$scorm->height);
// Check if scorm manifest needs to be reparsed
if ($scorm->launch == 0) {
// Delete old related records
delete_records('scorm_scoes','scorm',$scorm->id);
delete_records('scorm_scoes_track','scormid',$scorm->id);
if ($scorm->parse == 1) {
require_once('locallib.php');
$scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) && (basename($scorm->reference) != 'imsmanifest.xml')) {
if (is_dir($scorm->dir.'/'.$scorm->id)) {
scorm_delete_files($scorm->dir.'/'.$scorm->id);
}
if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) &&
(basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) {
rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id);
}
require_once('locallib.php');
$scorm->launch = scorm_parse($scorm);
}
return update_record('scorm', $scorm);
@@ -147,6 +152,7 @@ function scorm_delete_instance($id) {
$result = true;
// Delete any dependent files
require_once('locallib.php');
scorm_delete_files($CFG->dataroot.'/'.$scorm->course.'/moddata/scorm/'.$scorm->id);
// Delete any dependent records
@@ -186,8 +192,8 @@ function scorm_user_outline($course, $user, $mod, $scorm) {
require_once('locallib.php');
foreach ($scoes as $sco) {
if ($sco->launch!='') {
$scores->count++;
if ($userdata = scorm_get_tracks($sco->id, $user->id)) {
$scores->count++;
if ($userdata = scorm_get_tracks($sco->id, $user->id)) {
if (!isset($scores->{$userdata->status})) {
$scores->{$userdata->status} = 1;
} else {
@@ -206,7 +212,7 @@ function scorm_user_outline($course, $user, $mod, $scorm) {
}
switch ($scorm->grademethod) {
case GRADEHIGHEST:
if ($scores->values > 0) {
if ($scores->values > 0) {
$return->info = get_string('score','scorm').': '.$scores->max;
$return->time = $scores->lastmodify;
}
@@ -227,30 +233,30 @@ function scorm_user_outline($course, $user, $mod, $scorm) {
$return->info = '';
$scores->notattempted = $scores->count;
if (isset($scores->completed)) {
$return->info .= get_string('completed','scorm').':&nbsp;'.$scores->completed.'<br />';
$return->info .= get_string('completed','scorm').':&nbsp;'.$scores->completed.'<br />';
$scores->notattempted -= $scores->completed;
}
if (isset($scores->passed)) {
$return->info .= get_string('passed','scorm').':&nbsp;'.$scores->passed.'<br />';
$return->info .= get_string('passed','scorm').':&nbsp;'.$scores->passed.'<br />';
$scores->notattempted -= $scores->passed;
}
if (isset($scores->failed)) {
$return->info .= get_string('failed','scorm').':&nbsp;'.$scores->failed.'<br />';
$return->info .= get_string('failed','scorm').':&nbsp;'.$scores->failed.'<br />';
$scores->notattempted -= $scores->failed;
}
if (isset($scores->incomplete)) {
$return->info .= get_string('incomplete','scorm').':&nbsp;'.$scores->incomplete.'<br />';
$return->info .= get_string('incomplete','scorm').':&nbsp;'.$scores->incomplete.'<br />';
$scores->notattempted -= $scores->incomplete;
}
if (isset($scores->browsed)) {
$return->info .= get_string('browsed','scorm').':&nbsp;'.$scores->browsed.'<br />';
$return->info .= get_string('browsed','scorm').':&nbsp;'.$scores->browsed.'<br />';
$scores->notattempted -= $scores->browsed;
}
$return->time = $scores->lastmodify;
if ($return->info == '') {
$return = NULL;
} else {
$return->info .= get_string('notattempted','scorm').':&nbsp;'.$scores->notattempted.'<br />';
$return->info .= get_string('notattempted','scorm').':&nbsp;'.$scores->notattempted.'<br />';
}
break;
}
@@ -388,7 +394,7 @@ function scorm_user_complete($course, $user, $mod, $scorm) {
echo get_string('report','scorm').":<br />\n";
echo $report;
} else {
print_string('noactivity','scorm');
print_string('noactivity','scorm');
}
return true;
@@ -465,53 +471,6 @@ function scorm_get_post_actions() {
return array();
}
/**
* This function will permanently delete the given
* directory and all files and subdirectories.
*
* @param string $directory The directory to remove
* @return boolean
*/
function scorm_delete_files($directory) {
if (is_dir($directory)) {
$files=scorm_scandir($directory);
foreach($files as $file) {
if (($file != '.') && ($file != '..')) {
if (!is_dir($directory.'/'.$file)) {
unlink($directory.'/'.$file);
} else {
scorm_delete_files($directory.'/'.$file);
}
}
set_time_limit(5);
}
rmdir($directory);
return true;
}
return false;
}
/**
* Given a diretory path returns the file list
*
* @param string $directory
* @return array
*/
function scorm_scandir($directory) {
if (version_compare(phpversion(),'5.0.0','>=')) {
return scandir($directory);
} else {
$files = array();
if ($dh = opendir($directory)) {
while (($file = readdir($dh)) !== false) {
$files[] = $file;
}
closedir($dh);
}
return $files;
}
}
function scorm_option2text($scorm) {
global $SCORM_POPUP_OPTIONS;
View
@@ -4,7 +4,7 @@
$id = optional_param('id', '', PARAM_INT); // Course Module ID, or
$a = optional_param('a', '', PARAM_INT); // scorm ID
$scoid = required_param('scoid', PARAM_INT); // sco ID
$scoid = required_param('scoid', PARAM_INT); // sco ID
if (!empty($id)) {
if (! $cm = get_coursemodule_from_id('scorm', $id)) {
@@ -33,7 +33,7 @@
require_login($course->id, false, $cm);
if (!empty($scoid)) {
//
// Direct sco request
// Direct SCO request
//
if ($sco = get_record("scorm_scoes","id",$scoid)) {
if ($sco->launch == '') {
@@ -79,6 +79,9 @@
if (scorm_external_link($sco->launch)) {
$result = $launcher;
} else if ($scorm->reference[0] == '#') {
require_once($repositoryconfigfile);
$result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
} else {
if (basename($scorm->reference) == 'imsmanifest.xml') {
$basedir = dirname($scorm->reference);
Oops, something went wrong.

0 comments on commit 0fc2503

Please sign in to comment.