MDL-18272, MDL-18271: Conditional availability - grade condition to use percentages not raw grades; use wording rather than >= symbol in form because (apparently) teachers are functionally innumerate. ;)

This commit is contained in:
sam_marshall
2009-02-18 17:50:13 +00:00
parent b9061f5768
commit 7556422816
6 changed files with 51 additions and 17 deletions
+2 -1
View File
@@ -414,8 +414,9 @@ class moodleform_mod extends moodleform {
$grouparray[] =& $mform->createElement('select','conditiongradeitemid','',$gradeoptions);
$grouparray[] =& $mform->createElement('static', '', '',' '.get_string('grade_atleast','condition').' ');
$grouparray[] =& $mform->createElement('text', 'conditiongrademin','',array('size'=>3));
$grouparray[] =& $mform->createElement('static', '', '',' '.get_string('grade_upto','condition').' ');
$grouparray[] =& $mform->createElement('static', '', '','% '.get_string('grade_upto','condition').' ');
$grouparray[] =& $mform->createElement('text', 'conditiongrademax','',array('size'=>3));
$grouparray[] =& $mform->createElement('static', '', '','%');
$mform->setType('conditiongrademin',PARAM_FLOAT);
$mform->setType('conditiongrademax',PARAM_FLOAT);
$group = $mform->createElement('group','conditiongradegroup',
+2 -2
View File
@@ -11,8 +11,8 @@ $string['completion_pass']=' must be complete with pass grade';
$string['completion_fail']=' must be complete with fail grade';
$string['configenableavailability']='When enabled, this lets you set conditions (based on date, grade, or completion) that control whether an activity is available.';
$string['enableavailability']='Enable conditional availability';
$string['grade_atleast']='must be ≥';
$string['grade_upto']='and <';
$string['grade_atleast']='must be at least';
$string['grade_upto']='and less than';
$string['gradecondition']='Grade condition';
$string['completioncondition']='Activity completion condition';
$string['help_conditiondates']='available dates';
+23 -11
View File
@@ -439,8 +439,9 @@ WHERE
* @param bool $grabthelot If true, grabs all scores for current user on
* this course, so that later ones come from cache
* @param int $userid Set if requesting grade for a different user (does
* not use cache)
* @return float Grade score, or false if user does not have a grade yet
* not use cache)
* @return float Grade score as a percentage in range 0-100 (e.g. 100.0
* or 37.21), or false if user does not have a grade yet
*/
private function get_cached_grade_score($gradeitemid,$grabthelot=false,$userid=0) {
global $USER, $DB, $SESSION;
@@ -455,7 +456,7 @@ WHERE
// Get all grades for the current course
$rs=$DB->get_recordset_sql("
SELECT
gi.id,gg.finalgrade
gi.id,gg.finalgrade,gg.rawgrademin,gg.rawgrademax
FROM
{grade_items} gi
LEFT JOIN {grade_grades} gg ON gi.id=gg.itemid AND gg.userid=?
@@ -464,8 +465,11 @@ WHERE
foreach($rs as $record) {
$SESSION->gradescorecache[$record->id]=
is_null($record->finalgrade)
// No grade = false
? false
: $record->finalgrade;
// Otherwise convert grade to percentage
: (($record->finalgrade - $record->rawgrademin) * 100) /
($record->rawgrademax - $record->rawgrademin);
}
$rs->close();
@@ -477,11 +481,14 @@ WHERE
}
} else {
// Just get current grade
$score=$DB->get_field('grade_grades','finalgrade',array(
$record = $DB->get_record('grade_grades', array(
'userid'=>$USER->id,'itemid'=>$gradeitemid));
// Treat the case where row exists but is null, same as
// case where row doesn't exist
if(is_null($score)) {
if ($record && !is_null($record->finalgrade)) {
$score = (($record->finalgrade - $record->rawgrademin) * 100) /
($record->rawgrademax - $record->rawgrademin);
} else {
// Treat the case where row exists but is null, same as
// case where row doesn't exist
$score=false;
}
$SESSION->gradescorecache[$gradeitemid]=$score;
@@ -490,9 +497,14 @@ WHERE
return $SESSION->gradescorecache[$gradeitemid];
} else {
// Not the current user, so request the score individually
$score=$DB->get_field('grade_grades','finalgrade',array(
'userid'=>$userid,'itemid'=>$gradeitemid));
if($score===null) {
$record = $DB->get_record('grade_grades', array(
'userid'=>$userid, 'itemid'=>$gradeitemid));
if ($record && !is_null($record->finalgrade)) {
$score = (($record->finalgrade - $record->rawgrademin) * 100) /
($record->rawgrademax - $record->rawgrademin);
} else {
// Treat the case where row exists but is null, same as
// case where row doesn't exist
$score=false;
}
return $score;
+2 -2
View File
@@ -210,8 +210,8 @@
<FIELD NAME="sourcecmid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="If this condition is based on completion of another activity, then this is the course-module ID of that activity. Otherwise null." PREVIOUS="coursemoduleid" NEXT="requiredcompletion"/>
<FIELD NAME="requiredcompletion" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="If this condition is on a module's completion, then this should be set to the required completion state. Otherwise null. Suitable values are 1 = completed, 2 = completed-passed, 3 = completed-failed." PREVIOUS="sourcecmid" NEXT="gradeitemid"/>
<FIELD NAME="gradeitemid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="If this condition is based on a gradebook score, the item ID is given here (and the item will now not be available until a value is achieved for that grade). Otherwise null." PREVIOUS="requiredcompletion" NEXT="grademin"/>
<FIELD NAME="grademin" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="If set, this is the minimum grade that must be reached (greater than or equal) in order for this module to appear. Otherwise null." PREVIOUS="gradeitemid" NEXT="grademax"/>
<FIELD NAME="grademax" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="If set, this is the maximum grade that users must be below (less than) in order to display this item. Otherwise null." PREVIOUS="grademin"/>
<FIELD NAME="grademin" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="If set, this is the minimum grade percentage that must be reached (greater than or equal) in order for this module to appear. Otherwise null." PREVIOUS="gradeitemid" NEXT="grademax"/>
<FIELD NAME="grademax" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="If set, this is the maximum grade percentage that users must be below (less than) in order to display this item. Otherwise null." PREVIOUS="grademin"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="coursemoduleid"/>
+21
View File
@@ -1438,6 +1438,27 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint($result, 2009012901);
}
if ($result && $oldversion < 2009021800) {
// Converting format of grade conditions, if any exist, to percentages.
$DB->execute("
UPDATE {course_modules_availability} SET grademin=(
SELECT 100.0*({course_modules_availability}.grademin-gi.grademin)
/(gi.grademax-gi.grademin)
FROM {grade_items} gi
WHERE gi.id={course_modules_availability}.gradeitemid)
WHERE gradeitemid IS NOT NULL AND grademin IS NOT NULL");
$DB->execute("
UPDATE {course_modules_availability} SET grademax=(
SELECT 100.0*({course_modules_availability}.grademax-gi.grademin)
/(gi.grademax-gi.grademin)
FROM {grade_items} gi
WHERE gi.id={course_modules_availability}.gradeitemid)
WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
/// Main savepoint reached
upgrade_main_savepoint($result, 2009021800);
}
return $result;
}
+1 -1
View File
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
$version = 2009012901; // YYYYMMDD = date of the last version bump
$version = 2009021800; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20090218)'; // Human-friendly version name