From 6381fa56edfa2848e64d67fd1caf0fb9fdd092b6 Mon Sep 17 00:00:00 2001 From: piers Date: Tue, 16 Sep 2008 20:32:50 +0000 Subject: [PATCH] MDL-11501 Scorm New attempts and reviewing. Changes to help customise player/package interactions. --- .../help/scorm/displayattemptstatus.html | 4 + .../help/scorm/displaycoursestructure.html | 3 + lang/en_utf8/help/scorm/forcecompleted.html | 4 + lang/en_utf8/help/scorm/forcenewattempt.html | 3 + lang/en_utf8/help/scorm/lastattemptlock.html | 4 + lang/en_utf8/scorm.php | 10 ++ mod/scorm/datamodel.php | 2 +- mod/scorm/db/install.xml | 9 +- mod/scorm/db/upgrade.php | 30 ++++ mod/scorm/locallib.php | 135 ++++++++++++++++-- mod/scorm/mod_form.php | 28 ++++ mod/scorm/version.php | 2 +- mod/scorm/view.php | 6 +- 13 files changed, 227 insertions(+), 13 deletions(-) create mode 100644 lang/en_utf8/help/scorm/displayattemptstatus.html create mode 100644 lang/en_utf8/help/scorm/displaycoursestructure.html create mode 100644 lang/en_utf8/help/scorm/forcecompleted.html create mode 100644 lang/en_utf8/help/scorm/forcenewattempt.html create mode 100644 lang/en_utf8/help/scorm/lastattemptlock.html diff --git a/lang/en_utf8/help/scorm/displayattemptstatus.html b/lang/en_utf8/help/scorm/displayattemptstatus.html new file mode 100644 index 0000000000000..1bc89a71ab706 --- /dev/null +++ b/lang/en_utf8/help/scorm/displayattemptstatus.html @@ -0,0 +1,4 @@ +

Display Attempt Status

+ +

Display attempt status controls whether the status of SCORM attempts by a student are displayed on the SCORM outline page.

+

The status displays attempts, the scores, and grade passed to the Gradebook

diff --git a/lang/en_utf8/help/scorm/displaycoursestructure.html b/lang/en_utf8/help/scorm/displaycoursestructure.html new file mode 100644 index 0000000000000..0089ba76595a3 --- /dev/null +++ b/lang/en_utf8/help/scorm/displaycoursestructure.html @@ -0,0 +1,3 @@ +

Display Course Structure

+ +

Display course structure controls whether the SCORM table of contents gets displayed on the SCORM outline page.

diff --git a/lang/en_utf8/help/scorm/forcecompleted.html b/lang/en_utf8/help/scorm/forcecompleted.html new file mode 100644 index 0000000000000..465abc4dbd798 --- /dev/null +++ b/lang/en_utf8/help/scorm/forcecompleted.html @@ -0,0 +1,4 @@ +

Force Completed

+ +

Force completed will ensure that the status of the current attempt is forced to "completed" if cmi.core.score.raw has been issued, and as such is only relevant for SCORM 1.2 packages.

+

This is usefull if the SCORM package does not handle revisiting an attempt correctly, in review or browse mode, or otherwise incorrectly issues the completion status.

diff --git a/lang/en_utf8/help/scorm/forcenewattempt.html b/lang/en_utf8/help/scorm/forcenewattempt.html new file mode 100644 index 0000000000000..ddbeee524c5f7 --- /dev/null +++ b/lang/en_utf8/help/scorm/forcenewattempt.html @@ -0,0 +1,3 @@ +

Force New Attempt

+ +

Force new attempt will make every visit to a SCORM package a new attempt.

diff --git a/lang/en_utf8/help/scorm/lastattemptlock.html b/lang/en_utf8/help/scorm/lastattemptlock.html new file mode 100644 index 0000000000000..b714b89ff16ab --- /dev/null +++ b/lang/en_utf8/help/scorm/lastattemptlock.html @@ -0,0 +1,4 @@ +

Lock After Final Attempt

+ +

This enables the locking of the SCORM player after a student has used all of their allocated attempts.

+

The student will still be able to visit the course outline page and view the attempts status information (if enabled), but will not beable to select "Enter" to launch the player.

diff --git a/lang/en_utf8/scorm.php b/lang/en_utf8/scorm.php index 8cf989ed517d1..cd91df31b9eea 100644 --- a/lang/en_utf8/scorm.php +++ b/lang/en_utf8/scorm.php @@ -38,6 +38,8 @@ $string['directories'] = 'Show the directory links'; $string['display'] = 'Display package'; $string['domxml'] = 'DOMXML external library'; +$string['displayattemptstatus'] = 'Display attempt status'; +$string['displaycoursestructure'] = 'Display course structure'; $string['element'] = 'Element'; $string['entercourse'] = 'Enter course'; $string['enter'] = 'Enter'; @@ -56,9 +58,12 @@ $string['framewidth'] = 'This preference set the default width for stage frame or window'; $string['fullscreen'] = 'Fill the whole screen'; $string['general'] = 'General data'; +$string['forcenewattempt'] = 'Force new attempt'; +$string['forcecompleted'] = 'Force completed'; $string['gradeaverage'] = 'Average grade'; $string['gradehighest'] = 'Highest grade'; $string['grademethod'] = 'Grading method'; +$string['gradereported'] = 'Grade reported'; $string['gradescoes'] = 'Learning Objects'; $string['gradesum'] = 'Sum grade'; $string['height'] = 'Height'; @@ -78,6 +83,7 @@ $string['last'] = 'Last accessed on'; $string['lastaccess'] = 'Last access'; $string['lastattempt'] = 'Last attempt'; +$string['lastattemptlock'] = 'Lock after final attempt'; $string['location'] = 'Show the location bar'; $string['max'] = 'Max score'; $string['maximumattempts'] = 'Number of attempts'; @@ -176,4 +182,8 @@ $string['activitypleasewait'] = "Activity loading, please wait ...."; $string['scormloggingon'] = "API Logging is On"; $string['scormloggingoff'] = "API Logging is Off"; +$string['noattemptsallowed'] = "Number of attempts allowed"; +$string['noattemptsmade'] = "Number of attempts you have made"; +$string['gradeforattempt'] = "Grade for attempt"; +$string['exceededmaxattempts'] = "You have reached the maximum number of attempts."; ?> \ No newline at end of file diff --git a/mod/scorm/datamodel.php b/mod/scorm/datamodel.php index 19d4905b15eee..a10875b7457bd 100755 --- a/mod/scorm/datamodel.php +++ b/mod/scorm/datamodel.php @@ -43,7 +43,7 @@ $element = str_replace('__','.',$element); if (substr($element,0,3) == 'cmi') { $netelement = preg_replace('/\.N(\d+)\./',"\.\$1\.",$element); - $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $netelement, $value) && $result; + $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $element, $value, $scorm->forcecompleted) && $result; } if (substr($element,0,15) == 'adl.nav.request') { // SCORM 2004 Sequencing Request diff --git a/mod/scorm/db/install.xml b/mod/scorm/db/install.xml index 12642de474d8c..dabb226add780 100644 --- a/mod/scorm/db/install.xml +++ b/mod/scorm/db/install.xml @@ -16,8 +16,13 @@ - - + + + + + + + diff --git a/mod/scorm/db/upgrade.php b/mod/scorm/db/upgrade.php index 9061b248e9c96..5e4611eb46da2 100644 --- a/mod/scorm/db/upgrade.php +++ b/mod/scorm/db/upgrade.php @@ -234,6 +234,36 @@ function scorm_migrate_content_files($context, $base, $path) { upgrade_mod_savepoint($result, 2008090304, 'scorm'); } + + if ($result && $oldversion < 2008090305) { + + /// Define new fields forcecompleted, forcenewattempt, displayattemptstatus, and displaycoursestructure to be added to scorm + $table = new xmldb_table('scorm'); + $field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, '1', null, null, null, null, null, '0', 'maxattempt'); + if (!$dbman->field_exists($table,$field)) { + $dbman->add_field($table, $field); + } + $field = new xmldb_field('forcenewattempt', XMLDB_TYPE_INTEGER, '1', null, null, null, null, null, '0', 'forcecompleted'); + if (!$dbman->field_exists($table,$field)) { + $dbman->add_field($table, $field); + } + $field = new xmldb_field('lastattemptlock', XMLDB_TYPE_INTEGER, '1', null, null, null, null, null, '0', 'forcenewattempt'); + if (!$dbman->field_exists($table,$field)) { + $dbman->add_field($table, $field); + } + $field = new xmldb_field('displayattemptstatus', XMLDB_TYPE_INTEGER, '1', null, null, null, null, null, '1', 'lastattemptlock'); + if (!$dbman->field_exists($table,$field)) { + $dbman->add_field($table, $field); + } + $field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, '1', null, null, null, null, null, '1', 'displayattemptstatus'); + if (!$dbman->field_exists($table,$field)) { + $dbman->add_field($table, $field); + } + + /// scorm savepoint reached + upgrade_mod_savepoint($result, 2008090305, 'scorm'); + } + return $result; } diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 7fecd22debd23..28a6ff0355460 100755 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -238,10 +238,28 @@ function scorm_get_scoes($id,$organisation=false) { } } -function scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value) { +function scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value,$forcecompleted=false) { global $DB; $id = null; + + if ($forcecompleted) { + //TODO - this could be broadened to encompass SCORM 2004 in future + if (($element == 'cmi.core.lesson_status') && ($value == 'incomplete')) { + if ($track = $DB->get_record_select('scorm_scoes_track','userid=? AND scormid=? AND scoid=? AND attempt=? AND element=\'cmi.core.score.raw\'', array($userid, $scormid, $scoid, $attempt))) { + $value = 'completed'; + } + } + if ($element == 'cmi.core.score.raw') { + if ($tracktest = $DB->get_record_select('scorm_scoes_track','userid=? AND scormid=? AND scoid=? AND attempt=? AND element=\'cmi.core.lesson_status\'', array($userid, $scormid, $scoid, $attempt))) { + if ($tracktest->value == "incomplete") { + $tracktest->value = "completed"; + $idtest = $DB->update_record('scorm_scoes_track',$tracktest); + } + } + } + } + if ($track = $DB->get_record('scorm_scoes_track',array('userid'=>$userid, 'scormid'=>$scormid, 'scoid'=>$scoid, 'attempt'=>$attempt, 'element'=>$element))) { $track->value = $value; $track->timemodified = time(); @@ -499,6 +517,8 @@ function scorm_get_last_attempt($scormid, $userid) { } else { return $lastattempt->a; } + } else { + return false; } } @@ -561,10 +581,12 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') { $organization = optional_param('organization', '', PARAM_INT); - print_simple_box_start('center',$boxwidth); + if($scorm->displaycoursestructure == 1) { + print_simple_box_start('center',$boxwidth); ?>
launch; } @@ -607,9 +629,18 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') { $result = scorm_get_toc($user,$scorm,'structlist',$orgidentifier); $incomplete = $result->incomplete; - echo $result->toc; - print_simple_box_end(); + // do we want the TOC to be displayed? + if($scorm->displaycoursestructure == 1) { + echo $result->toc; + print_simple_box_end(); + } + + // is this the first attempt ? + $attemptcount = scorm_get_attempt_count($user, $scorm); + + // do not give the player launch FORM if the SCORM object is locked after the final attempt + if ($scorm->lastattemptlock == 0 || $result->attemptleft > 0) { ?>
@@ -621,11 +652,15 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') { } else { echo ''."\n"; } - if (($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) { + if ($scorm->forcenewattempt == 1) { + if ($incomplete === false) { + echo ''."\n"; + } + } elseif ($attemptcount != 0 && ($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) { ?> -
- - +
+ + @@ -637,6 +672,7 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
get_records_select('scorm_scoes_track',"element='cmi.core.score.raw' AND userid=? AND scormid=?", array($user->id, $scorm->id),'attempt','attempt AS attemptnumber, value AS grade'); + if(empty($attempts)) { + $attemptcount = 0; + } else { + $attemptcount = count($attempts); + } + + $result = '

'.get_string('noattemptsallowed', 'scorm').': '; + if ($scorm->maxattempt > 0) { + $result .= $scorm->maxattempt . '
'; + } else { + $result .= get_string('unlimited').'
'; + } + $result .= get_string('noattemptsmade', 'scorm').': ' . $attemptcount . '
'; + + $gradereported = 0; + $gradesum = 0; + switch ($scorm->grademethod) { + case GRADEHIGHEST: + $grademethod = get_string('gradehighest', 'scorm'); + break; + case GRADEAVERAGE: + $grademethod = get_string('gradeaverage', 'scorm'); + break; + case GRADESUM: + $grademethod = get_string('gradesum', 'scorm'); + break; + case GRADESCOES: + $grademethod = get_string('gradescoes', 'scorm'); + break; + } + + if(!empty($attempts)) { + foreach($attempts as $attempt) { + $gradereported = scorm_grade_user_attempt($scorm, $user->id, $attempt->attemptnumber); + $result .= get_string('gradeforattempt', 'scorm').' ' . $attempt->attemptnumber . ': ' . $attempt->grade .'%
'; + } + } + + $result .= get_string('grademethod', 'scorm'). ': ' . $grademethod; + if(empty($attempts)) { + $result .= '
' . get_string('gradereported','scorm') . ': ' . get_string('none') . '
'; + } else { + $result .= '
' . get_string('gradereported','scorm') . ': ' . $gradereported . ($scorm->grademethod == GRADESCOES ? '' : '%') .'
'; + } + $result .= '

'; + if ($attemptcount >= $scorm->maxattempt and $scorm->maxattempt > 0) { + $result .= '

'.get_string('exceededmaxattempts','scorm').'

'; + } + return $result; +} + +/** +* Get SCORM attempt count +* +* @param object $user Current context user +* @param object $scorm a moodle scrom object - mdl_scorm +* @return int - no. of attempts so far +*/ +function scorm_get_attempt_count($user, $scorm) { + global $DB; + $attemptcount = 0; + $element = 'cmi.core.score.raw'; + if ($scorm->version == 'scorm1_3') { + $element = 'cmi.score.raw'; + } + $attempts = $DB->get_records_select('scorm_scoes_track',"element=? AND userid=? AND scormid=?", array($element, $user->id, $scorm->id),'attempt','attempt AS attemptnumber, value AS grade'); + if(!empty($attempts)) { + $attemptcount = count($attempts); + } + return $attemptcount; +} ?> \ No newline at end of file diff --git a/mod/scorm/mod_form.php b/mod/scorm/mod_form.php index 399edc375068c..4d1453dc6aa2a 100644 --- a/mod/scorm/mod_form.php +++ b/mod/scorm/mod_form.php @@ -103,6 +103,34 @@ function definition() { $mform->setHelpButton('maxattempt', array('maxattempt',get_string('maximumattempts', 'scorm'), 'scorm')); $mform->setDefault('maxattempt', 1); +// Display attempt status + $mform->addElement('selectyesno', 'displayattemptstatus', get_string('displayattemptstatus', 'scorm')); + $mform->setHelpButton('displayattemptstatus', array('displayattemptstatus',get_string('displayattemptstatus', 'scorm'), 'scorm')); + $mform->setDefault('displayattemptstatus', 1); + +// Display course structure + $mform->addElement('selectyesno', 'displaycoursestructure', get_string('displaycoursestructure', 'scorm')); + $mform->setHelpButton('displaycoursestructure', array('displaycoursestructure',get_string('displaycoursestructure', 'scorm'), 'scorm')); + $mform->setDefault('displaycoursestructure', 1); + +// Force completed + $mform->addElement('selectyesno', 'forcecompleted', get_string('forcecompleted', 'scorm')); + $mform->setHelpButton('forcecompleted', array('forcecompleted',get_string('forcecompleted', 'scorm'), 'scorm')); + $mform->setDefault('forcecompleted', 0); + $mform->setAdvanced('forcecompleted'); + +// Force new attempt + $mform->addElement('selectyesno', 'forcenewattempt', get_string('forcenewattempt', 'scorm')); + $mform->setHelpButton('forcenewattempt', array('forcenewattempt',get_string('forcenewattempt', 'scorm'), 'scorm')); + $mform->setDefault('forcenewattempt', 0); + $mform->setAdvanced('forcenewattempt'); + +// Last attempt lock - lock the enter button after the last available attempt has been made + $mform->addElement('selectyesno', 'lastattemptlock', get_string('lastattemptlock', 'scorm')); + $mform->setHelpButton('lastattemptlock', array('lastattemptlock',get_string('lastattemptlock', 'scorm'), 'scorm')); + $mform->setDefault('lastattemptlock', 0); + $mform->setAdvanced('lastattemptlock'); + // What Grade $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'), $SCORM_WHAT_GRADE); $mform->disabledIf('whatgrade', 'maxattempt','eq',1); diff --git a/mod/scorm/version.php b/mod/scorm/version.php index 3abb85dc7348f..febd804a2aebf 100755 --- a/mod/scorm/version.php +++ b/mod/scorm/version.php @@ -10,7 +10,7 @@ // catch up now, so until 27th October please only increment in very tiny steps // in HEAD, until we get past that date.. -$module->version = 2008090304; // The (date) version of this module +$module->version = 2008090305; // The (date) version of this module $module->requires = 2008090108; // The version of Moodle that is required $module->cron = 300; // How often should cron check this module (seconds)? diff --git a/mod/scorm/view.php b/mod/scorm/view.php index 1cfc00d25ce25..4ccdc3c579804 100755 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -82,7 +82,11 @@ // Print the main part of the page print_heading(format_string($scorm->name)); - print_box(format_text($scorm->summary), 'generalbox', 'intro'); + $attemptstatus = ''; + if($scorm->displayattemptstatus == 1) { + $attemptstatus = scorm_get_attempt_status($USER,$scorm); + } + print_simple_box(format_text($scorm->summary).$attemptstatus, 'center', '70%', '', 5, 'generalbox', 'intro'); scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm); print_footer($course); ?>