MLD-9506 Corrected update_final_grades() in grade_item, which was updating the grade_raw table

instead of grade_final. Made a few other adjustments.
This commit is contained in:
nicolasconnault 2007-04-30 05:25:19 +00:00
parent e7e3f50fc2
commit 869807d8e4
5 changed files with 44 additions and 14 deletions

View File

@ -50,6 +50,18 @@ class grade_grades_final extends grade_object {
*/
var $userid;
/**
* The value of the grade.
* @var float $gradevalue
*/
var $gradevalue;
/**
* The scale of this grade.
* @var int $gradescale
*/
var $gradescale;
/**
* Date until which to hide this grade_item. If null, 0 or false, grade_item is not hidden. Hiding prevents viewing.
* @var int $hidden

View File

@ -156,8 +156,7 @@ class grade_grades_raw extends grade_object {
return true;
} else {
return false;
}
}
}
}

View File

@ -241,13 +241,30 @@ class grade_item extends grade_object {
* @return mixed An array of all final_grades (stdClass objects) for this grade_item, or a single final_grade.
*/
function get_final($userid=NULL) {
$grade_final = null;
if (!empty($userid)) {
$grade_final = get_record('grade_grades_final', 'itemid', $this->id, 'userid', $userid);
} else {
$grade_final = get_records('grade_grades_final', 'itemid', $this->id);
if (empty($this->grade_grades_final)) {
$this->load_final();
}
return $grade_final;
$grade_final_array = null;
if (!empty($userid)) {
$f = get_record('grade_grades_final', 'itemid', $this->id, 'userid', $userid);
$grade_final_array[$f->userid] = new grade_grades_final($f);
} else {
$grade_final_array = $this->grade_grades_final;
}
return $grade_final_array;
}
/**
* Loads all the grade_grades_final objects for this grade_item from the DB into grade_item::$grade_grades_final array.
* @return array grade_grades_final objects
*/
function load_final() {
$grade_final_array = get_records('grade_grades_final', 'itemid', $this->id);
foreach ($grade_final_array as $f) {
$this->grade_grades_final[$f->userid] = new grade_grades_final($f);
}
return $this->grade_grades_final;
}
/**
@ -342,7 +359,7 @@ class grade_item extends grade_object {
}
/**
* Performs the necessary calculations on the grades_raw referenced by this grade_item,
* Performs the necessary calculations on the grades_final referenced by this grade_item,
* and stores the results in grade_grades_final. Performs this for only one userid if
* requested. Also resets the needs_update flag once successfully performed.
*
@ -352,14 +369,14 @@ class grade_item extends grade_object {
* @return boolean Success or failure
*/
function update_final_grade($userid=NULL, $howmodified='manual', $note=NULL) {
if (empty($this->grade_grades_raw)) {
$this->load_raw();
if (empty($this->grade_grades_final)) {
$this->load_final();
}
// TODO implement parsing of formula and calculation MDL-9643
foreach ($this->grade_grades_raw as $r) {
foreach ($this->grade_grades_final as $f) {
$newgradevalue = 0; // TODO replace '0' with calculated value
$r->update($newgradevalue, $howmodified, $note);
$f->update($newgradevalue, $howmodified, $note);
}
return true;

View File

@ -41,6 +41,7 @@ require_once($CFG->libdir . '/grade/grade_category.php');
require_once($CFG->libdir . '/grade/grade_item.php');
require_once($CFG->libdir . '/grade/grade_calculation.php');
require_once($CFG->libdir . '/grade/grade_grades_raw.php');
require_once($CFG->libdir . '/grade/grade_grades_final.php');
/**
* Extracts from the gradebook all the grade items attached to the calling object.

View File

@ -660,7 +660,8 @@ class gradelib_test extends UnitTestCase {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'get_final'));
$final_grade = $grade_item->get_final($this->userid);
$final_grades = $grade_item->get_final($this->userid);
$final_grade = current($final_grades);
$this->assertEqual(1, count($final_grade));
$this->assertEqual($this->grade_grades_final[0]->gradevalue, $final_grade->gradevalue);
}