]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9506 Added grade_outcome.php. Also added unit test for creation of log in history...
authornicolasconnault <nicolasconnault>
Thu, 3 May 2007 08:51:48 +0000 (08:51 +0000)
committernicolasconnault <nicolasconnault>
Thu, 3 May 2007 08:51:48 +0000 (08:51 +0000)
lib/grade/grade_grades_raw.php
lib/grade/grade_outcome.php [new file with mode: 0644]
lib/grade/grade_scale.php
lib/gradelib.php
lib/simpletest/testgradelib.php

index 1d9d8b37e856fd8e16b868af7ad92c4662f70e24..f79a07b46fa23be76f4de90287d6c8c751d5c098 100644 (file)
@@ -109,7 +109,7 @@ class grade_grades_raw extends grade_object {
 
     /**
      * Finds and returns a grade_grades_raw object based on 1-3 field values.
-     *
+     * @static
      * @param string $field1
      * @param string $value1
      * @param string $field2
@@ -119,8 +119,7 @@ class grade_grades_raw extends grade_object {
      * @param string $fields
      * @return object grade_category object or false if none found.
      */
-    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*")
-    { 
+    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { 
         if ($object = get_record('grade_grades_raw', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
             if (isset($this) && get_class($this) == 'grade_grades_raw') {
                 foreach ($object as $param => $value) {
diff --git a/lib/grade/grade_outcome.php b/lib/grade/grade_outcome.php
new file mode 100644 (file)
index 0000000..9567c61
--- /dev/null
@@ -0,0 +1,94 @@
+<?php // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 2001-2003  Martin Dougiamas  http://dougiamas.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once('grade_object.php');
+
+/**
+ * Class representing a grade outcome. It is responsible for handling its DB representation,
+ * modifying and returning its metadata.
+ */
+class grade_outcome extends grade_object {
+    /**
+     * DB Table (used by grade_object).
+     * @var string $table
+     */
+    var $table = 'grade_outcomes';
+    
+    /**
+     * Array of class variables that are not part of the DB table fields
+     * @var array $nonfields
+     */
+    var $nonfields = array('table', 'nonfields', 'scale');
+  
+    /**
+     * The course this outcome belongs to.
+     * @var int $courseid
+     */
+    var $courseid;
+    
+    /**
+     * The shortname of the outcome.
+     * @var string $shortname
+     */
+    var $shortname;
+
+    /**
+     * The fullname of the outcome.
+     * @var string $fullname
+     */
+    var $fullname;
+
+    /**
+     * A full grade_scale object referenced by $this->scaleid.
+     * @var object $scale
+     */
+    var $scale;
+
+    /**
+     * The id of the scale referenced by this outcome.
+     * @var int $scaleid
+     */
+    var $scaleid;
+    
+    /**
+     * The userid of the person who last modified this outcome.
+     * @var int $usermodified
+     */
+    var $usermodified;
+    
+    /**
+     * Constructor. Extends the basic functionality defined in grade_object.
+     * @param array $params Can also be a standard object.
+     * @param boolean $fetch Wether or not to fetch the corresponding row from the DB.
+     */
+    function grade_grades_raw($params=NULL, $fetch=true) {
+        $this->grade_object($params, $fetch);
+        if (!empty($this->scaleid)) {
+            $this->scale = new grade_scale(array('id' => $this->scaleid));
+            $this->scale->load_items();
+        }
+    }
+}
+?>
index 4d5e4bc112f2eae64ee168dbe8df734cf664c6df..f5f56b3dbc4dbe364c4aa585c73ffdf740d10864 100644 (file)
@@ -26,7 +26,7 @@
 require_once('grade_object.php');
 
 /**
- * Class representing a grade item. It is responsible for handling its DB representation,
+ * Class representing a grade scale. It is responsible for handling its DB representation,
  * modifying and returning its metadata.
  */
 class grade_scale extends grade_object {
index bea775fe559f5ede157612a84c42828dedc9445e..f190c83f47979eb66bfaccf9c5ad65aed79f7f03 100644 (file)
@@ -47,6 +47,7 @@ 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');
 require_once($CFG->libdir . '/grade/grade_scale.php');
+require_once($CFG->libdir . '/grade/grade_outcome.php');
 
 /**
 * Extracts from the gradebook all the grade items attached to the calling object. 
index 9e9ab4dfad7f40e703204a05163cd98b88a7153b..733ecaa702a1526b7435ce5d6aa49ad803c7ebf6 100644 (file)
@@ -1044,6 +1044,33 @@ class gradelib_test extends UnitTestCase {
 
 // GRADE_CALCULATION OBJECT
 
+// GRADE_GRADES_RAW OBJECT
+    
+    function test_grade_raw_construct() {
+        
+    }
+
+    /**
+     * Make sure that an update of a grade_raw object also updates the history table.
+     */
+    function test_grade_raw_update_history() {
+        $grade_raw = new grade_grades_raw($this->grade_grades_raw[0]);
+        $oldgrade = $grade_raw->gradevalue;
+        $newgrade = 88;
+        $howmodified = 'manual';
+        $note = 'unittest editing grade manually';
+        $grade_raw->update($newgrade, $howmodified, $note);
+        
+        // Get last entry in the history log and check its attributes
+        $results = get_records('grade_history', 'itemid', $grade_raw->itemid, 'id DESC', '*', 0, 1);
+        $history_log = current($results);
+        $this->assertEqual($grade_raw->userid, $history_log->userid);
+        $this->assertEqual($oldgrade, $history_log->oldgrade);
+        $this->assertEqual($newgrade, $history_log->newgrade);
+        $this->assertEqual($howmodified, $history_log->howmodified);
+        $this->assertEqual($note, $history_log->note);
+    }
+
 // SCALE OBJECT
 
     function test_scale_constructor() {