]> git.mjollnir.org Git - moodle.git/commitdiff
MLD-9506 Grade_grades_raw object now infers grademax and grademin from scale, if...
authornicolasconnault <nicolasconnault>
Wed, 9 May 2007 08:56:08 +0000 (08:56 +0000)
committernicolasconnault <nicolasconnault>
Wed, 9 May 2007 08:56:08 +0000 (08:56 +0000)
lib/grade/grade_grades_raw.php
lib/simpletest/grade/simpletest/testgraderaw.php
lib/simpletest/testgradelib.php

index eeceef3e32d9227433761e1c95d7eb88c0d0be34..3b8754c5607b547394b0038ddb43624a25d483df 100644 (file)
@@ -206,6 +206,9 @@ class grade_grades_raw extends grade_object {
         
         if (!empty($this->scale->id)) {
             $this->scaleid = $this->scale->id;
+            $this->grademin = 0;
+            $this->scale->load_items();
+            $this->grademax = count($this->scale->scale_items);
         }
 
         $result = parent::update();
@@ -226,6 +229,23 @@ class grade_grades_raw extends grade_object {
             return false;
         } 
     }
+    
+    /**
+     * In addition to perform parent::insert(), this infers the grademax from the scale if such is given, and
+     * sets grademin to 0 if scale is given.
+     * @return int ID of the new grades_grade_raw record.
+     */
+    function insert() {
+        // Retrieve scale and infer grademax from it
+        if (!empty($this->scaleid)) {
+            $this->load_scale();
+            $this->scale->load_items();
+            $this->grademax = count ($this->scale->scale_items);
+            $this->grademin = 0;
+        }
+
+        return parent::insert();
+    }
 }
 
 ?>
index d69a70f879bda829ba443e1c82cafe0558caf155..d918915da30e854759d11b9619a8353b16092a9f 100755 (executable)
@@ -67,6 +67,19 @@ class grade_raw_test extends gradelib_test {
         $this->assertEqual($grade_grades_raw->id, $last_grade_grades_raw->id + 1);
         $this->assertFalse(empty($grade_grades_raw->timecreated));
         $this->assertFalse(empty($grade_grades_raw->timemodified));
+
+        // try a scale raw grade
+        $grade_grades_raw = new grade_grades_raw();
+        
+        $grade_grades_raw->itemid = $this->grade_items[0]->id;
+        $grade_grades_raw->userid = 1;
+        $grade_grades_raw->gradevalue = 6;
+        $grade_grades_raw->scaleid = $this->scale[0]->id;
+
+        $grade_grades_raw->insert();
+
+        $this->assertEqual(7, $grade_grades_raw->grademax);
+        $this->assertEqual(0, $grade_grades_raw->grademin); 
     }
 
     function test_grade_grades_raw_update() {
index eb9389e2d1394ee15c862be9185eaf9611ec8d3a..67241456b23d86a66aafa801248003ef50eb9ddb 100644 (file)
@@ -196,7 +196,8 @@ class gradelib_test extends UnitTestCase {
 
             /// Adding fields to table grade_grades_text
             $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
-            $table->addFieldInfo('gradesid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
+            $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
+            $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
             $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
             $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
@@ -207,7 +208,8 @@ class gradelib_test extends UnitTestCase {
 
             /// Adding keys to table grade_grades_text
             $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
-            $table->addKeyInfo('gradesid', XMLDB_KEY_FOREIGN, array('gradesid'), 'grade_grades_raw', array('id'));
+            $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
+            $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
             $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
 
             /// Launch create table for grade_grades_text