From 398a160d4d5bad7bea4d3b67f1b398c8b3e82bf2 Mon Sep 17 00:00:00 2001 From: skodak Date: Wed, 22 Apr 2009 21:03:38 +0000 Subject: [PATCH] MDL-18934 removed legacy grading support --- grade/edit/tree/index.php | 7 -- lib/gradelib.php | 154 +------------------------------------- mod/upgrade.txt | 1 + 3 files changed, 3 insertions(+), 159 deletions(-) diff --git a/grade/edit/tree/index.php b/grade/edit/tree/index.php index 19406c28a2..6a3b5edfcd 100644 --- a/grade/edit/tree/index.php +++ b/grade/edit/tree/index.php @@ -157,10 +157,6 @@ switch ($action) { //TODO: implement autosorting based on order of mods on course page, categories first, manual items last break; - case 'synclegacy': - grade_grab_legacy_grades($course->id); - redirect($returnurl); - case 'move': if ($eid and confirm_sesskey()) { $moveafter = required_param('moveafter', PARAM_ALPHANUM); @@ -361,9 +357,6 @@ if ($moving) { } //print_single_button('index.php', array('id'=>$course->id, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get'); - echo "

"; - print_single_button('index.php', array('id'=>$course->id, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get'); - helpbutton('synclegacygrades', get_string('synclegacygrades', 'grades'), 'grade'); } echo ''; diff --git a/lib/gradelib.php b/lib/gradelib.php index dafb848f89..32388279d9 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -997,38 +997,6 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null) } } -/** - * For backwards compatibility with old third-party modules, this function can - * be used to import all grades from activities with legacy grading. - * @param int $courseid - */ -function grade_grab_legacy_grades($courseid) { - global $CFG; - - if (!$mods = get_list_of_plugins('mod') ) { - print_error('nomodules', 'debug'); - } - - foreach ($mods as $mod) { - if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it - continue; - } - - $fullmod = $CFG->dirroot.'/mod/'.$mod; - - // include the module lib once - if (file_exists($fullmod.'/lib.php')) { - include_once($fullmod.'/lib.php'); - // look for modname_grades() function - old gradebook pulling function - // if present sync the grades with new grading system - $gradefunc = $mod.'_grades'; - if (function_exists($gradefunc)) { - grade_grab_course_grades($courseid, $mod); - } - } - } -} - /** * Refetches data from all course activities * @param int $courseid @@ -1081,7 +1049,7 @@ function grade_grab_course_grades($courseid, $modname=null) { } /** - * Force full update of module grades in central gradebook - works for both legacy and converted activities. + * Force full update of module grades in central gradebook * @param object $modinstance object with extra cmidnumber and modname property * @return boolean success */ @@ -1095,64 +1063,10 @@ function grade_update_mod_grades($modinstance, $userid=0) { } include_once($fullmod.'/lib.php'); - // does it use legacy grading? - $gradefunc = $modinstance->modname.'_grades'; $updategradesfunc = $modinstance->modname.'_update_grades'; $updateitemfunc = $modinstance->modname.'_grade_item_update'; - if (function_exists($gradefunc)) { - - // legacy module - not yet converted - if ($oldgrades = $gradefunc($modinstance->id)) { - - $grademax = $oldgrades->maxgrade; - $scaleid = NULL; - if (!is_numeric($grademax)) { - // scale name is provided as a string, try to find it - if (!$scale = $DB->get_record('scale', array('name'=>$grademax))) { - debugging('Incorrect scale name! name:'.$grademax); - return false; - } - $scaleid = $scale->id; - } - - if (!$grade_item = grade_get_legacy_grade_item($modinstance, $grademax, $scaleid)) { - debugging('Can not get/create legacy grade item!'); - return false; - } - - if (!empty($oldgrades->grades)) { - $grades = array(); - - foreach ($oldgrades->grades as $uid=>$usergrade) { - if ($userid and $uid != $userid) { - continue; - } - $grade = new object(); - $grade->userid = $uid; - - if ($usergrade == '-') { - // no grade - $grade->rawgrade = null; - - } else if ($scaleid) { - // scale in use, words used - $gradescale = explode(",", $scale->scale); - $grade->rawgrade = array_search($usergrade, $gradescale) + 1; - - } else { - // good old numeric value - $grade->rawgrade = $usergrade; - } - $grades[] = $grade; - } - - grade_update('legacygrab', $grade_item->courseid, $grade_item->itemtype, $grade_item->itemmodule, - $grade_item->iteminstance, $grade_item->itemnumber, $grades); - } - } - - } else if (function_exists($updategradesfunc) and function_exists($updateitemfunc)) { + if (function_exists($updategradesfunc) and function_exists($updateitemfunc)) { //new grading supported, force updating of grades $updateitemfunc($modinstance); $updategradesfunc($modinstance, $userid); @@ -1164,70 +1078,6 @@ function grade_update_mod_grades($modinstance, $userid=0) { return true; } -/** - * Get and update/create grade item for legacy modules. - */ -function grade_get_legacy_grade_item($modinstance, $grademax, $scaleid) { - - // does it already exist? - if ($grade_items = grade_item::fetch_all(array('courseid'=>$modinstance->course, 'itemtype'=>'mod', 'itemmodule'=>$modinstance->modname, 'iteminstance'=>$modinstance->id, 'itemnumber'=>0))) { - if (count($grade_items) > 1) { - debugging('Multiple legacy grade_items found.'); - return false; - } - - $grade_item = reset($grade_items); - - if (is_null($grademax) and is_null($scaleid)) { - $grade_item->gradetype = GRADE_TYPE_NONE; - - } else if ($scaleid) { - $grade_item->gradetype = GRADE_TYPE_SCALE; - $grade_item->scaleid = $scaleid; - $grade_item->grademin = 1; - - } else { - $grade_item->gradetype = GRADE_TYPE_VALUE; - $grade_item->grademax = $grademax; - $grade_item->grademin = 0; - } - - $grade_item->itemname = $modinstance->name; - $grade_item->idnumber = $modinstance->cmidnumber; - - $grade_item->update(); - - return $grade_item; - } - - // create new one - $params = array('courseid' =>$modinstance->course, - 'itemtype' =>'mod', - 'itemmodule' =>$modinstance->modname, - 'iteminstance'=>$modinstance->id, - 'itemnumber' =>0, - 'itemname' =>$modinstance->name, - 'idnumber' =>$modinstance->cmidnumber); - - if (is_null($grademax) and is_null($scaleid)) { - $params['gradetype'] = GRADE_TYPE_NONE; - - } else if ($scaleid) { - $params['gradetype'] = GRADE_TYPE_SCALE; - $params['scaleid'] = $scaleid; - $grade_item->grademin = 1; - } else { - $params['gradetype'] = GRADE_TYPE_VALUE; - $params['grademax'] = $grademax; - $params['grademin'] = 0; - } - - $grade_item = new grade_item($params); - $grade_item->insert(); - - return $grade_item; -} - /** * Remove grade letters for given context * @param object $context diff --git a/mod/upgrade.txt b/mod/upgrade.txt index 83330a99a9..811ca58576 100644 --- a/mod/upgrade.txt +++ b/mod/upgrade.txt @@ -13,6 +13,7 @@ required changes in code: * rewrite backup/restore * rewrite trusstext support - new db table columns needed * migrade all module features from mod_edit.php form to lib.php/modulename_supports() function +* implement new gradebook support (legacy 1.8.x grading not supported anymore) optional - no changes needed in older code: * portfolio support -- 2.39.5