Permalink
Browse files

SCORM MDL-21568 - use correct storing of grading method - remove old …

…references to bad calls. thanks to Bruce Cota for report/patch - merged from HEAD
  • Loading branch information...
1 parent 119fff5 commit d29c03772555530b197753d2859b19348bc5f0fe @danmarsden danmarsden committed Jul 8, 2010
Showing with 20 additions and 18 deletions.
  1. +16 −1 mod/scorm/db/upgrade.php
  2. +0 −2 mod/scorm/lib.php
  3. +2 −12 mod/scorm/locallib.php
  4. +1 −2 mod/scorm/mod_form.php
  5. +1 −1 mod/scorm/version.php
View
@@ -300,9 +300,24 @@ function xmldb_scorm_upgrade($oldversion=0) {
if (!field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'grademethod');
$result = $result && add_field($table, $field);
+ /// fix bad usage of whatgrade/grading method.
+ $scorms = get_records('scorm');
@mudrd8mz

mudrd8mz Jul 16, 2010

Member

Here must go
if (is_array($scorms))

+ foreach ($scorms as $scorm) {
@mudrd8mz

mudrd8mz Jul 16, 2010

Member

Here must go
if (is_array($scorms))

+ $scorm->whatgrade = $scorm->grademethod/10;
+ update_record('scorm', $scorm);
+ }
+ set_config('whatgradefixed', '1', 'scorm'); //set this so that when upgrade to Moodle 2.0 we don't do this again.
}
}
-
+ if ($result && $oldversion < 2007110503) {
+ /// fix bad usage of whatgrade/grading method
+ $scorms = get_records('scorm');
@mudrd8mz

mudrd8mz Jul 16, 2010

Member

Here must go
if (is_array($scorms))

+ foreach ($scorms as $scorm) {
+ $scorm->grademethod = $scorm->grademethod%10;
+ update_record('scorm', $scorm);
+ }
+ set_config('grademethodfixed', '1', 'scorm'); //set this so that when upgrade to Moodle 2.0 we don't do this again.
+ }
//===== 1.9.0 upgrade line ======//
View
@@ -40,7 +40,6 @@ function scorm_add_instance($scorm) {
if (!isset($scorm->whatgrade)) {
$scorm->whatgrade = 0;
}
- $scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod;
$id = insert_record('scorm', $scorm);
@@ -108,7 +107,6 @@ function scorm_update_instance($scorm) {
if (!isset($scorm->whatgrade)) {
$scorm->whatgrade = 0;
}
- $scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod;
// Check if scorm manifest needs to be reparsed
if ($scorm->parse == 1) {
View
@@ -320,7 +320,6 @@ function scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value) {
if (strstr($element, '.score.raw') ||
(($element == 'cmi.core.lesson_status' || $element == 'cmi.completion_status') && ($track->value == 'completed' || $track->value == 'passed'))) {
$scorm = get_record('scorm', 'id', $scormid);
- $grademethod = $scorm->grademethod % 10;
include_once($CFG->dirroot.'/mod/scorm/lib.php');
scorm_update_grades($scorm, $userid);
}
@@ -441,11 +440,6 @@ function scorm_grade_user_attempt($scorm, $userid, $attempt=1, $time=false) {
return NULL;
}
- // this treatment is necessary as the whatgrade field was not in the DB
- // and so whatgrade and grademethod are combined in grademethod 10s are whatgrade
- // and 1s are grademethod
- $grademethod = $scorm->grademethod % 10;
-
foreach ($scoes as $sco) {
if ($userdata = scorm_get_tracks($sco->id, $userid, $attempt)) {
if (($userdata->status == 'completed') || ($userdata->status == 'passed')) {
@@ -463,7 +457,7 @@ function scorm_grade_user_attempt($scorm, $userid, $attempt=1, $time=false) {
}
}
}
- switch ($grademethod) {
+ switch ($scorm->grademethod) {
case GRADEHIGHEST:
$score = $attemptscore->max;
break;
@@ -496,18 +490,14 @@ function scorm_grade_user_attempt($scorm, $userid, $attempt=1, $time=false) {
}
function scorm_grade_user($scorm, $userid, $time=false) {
- // this treatment is necessary as the whatgrade field was not in the DB
- // and so whatgrade and grademethod are combined in grademethod 10s are whatgrade
- // and 1s are grademethod
- $whatgrade = intval($scorm->grademethod / 10);
// insure we dont grade user beyond $scorm->maxattempt settings
$lastattempt = scorm_get_last_attempt($scorm->id, $userid);
if($scorm->maxattempt != 0 && $lastattempt >= $scorm->maxattempt){
$lastattempt = $scorm->maxattempt;
}
- switch ($whatgrade) {
+ switch ($scorm->whatgrade) {
case FIRSTATTEMPT:
return scorm_grade_user_attempt($scorm, $userid, 1, $time);
break;
View
@@ -192,8 +192,7 @@ function data_preprocessing(&$default_values) {
}
}
if (isset($default_values['grademethod'])) {
- $default_values['whatgrade'] = intval($default_values['grademethod'] / 10);
- $default_values['grademethod'] = $default_values['grademethod'] % 10;
+ $default_values['grademethod'] = intval($default_values['grademethod']);
}
if (isset($default_value['width']) && (strpos($default_value['width'],'%') === false) && ($default_value['width'] <= 100)) {
$default_value['width'] .= '%';
View
@@ -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 = 2007110502; // The (date) version of this module
+$module->version = 2007110503; // The (date) version of this module
$module->requires = 2007101509; // The version of Moodle that is required
$module->cron = 300; // How often should cron check this module (seconds)?

0 comments on commit d29c037

Please sign in to comment.