]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9506 Fixed some small issues.
authornicolasconnault <nicolasconnault>
Fri, 4 May 2007 09:04:40 +0000 (09:04 +0000)
committernicolasconnault <nicolasconnault>
Fri, 4 May 2007 09:04:40 +0000 (09:04 +0000)
lib/grade/grade_grades_raw.php
lib/grade/grade_item.php

index 64d5e20a2839b02ef744b45fb12a79c61629c24b..70fc5b04f14d4715882bce55cdf673a61eb28127 100644 (file)
@@ -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();
index 14ecd78961deec03ce024fcaaa630252d8efde8f..959906683f4d5f02d22c6fde2de8382d37602676 100644 (file)
@@ -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);