$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',
$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';
* @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;
// 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=?
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();
}
} 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;
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;
<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"/>
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;
}
// 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