force hotpot grades (pre Moodle 1.9 on 27th Mar 2008) to be updated:
(1) call "hotpot_updated_grades()" from db/upgrade.php
(2) fix typo in "hotpot_updated_grades()" - "s.id' should be "h.id"
(3) micro-increment version number to trigger the update
This commit is contained in:
+16
-23
@@ -1,21 +1,6 @@
|
||||
<?php //$Id$
|
||||
|
||||
// This file keeps track of upgrades to
|
||||
// the hotpot module
|
||||
//
|
||||
// Sometimes, changes between versions involve
|
||||
// alterations to database structures and other
|
||||
// major things that may break installations.
|
||||
//
|
||||
// The upgrade function in this file will attempt
|
||||
// to perform all the necessary actions to upgrade
|
||||
// your older installtion to the current version.
|
||||
//
|
||||
// If there's something it cannot do itself, it
|
||||
// will tell you what you need to do.
|
||||
//
|
||||
// The commands in here will all be database-neutral,
|
||||
// using the functions defined in lib/ddllib.php
|
||||
// This file keeps track of upgrades to the hotpot module
|
||||
|
||||
function xmldb_hotpot_upgrade($oldversion=0) {
|
||||
|
||||
@@ -23,14 +8,22 @@ function xmldb_hotpot_upgrade($oldversion=0) {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// And upgrade begins here. For each one, you'll need one
|
||||
/// block of code similar to the next one. Please, delete
|
||||
/// this comment lines once this file start handling proper
|
||||
/// upgrade code.
|
||||
// update hotpot grades from sites earlier than Moodle 1.9, 27th March 2008
|
||||
if ($result && $oldversion < 2007101509) {
|
||||
|
||||
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
|
||||
/// $result = result of "/lib/ddllib.php" function calls
|
||||
/// }
|
||||
// ensure "hotpot_update_grades" function is available
|
||||
require_once $CFG->dirroot.'/mod/hotpot/lib.php';
|
||||
|
||||
// disable display of debugging messages
|
||||
$db_debug_save = $db->debug;
|
||||
$db->debug = false;
|
||||
|
||||
notify('Processing hotpot grades, this may take a while if there are many hotpots...', 'notifysuccess');
|
||||
hotpot_update_grades();
|
||||
|
||||
// restore $db->debug
|
||||
$db->debug = $db_debug_save;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
+37
-27
@@ -1243,42 +1243,53 @@ function hotpot_get_user_grades($hotpot, $userid=0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update grades in central gradebook
|
||||
* this function is called from db/upgrade.php
|
||||
* it is initially called with no arguments, which forces it to get a list of all hotpots
|
||||
* it then iterates through the hotpots, calling itself to create a grade record for each hotpot
|
||||
*
|
||||
* @param object $hotpot null means all hotpots
|
||||
* @param int $userid specific user only, 0 mean all
|
||||
* @param int $userid specific user only, 0 means all users
|
||||
*/
|
||||
function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
|
||||
global $CFG;
|
||||
if (! function_exists('grade_update')) { //workaround for buggy PHP versions
|
||||
if (! function_exists('grade_update')) {
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
}
|
||||
if ($hotpot) {
|
||||
if ($grades = hotpot_get_user_grades($hotpot, $userid)) {
|
||||
hotpot_grade_item_update($hotpot, $grades);
|
||||
|
||||
} else if ($userid && $nullifnone) {
|
||||
$grade = new object();
|
||||
$grade->userid = $userid;
|
||||
$grade->rawgrade = null;
|
||||
hotpot_grade_item_update($hotpot, $grade);
|
||||
|
||||
} else {
|
||||
hotpot_grade_item_update($hotpot);
|
||||
}
|
||||
} else {
|
||||
$sql = "SELECT h.*, cm.idnumber as cmidnumber
|
||||
FROM {$CFG->prefix}hotpot h, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
||||
WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=s.id";
|
||||
if (is_null($hotpot)) {
|
||||
// update (=create) grades for all hotpots
|
||||
$sql = "
|
||||
SELECT h.*, cm.idnumber as cmidnumber
|
||||
FROM {$CFG->prefix}hotpot h, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
||||
WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=h.id"
|
||||
;
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
while ($hotpot = rs_fetch_next_record($rs)) {
|
||||
hotpot_update_grades($hotpot, 0, false);
|
||||
}
|
||||
rs_close($rs);
|
||||
}
|
||||
} else {
|
||||
// update (=create) grade for a single hotpot
|
||||
if ($grades = hotpot_get_user_grades($hotpot, $userid)) {
|
||||
hotpot_grade_item_update($hotpot, $grades);
|
||||
|
||||
} else if ($userid && $nullifnone) {
|
||||
// no grades for this user, but we must force the creation of a "null" grade record
|
||||
$grade = new object();
|
||||
$grade->userid = $userid;
|
||||
$grade->rawgrade = null;
|
||||
hotpot_grade_item_update($hotpot, $grade);
|
||||
|
||||
} else {
|
||||
// no grades and no userid
|
||||
hotpot_grade_item_update($hotpot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update/create grade item for given hotpot
|
||||
*
|
||||
@@ -1286,18 +1297,16 @@ function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
|
||||
* @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
|
||||
* @return object grade_item
|
||||
*/
|
||||
function hotpot_grade_item_update($hotpot, $grades=NULL) {
|
||||
function hotpot_grade_item_update($hotpot, $grades=null) {
|
||||
global $CFG;
|
||||
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
|
||||
if (! function_exists('grade_update')) {
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
}
|
||||
|
||||
$params = array('itemname' => $hotpot->name);
|
||||
if (array_key_exists('cmidnumber', $hotpot)) {
|
||||
//cmidnumber may not be always present
|
||||
$params['idnumber'] = $hotpot->cmidnumber;
|
||||
}
|
||||
|
||||
if ($hotpot->grade > 0) {
|
||||
$params['gradetype'] = GRADE_TYPE_VALUE;
|
||||
$params['grademax'] = $hotpot->grade;
|
||||
@@ -1306,9 +1315,9 @@ function hotpot_grade_item_update($hotpot, $grades=NULL) {
|
||||
} else {
|
||||
$params['gradetype'] = GRADE_TYPE_NONE;
|
||||
}
|
||||
|
||||
return grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, $grades, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete grade item for given hotpot
|
||||
*
|
||||
@@ -1317,9 +1326,10 @@ function hotpot_grade_item_update($hotpot, $grades=NULL) {
|
||||
*/
|
||||
function hotpot_grade_item_delete($hotpot) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
|
||||
return grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, NULL, array('deleted'=>1));
|
||||
if (! function_exists('grade_update')) {
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
}
|
||||
return grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, null, array('deleted'=>1));
|
||||
}
|
||||
|
||||
function hotpot_get_participants($hotpotid) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/// Code fragment to define the version of hotpot
|
||||
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
$module->version = 2007101509; // release date of this version (see note below)
|
||||
$module->version = 2007101510; // release date of this version (see note below)
|
||||
$module->release = 'v2.4.2'; // human-friendly version name (used in mod/hotpot/lib.php)
|
||||
$module->requires = 2007101509; // Requires this Moodle version
|
||||
$module->cron = 0; // period for cron to check this module (secs)
|
||||
|
||||
Reference in New Issue
Block a user