From: nicolasconnault Date: Fri, 4 May 2007 09:04:40 +0000 (+0000) Subject: MDL-9506 Fixed some small issues. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2b4f19a9ce3f7913df632b4cf386bf3d2a0d0999;p=moodle.git MDL-9506 Fixed some small issues. --- diff --git a/lib/grade/grade_grades_raw.php b/lib/grade/grade_grades_raw.php index 64d5e20a28..70fc5b04f1 100644 --- a/lib/grade/grade_grades_raw.php +++ b/lib/grade/grade_grades_raw.php @@ -108,13 +108,21 @@ class grade_grades_raw extends grade_object { */ function grade_grades_raw($params=NULL, $fetch=true) { $this->grade_object($params, $fetch); + $this->load_text(); + $this->load_scale(); + } + + /** + * Instantiates a grade_scale object whose data is retrieved from the DB, + * if this raw grade's scaleid variable is set. + * @return object grade_scale + */ + function load_scale() { if (!empty($this->scaleid)) { - $this->scale = new grade_scale(array('id' => $this->scaleid)); + $this->scale = grade_scale::fetch('id', $this->scaleid); $this->scale->load_items(); - } - - // Load text object - $this->load_text(); + } + return $this->scale; } /** @@ -125,6 +133,7 @@ class grade_grades_raw extends grade_object { if (!empty($this->id)) { $this->text = grade_grades_text::fetch('gradesid', $this->id); } + return $this->text; } /** @@ -145,7 +154,8 @@ class grade_grades_raw extends grade_object { foreach ($object as $param => $value) { $this->$param = $value; } - + + $this->load_scale(); $this->load_text(); return $this; } else { @@ -204,9 +214,8 @@ class grade_grades_raw extends grade_object { $oldgrade = $this->gradevalue; $this->gradevalue = $newgrade; - // Update this scaleid if it has changed (use the largest integer (most recent)) - if ($this->scale->id != $this->scaleid) { - $this->scaleid = max($this->scale->id, $this->scaleid); + if (!empty($this->scale->id)) { + $this->scaleid = $this->scale->id; } $result = parent::update(); diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 14ecd78961..959906683f 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -119,9 +119,15 @@ class grade_item extends grade_object { * @var object $scale */ var $scale; + + /** + * The id of the optional grade_outcome associated with this grade_item. + * @var int $outcomeid + */ + var $outcomeid; /** - * The Outcome this grade is associated with, if applicable. + * The grade_outcome this grade is associated with, if applicable. * @var object $outcome */ var $outcome; @@ -193,10 +199,48 @@ class grade_item extends grade_object { */ function grade_item($params=NULL, $fetch=true) { $this->grade_object($params, $fetch); + $this->load_scale(); + $this->load_outcome(); + } + + /** + * Instantiates a grade_scale object whose data is retrieved from the DB, + * if this item's scaleid variable is set. + * @return object grade_scale + */ + function load_scale() { if (!empty($this->scaleid)) { - $this->scale = new grade_scale(array('id' => $this->scaleid)); + $this->scale = grade_scale::fetch('id', $this->scaleid); $this->scale->load_items(); + } + return $this->scale; + } + + /** + * Instantiates a grade_outcome object whose data is retrieved from the DB, + * if this item's outcomeid variable is set. + * @return object grade_outcome + */ + function load_outcome() { + if (!empty($this->outcomeid)) { + $this->outcome = grade_outcome::fetch('id', $this->outcomeid); + } + return $this->outcome; + } + + /** + * In addition to update() as defined in grade_object, handle the grade_outcome and grade_scale objects. + */ + function update() { + if (!empty($this->outcome->id)) { + $this->outcomeid = $this->outcome->id; + } + + if (!empty($this->scale->id)) { + $this->scaleid = $this->scale->id; } + + return parent::update(); } /** @@ -217,6 +261,9 @@ class grade_item extends grade_object { foreach ($grade_item as $param => $value) { $this->$param = $value; } + + $this->load_scale(); + $this->load_outcome(); return $this; } else { $grade_item = new grade_item($grade_item);