]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10233 improved static factory methods of grade obejcts fetch() and fetch_all...
authorskodak <skodak>
Sun, 24 Jun 2007 22:26:33 +0000 (22:26 +0000)
committerskodak <skodak>
Sun, 24 Jun 2007 22:26:33 +0000 (22:26 +0000)
29 files changed:
grade/export/grade_export_form.php
grade/export/lib.php
grade/export/txt/grade_export_txt_form.php
grade/export/txt/index.php
grade/import/grade_import_form.php
lib/db/install.xml
lib/db/upgrade.php
lib/grade/grade_category.php
lib/grade/grade_grades.php
lib/grade/grade_grades_text.php
lib/grade/grade_history.php
lib/grade/grade_item.php
lib/grade/grade_object.php
lib/grade/grade_outcome.php
lib/grade/grade_scale.php
lib/grade/grade_tree.php
lib/gradelib.php
lib/simpletest/fixtures/gradetest.php
lib/simpletest/grade/simpletest/testgradecategory.php
lib/simpletest/grade/simpletest/testgradegrades.php
lib/simpletest/grade/simpletest/testgradegradestext.php [moved from lib/simpletest/grade/simpletest/testgradetext.php with 92% similarity]
lib/simpletest/grade/simpletest/testgradehistory.php
lib/simpletest/grade/simpletest/testgradeitem.php
lib/simpletest/grade/simpletest/testgradeoutcome.php
lib/simpletest/grade/simpletest/testgradescale.php
lib/simpletest/grade/simpletest/testgradetree.php
lib/simpletest/testgradelib.php
tags
version.php

index cde373fc1a26ac55084c32617454879d243bc2eb..dfda9fd6a9d1bfa38c7afc5b7cd0d2c802497b44 100755 (executable)
@@ -9,7 +9,7 @@ class grade_export_form extends moodleform {
         $mform->addElement('header', 'general', get_string('gradeitemsinc', 'grades')); // TODO: localize
         $id = $this->_customdata['id']; // course id
         $mform->addElement('hidden', 'id', $id);
-        if ($grade_items = grade_get_items($id)) {
+        if ($grade_items = grade_grades::fetch_all(array('courseid'=>$id))) {
             foreach ($grade_items as $grade_item) {
                 $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->itemname, array('selected'=>'selected'), array(0, $grade_item->id));
                 $element->setChecked(1);
index 611df8745faa1365b3b7764e7e2ae74cfbbab6ee..9890271c33973d2320fd5e8441522c9267b7bc6e 100755 (executable)
@@ -127,7 +127,7 @@ class grade_export {
             }  
         } else {
             // else we get all items for this course
-            $gradeitems = grade_get_items($this->id);
+            $gradeitems = grade_grades::fetch_all(array('courseid'=>$this->id));
         }
         
         if ($gradeitems) {
index ec0156555eb14185ced7c7758d2a22da8f3fcf2b..d27770108b02aa02a8ff4e61c8bc35780db69ed8 100755 (executable)
@@ -9,7 +9,7 @@ class grade_export_txt_form extends moodleform {
         $mform->addElement('header', 'general', 'Gradeitems to be included'); // TODO: localize
         $id = $this->_customdata['id']; // course id
         $mform->addElement('hidden', 'id', $id);
-        if ($grade_items = grade_get_items($id)) {
+        if ($grade_items = grade_grades::fetch_all(array('courseid'=>$id))) {
             foreach ($grade_items as $grade_item) {
                 $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->itemname, array('selected'=>'selected'), array(0, $grade_item->id));
                 $element->setChecked(1);
index 2ab595bb258dc69c8d6d6334a55bf7e23dfca82e..6f93d3abb584a9dd2b5b89a82e35fd20f92f8394 100755 (executable)
@@ -61,7 +61,7 @@ $mform->display();
 // print_gradeitem_selections($id);
 // print all items for selections
 // make this a standard function in lib maybe
-if ($grade_items = grade_get_items($id)) {
+if ($grade_items = grade_grades::fetch_all(array('courseid'=>$id))) {
     echo '<form action="index.php" method="post">';
     echo '<div>';
     foreach ($grade_items as $grade_item) {
index 4b33d81a75e05f15fdb35e756c63fc08fae74208..9c223e8f6646cb4d1a889d3947dd3d30bc307476 100755 (executable)
@@ -66,7 +66,7 @@ class grade_import_mapping_form extends moodleform {
         include_once($CFG->libdir.'/gradelib.php');
         
         if ($id) {
-            if ($grade_items = grade_get_items($id)) {
+            if ($grade_items = grade_grades::fetch_all(array('courseid'=>$id))) {
                 foreach ($grade_items as $grade_item) {
                     $gradeitems[$grade_item->idnumber] = $grade_item->itemname;      
                 }
index 9d2717c703a3326dab9015c93c028d51aba452aa..9764f4b9e0f8678b9132b5b20a14f3e4353c41b4 100644 (file)
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="courseid"/>
         <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="The course this item is part of" PREVIOUS="id" NEXT="categoryid"/>
         <FIELD NAME="categoryid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="(optional) the category group this item belongs to" PREVIOUS="courseid" NEXT="itemname"/>
-        <FIELD NAME="itemname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="The name of this item (pushed in by the module)" PREVIOUS="categoryid" NEXT="itemtype"/>
+        <FIELD NAME="itemname" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="The name of this item (pushed in by the module)" PREVIOUS="categoryid" NEXT="itemtype"/>
         <FIELD NAME="itemtype" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="'mod', 'blocks', 'import', 'calculated' etc" PREVIOUS="itemname" NEXT="itemmodule"/>
-        <FIELD NAME="itemmodule" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="'forum', 'quiz', 'csv', etc" PREVIOUS="itemtype" NEXT="iteminstance"/>
+        <FIELD NAME="itemmodule" TYPE="char" LENGTH="30" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="'forum', 'quiz', 'csv', etc" PREVIOUS="itemtype" NEXT="iteminstance"/>
         <FIELD NAME="iteminstance" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="id of the item module" PREVIOUS="itemmodule" NEXT="itemnumber"/>
         <FIELD NAME="itemnumber" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="Can be used to distinguish multiple grades for an activity" PREVIOUS="iteminstance" NEXT="iteminfo"/>
-        <FIELD NAME="iteminfo" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Info and notes about this item XXX" PREVIOUS="itemnumber" NEXT="idnumber"/>
+        <FIELD NAME="iteminfo" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Info and notes about this item XXX" PREVIOUS="itemnumber" NEXT="idnumber"/>
         <FIELD NAME="idnumber" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Arbitrary idnumber provided by the module responsible" PREVIOUS="iteminfo" NEXT="calculation"/>
         <FIELD NAME="calculation" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="Formula describing how to derive this grade from other items, referring to them using giXXX where XXX is grade item id ... eg something like: =sin(square([#gi20#])) + [#gi30#]" PREVIOUS="idnumber" NEXT="gradetype"/>
         <FIELD NAME="gradetype" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" ENUM="false" COMMENT="0 = none, 1 = value, 2 = scale, 3 = text" PREVIOUS="calculation" NEXT="grademax"/>
index 694bb843a96214279d192eef99cbd9ae0356eaf6..96143cfa8a3d439dfb504dfc61bf0f991a31f830 100644 (file)
@@ -812,12 +812,12 @@ function xmldb_main_upgrade($oldversion=0) {
         $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
         $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
         $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
-        $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
+        $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
         $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
-        $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
+        $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
         $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
         $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
-        $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
+        $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
         $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
         $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
         $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0');
@@ -1025,7 +1025,7 @@ function xmldb_main_upgrade($oldversion=0) {
     /// Define field path to be added to grade_categories
         $table = new XMLDBTable('grade_categories');
         $field = new XMLDBField('path');
-        $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'depth');
+        $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'depth');
 
     /// Launch add field path
         $result = $result && add_field($table, $field);
@@ -1333,6 +1333,39 @@ function xmldb_main_upgrade($oldversion=0) {
         /// Launch add field calculation
             $result = $result && add_field($table, $field);
         }
+    }
+
+    if ($result && $oldversion < 2007062401) {
+
+    /// Changing nullability of field itemname on table grade_items to null
+        $table = new XMLDBTable('grade_items');
+        $field = new XMLDBField('itemname');
+        $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'categoryid');
+
+    /// Launch change of nullability for field itemname
+        $result = $result && change_field_notnull($table, $field);
+
+        $field = new XMLDBField('itemmodule');
+        $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null, 'itemtype');
+
+    /// Launch change of nullability for field itemname
+        $result = $result && change_field_notnull($table, $field);
+
+        $field = new XMLDBField('iteminfo');
+        $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'itemnumber');
+
+    /// Launch change of nullability for field itemname
+        $result = $result && change_field_notnull($table, $field);
+
+
+    /// Changing nullability of field path on table grade_categories to null
+        $table = new XMLDBTable('grade_categories');
+        $field = new XMLDBField('path');
+        $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'depth');
+
+    /// Launch change of nullability for field path
+        $result = $result && change_field_notnull($table, $field);
+
 
         /// Remove the obsoleted unitttests tables - they will be recreated automatically
         $tables = array('grade_categories',
index 07d0718f8264f2570601e51b0c2eb1db06ca3ab7..25495e1fed49df5034e9fe69623851183e6a1c52 100644 (file)
@@ -85,19 +85,19 @@ class grade_category extends grade_object {
      * A constant pointing to one of the predefined aggregation strategies (none, mean, median, sum etc) .
      * @var int $aggregation
      */
-    var $aggregation;
+    var $aggregation = GRADE_AGGREGATE_MEAN_ALL;
 
     /**
      * Keep only the X highest items.
      * @var int $keephigh
      */
-    var $keephigh;
+    var $keephigh = 0;
 
     /**
      * Drop the X lowest items.
      * @var int $droplow
      */
-    var $droplow;
+    var $droplow = 0;
 
     /**
      * Array of grade_items or grade_categories nested exactly 1 level below this category
@@ -119,18 +119,6 @@ class grade_category extends grade_object {
      */
     var $grade_item;
 
-    /**
-     * Constructor. Extends the basic functionality defined in grade_object.
-     * @param array $params Can also be a standard object.
-     * @param boolean $fetch Whether or not to fetch the corresponding row from the DB.
-     * @param object $grade_item The associated grade_item object can be passed during construction.
-     */
-    function grade_category($params=NULL, $fetch=true) {
-        $this->grade_object($params, $fetch);
-        $this->path = grade_category::build_path($this);
-    }
-
-
     /**
      * Builds this category's path string based on its parents (if any) and its own id number.
      * This is typically done just before inserting this object in the DB for the first time,
@@ -152,22 +140,35 @@ class grade_category extends grade_object {
 
 
     /**
-     * Finds and returns a grade_category object based on 1-3 field values.
+     * Finds and returns a grade_category instance based on params.
      * @static
      *
-     * @param string $field1
-     * @param string $value1
-     * @param string $field2
-     * @param string $value2
-     * @param string $field3
-     * @param string $value3
-     * @param string $fields
-     * @return object grade_category object or false if none found.
-     */
-    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
-        if ($grade_category = get_record('grade_categories', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
-            $grade_category = new grade_category($grade_category);
-            return $grade_category;
+     * @param array $params associative arrays varname=>value
+     * @return object grade_category instance or false if none found.
+     */
+    function fetch($params) {
+        if ($category = grade_object::fetch_helper('grade_categories', 'grade_category', $params)) {
+            $category->path = grade_category::build_path($category);
+            return $category;
+
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Finds and returns all grade_category instances based on params.
+     * @static
+     *
+     * @param array $params associative arrays varname=>value
+     * @return array array of grade_category insatnces or false if none found.
+     */
+    function fetch_all($params) {
+        if ($categories = grade_object::fetch_all_helper('grade_categories', 'grade_category', $params)) {
+            foreach ($categories as $key=>$value) {
+                $categories[$key]->path = grade_category::build_path($categories[$key]);
+            }
+            return $categories;
 
         } else {
             return false;
@@ -360,7 +361,7 @@ class grade_category extends grade_object {
         $items = array();
 
         foreach($depends_on as $dep) {
-            $items[$dep] = grade_item::fetch('id', $dep);
+            $items[$dep] = grade_item::fetch(array('id'=>$dep));
         }
 
         // where to look for final grades - include or grade item too
@@ -712,9 +713,11 @@ class grade_category extends grade_object {
             return false;
         }
 
-        $grade_item = new grade_item(array('courseid'=>$this->courseid, 'itemtype'=>'category', 'iteminstance'=>$this->id), false);
-        if (!$grade_items = $grade_item->fetch_all_using_this()) {
+        $params = array('courseid'=>$this->courseid, 'itemtype'=>'category', 'iteminstance'=>$this->id);
+
+        if (!$grade_items = grade_item::fetch_all($params)) {
             // create a new one
+            $grade_item = new grade_item($params, false);
             $grade_item->gradetype = GRADE_TYPE_VALUE;
             $grade_item->insert();
 
index 7d05b5d5a4bce2f3a40b2eede22c9cf0e4042a49..edec57607d7b5b7afd85e778cf8b31c4a3569f0b 100644 (file)
@@ -67,13 +67,13 @@ class grade_grades extends grade_object {
      * The maximum allowable grade when this grade was created.
      * @var float $rawgrademax
      */
-    var $rawgrademax;
+    var $rawgrademax = 100;
 
     /**
      * The minimum allowable grade when this grade was created.
      * @var float $rawgrademin
      */
-    var $rawgrademin;
+    var $rawgrademin = 0;
 
     /**
      * id of the scale, if this grade is based on a scale.
@@ -105,34 +105,25 @@ class grade_grades extends grade_object {
      * 0 if visible, 1 always hidden or date not visible until
      * @var float $hidden
      */
-    var $hidden;
+    var $hidden = 0;
 
     /**
      * 0 not locked, date when the item was locked
      * @var float locked
      */
-    var $locked;
+    var $locked = 0;
 
     /**
      * 0 no automatic locking, date when to lock the grade automatically
      * @var float $locktime
      */
-    var $locktime;
+    var $locktime = 0;
 
     /**
      * Exported flag
      * @var boolean $exported
      */
-    var $exported;
-
-    /**
-     * 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($params=NULL, $fetch=true) {
-        $this->grade_object($params, $fetch);
-    }
+    var $exported = 0;
 
     /**
      * Loads the grade_grades_text object linked to this grade (through the intersection of itemid and userid), and
@@ -141,7 +132,7 @@ class grade_grades extends grade_object {
      */
     function load_text() {
         if (empty($this->grade_grades_text->id)) {
-            $this->grade_grades_text = grade_grades_text::fetch('itemid', $this->itemid, 'userid', $this->userid);
+            $this->grade_grades_text = grade_grades_text::fetch(array('itemid'=>$this->itemid, 'userid'=>$this->userid));
         }
 
         return $this->grade_grades_text;
@@ -153,7 +144,7 @@ class grade_grades extends grade_object {
      */
     function load_grade_item() {
         if (empty($this->grade_item) && !empty($this->itemid)) {
-            $this->grade_item = grade_item::fetch('id', $this->itemid);
+            $this->grade_item = grade_item::fetch(array('id'=>$this->itemid));
         }
         return $this->grade_item;
     }
@@ -214,26 +205,25 @@ class grade_grades extends grade_object {
     }
 
     /**
-     * Finds and returns a grade_grades object based on 1-3 field values.
+     * Finds and returns a grade_grades instance based on params.
      * @static
      *
-     * @param string $field1
-     * @param string $value1
-     * @param string $field2
-     * @param string $value2
-     * @param string $field3
-     * @param string $value3
-     * @param string $fields
-     * @return object grade_category object or false if none found.
+     * @param array $params associative arrays varname=>value
+     * @return object grade_grades instance or false if none found.
      */
-    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
-        if ($object = get_record('grade_grades', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
-            $object = new grade_grades($object);
-            return $object;
+    function fetch($params) {
+        return grade_object::fetch_helper('grade_grades', 'grade_grades', $params);
+    }
 
-        } else {
-            return false;
-        }
+    /**
+     * Finds and returns all grade_grades instances based on params.
+     * @static
+     *
+     * @param array $params associative arrays varname=>value
+     * @return array array of grade_grades insatnces or false if none found.
+     */
+    function fetch_all($params) {
+        return grade_object::fetch_all_helper('grade_grades', 'grade_grades', $params);
     }
 
     /**
index 3700232ffe3d5d68deaec4e6e574a8456cca7184..3d41b7b6e3679bfd37df65a75ad6e31de31bf67f 100644 (file)
@@ -70,7 +70,7 @@ class grade_grades_text extends grade_object {
      * Text format for information (FORMAT_PLAIN, FORMAT_HTML etc...).
      * @var int $informationformat
      */
-    var $informationformat;
+    var $informationformat = FORMAT_MOODLE;
 
     /**
      * Manual feedback from the teacher. This could be a code like 'mi'.
@@ -82,7 +82,7 @@ class grade_grades_text extends grade_object {
      * Text format for feedback (FORMAT_PLAIN, FORMAT_HTML etc...).
      * @var int $feedbackformat
      */
-    var $feedbackformat;
+    var $feedbackformat = FORMAT_MOODLE;
 
     /**
      * The userid of the person who last modified this text.
@@ -91,27 +91,25 @@ class grade_grades_text extends grade_object {
     var $usermodified;
 
     /**
-     * Finds and returns a grade_text object based on 1-3 field values.
+     * Finds and returns a grade_grades_text instance based on params.
      * @static
      *
-     * @param boolean $static Unless set to true, this method will also set $this object with the returned values.
-     * @param string $field1
-     * @param string $value1
-     * @param string $field2
-     * @param string $value2
-     * @param string $field3
-     * @param string $value3
-     * @param string $fields
-     * @return object grade_text object or false if none found.
+     * @param array $params associative arrays varname=>value
+     * @return object grade_grades_text instance or false if none found.
      */
-    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
-        if ($grade_text = get_record('grade_grades_text', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
-            $grade_text = new grade_grades_text($grade_text);
-            return $grade_text;
+    function fetch($params) {
+        return grade_object::fetch_helper('grade_grades_text', 'grade_grades_text', $params);
+    }
 
-        } else {
-            return false;
-        }
+    /**
+     * Finds and returns all grade_grades_text instances based on params.
+     * @static
+     *
+     * @param array $params associative arrays varname=>value
+     * @return array array of grade_grades_text insatnces or false if none found.
+     */
+    function fetch_all($params) {
+        return grade_object::fetch_all_helper('grade_grades_text', 'grade_grades_text', $params);
     }
 
     /**
@@ -120,7 +118,7 @@ class grade_grades_text extends grade_object {
      */
     function load_grade_item() {
         if (empty($this->grade_item) && !empty($this->itemid)) {
-            $this->grade_item = grade_item::fetch('id', $this->itemid);
+            $this->grade_item = grade_item::fetch(array('id'=>$this->itemid));
         }
         return $this->grade_item;
     }
index 9c8da938af5bef5ca3390a23da28b9b791d3e66b..47f77de52e7db5508c347fa2f59b24bd870e8cb8 100644 (file)
@@ -72,33 +72,38 @@ class grade_history extends grade_object {
      */
     var $note;
 
+    /**
+     * Which user account did the modification.
+     * @var string $usermodified
+     */
+    var $usermodified;
+
     /**
      * How the grade was modified ('manual', 'module', 'import' etc...).
      * @var string $howmodified
      */
-    var $howmodified;
+    var $howmodified = 'manual';
 
     /**
-     * Finds and returns a grade_history object based on 1-3 field values.
+     * Finds and returns a grade_history instance based on params.
      * @static
      *
-     * @param string $field1
-     * @param string $value1
-     * @param string $field2
-     * @param string $value2
-     * @param string $field3
-     * @param string $value3
-     * @param string $fields
-     * @return object grade_history object or false if none found.
+     * @param array $params associative arrays varname=>value
+     * @return object grade_history instance or false if none found.
      */
-    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
-        if ($grade_history = get_record('grade_history', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
-            $grade_history = new grade_history($grade_history);
-            return $grade_history;
+    function fetch($params) {
+        return grade_object::fetch_helper('grade_history', 'grade_history', $params);
+    }
 
-        } else {
-            return false;
-        }
+    /**
+     * Finds and returns all grade_history instances based on params.
+     * @static
+     *
+     * @param array $params associative arrays varname=>value
+     * @return array array of grade_history insatnces or false if none found.
+     */
+    function fetch_all($params) {
+        return grade_object::fetch_all_helper('grade_history', 'grade_history', $params);
     }
 
     /**
@@ -120,8 +125,6 @@ class grade_history extends grade_object {
         $history->newgrade     = $newgrade;
         $history->note         = $note;
         $history->howmodified  = $howmodified;
-        $history->timemodified = time();
-        $history->usermodified = $USER->id;
 
         return $history->insert();
     }
index 7b26cd560a6f2d1b88449e652a01a5abe175dcef..af7a98201521a4e0de4c77338274d4297d15cb81 100644 (file)
@@ -73,7 +73,7 @@ class grade_item extends grade_object {
     var $itemname;
 
     /**
-     * e.g. 'mod', 'blocks', 'import', 'calculate' etc...
+     * e.g. 'category', 'total' and 'mod', 'blocks', 'import', etc...
      * @var string $itemtype
      */
     var $itemtype;
@@ -129,19 +129,19 @@ class grade_item extends grade_object {
      * The type of grade (0 = none, 1 = value, 2 = scale, 3 = text)
      * @var int $gradetype
      */
-    var $gradetype;
+    var $gradetype = GRADE_TYPE_VALUE;
 
     /**
      * Maximum allowable grade.
      * @var float $grademax
      */
-    var $grademax;
+    var $grademax = 100;
 
     /**
      * Minimum allowable grade.
      * @var float $grademin
      */
-    var $grademin;
+    var $grademin = 0;
 
     /**
      * id of the scale, if this grade is based on a scale.
@@ -168,61 +168,58 @@ class grade_item extends grade_object {
     var $outcome;
 
     /**
-     * grade required to pass. (grademin < gradepass <= grademax)
+     * grade required to pass. (grademin <= gradepass <= grademax)
      * @var float $gradepass
      */
-    var $gradepass;
+    var $gradepass = 0;
 
     /**
      * Multiply all grades by this number.
      * @var float $multfactor
      */
-    var $multfactor;
+    var $multfactor = 1.0;
 
     /**
      * Add this to all grades.
      * @var float $plusfactor
      */
-    var $plusfactor;
+    var $plusfactor = 0;
 
     /**
      * Sorting order of the columns.
      * @var int $sortorder
      */
-    var $sortorder;
+    var $sortorder = 0;
 
     /**
      * Date until which to hide this grade_item. If null, 0 or false, grade_item is not hidden. Hiding prevents viewing.
      * @var int $hidden
      */
-    var $hidden;
+    var $hidden = 0;
 
     /**
-     * Date until which to lock this grade_item. If null, 0 or false, grade_item is not locked. Locking prevents updating.
+     * Grade item lock flag. Enmpty if not locked, lcoked if any value presetn ,usually date when was locked. Locking prevents updating.
      * @var int $locked
      */
-    var $locked;
+    var $locked = 0;
+
+    /**
+     * Date when to lock the grade. Empty means no automatic locking.
+     * @var int $locktime
+     */
+    var $locktime = 0;
 
     /**
      * Whether or not the module instance referred to by this grade_item has been deleted.
      * @var int $deleted
      */
-    var $deleted;
+    var $deleted = 0;
 
     /**
      * If set, the whole column will be recalculated, then this flag will be switched off.
      * @var boolean $needsupdate
      */
-    var $needsupdate;
-
-    /**
-     * 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_item($params=NULL, $fetch=true) {
-        $this->grade_object($params, $fetch);
-    }
+    var $needsupdate = 0;
 
     /**
      * In addition to update() as defined in grade_object, handle the grade_outcome and grade_scale objects.
@@ -293,26 +290,25 @@ class grade_item extends grade_object {
     }
 
     /**
-     * Finds and returns a grade_item object based on 1-3 field values.
+     * Finds and returns a grade_item instance based on params.
      * @static
      *
-     * @param string $field1
-     * @param string $value1
-     * @param string $field2
-     * @param string $value2
-     * @param string $field3
-     * @param string $value3
-     * @param string $fields
-     * @return object grade_item object or false if none found.
-     */
-    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
-        if ($grade_item = get_record('grade_items', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
-            $grade_item = new grade_item($grade_item);
-            return $grade_item;
+     * @param array $params associative arrays varname=>value
+     * @return object grade_item instance or false if none found.
+     */
+    function fetch($params) {
+        return grade_object::fetch_helper('grade_items', 'grade_item', $params);
+    }
 
-        } else {
-            return false;
-        }
+    /**
+     * Finds and returns all grade_item instances based on params.
+     * @static
+     *
+     * @param array $params associative arrays varname=>value
+     * @return array array of grade_item insatnces or false if none found.
+     */
+    function fetch_all($params) {
+        return grade_object::fetch_all_helper('grade_items', 'grade_item', $params);
     }
 
     /**
@@ -728,7 +724,7 @@ class grade_item extends grade_object {
         }
 
         if (!empty($this->scaleid)) {
-            $this->scale = grade_scale::fetch('id', $this->scaleid);
+            $this->scale = grade_scale::fetch(array('id'=>$this->scaleid));
             $this->scale->load_items();
             $this->grademax = count($this->scale->scale_items) - 1;
             $this->grademin = 0;
@@ -746,7 +742,7 @@ class grade_item extends grade_object {
      */
     function load_outcome() {
         if (!empty($this->outcomeid)) {
-            $this->outcome = grade_outcome::fetch('id', $this->outcomeid);
+            $this->outcome = grade_outcome::fetch(array('id'=>$this->outcomeid));
         }
         return $this->outcome;
     }
@@ -762,9 +758,9 @@ class grade_item extends grade_object {
         $category = null;
 
         if (!empty($this->categoryid)) {
-            $category = grade_category::fetch('id', $this->categoryid);
+            $category = grade_category::fetch(array('id'=>$this->categoryid));
         } elseif (!empty($this->iteminstance) && $this->itemtype == 'category') {
-            $category = grade_category::fetch('id', $this->iteminstance);
+            $category = grade_category::fetch(array('id'=>$this->iteminstance));
         }
 
         return $category;
@@ -798,7 +794,7 @@ class grade_item extends grade_object {
         // first detect if we need to update calculation formula from [idnumber] to [#giXXX#] (after backup, etc.)
         if (!$this->calculation_normalized and preg_match_all('/\[(?!#gi)(.*?)\]/', $this->calculation, $matches)) {
             foreach ($matches[1] as $idnumber) {
-                if ($grade_item = grade_item::fetch('courseid', $this->courseid, 'idnumber', $idnumber)) {
+                if ($grade_item = grade_item::fetch(array('courseid'=>$this->courseid, 'idnumber'=>$idnumber))) {
                     $this->calculation = str_replace('['.$grade_item->idnumber.']', '[#gi'.$grade_item->id.'#]', $this->calculation);
                 }
             }
@@ -820,7 +816,7 @@ class grade_item extends grade_object {
             // denormalize formula - convert [#giXX#] to [idnumber]
             if (preg_match_all('/\[#gi([0-9]+)#\]/', $formula, $matches)) {
                 foreach ($matches[1] as $id) {
-                    if ($grade_item = grade_item::fetch('id', $id)) {
+                    if ($grade_item = grade_item::fetch(array('id'=>$id))) {
                         if (!empty($grade_item->idnumber)) {
                             $formula = str_replace('[#gi'.$grade_item->id.'#]', '['.$grade_item->idnumber.']', $formula);
                         }
@@ -854,8 +850,7 @@ class grade_item extends grade_object {
             }
 
             // normalize formula - we want grade item ids [#giXXX#] instead of [idnumber]
-            $grade_item = new grade_item(array('courseid'=>$this->courseid), false);
-            if ($grade_items = $grade_item->fetch_all_using_this()) {
+            if ($grade_items = grade_item::fetch_all(array('courseid'=>$this->courseid))) {
                 foreach ($grade_items as $grade_item) {
                     $formula = str_replace('['.$grade_item->idnumber.']', '[#gi'.$grade_item->id.'#]', $formula);
                 }
index 43c40cb3e6813fff62dceffa0d5a488cf244016e..8dd5066b76401330a7a63d4a52f7c0fa46dd8448 100644 (file)
@@ -60,19 +60,107 @@ class grade_object {
 
     /**
      * Constructor. Optionally (and by default) attempts to fetch corresponding row from DB.
-     * @param object $params an object with named parameters for this grade item.
+     * @param array $params an array with required parameters for this grade object.
      * @param boolean $fetch Whether to fetch corresponding row from DB or not.
      */
     function grade_object($params=NULL, $fetch = true) {
-        if (!empty($params) && (is_array($params) || is_object($params))) {
-            $this->assign_to_this($params);
-
-            if ($fetch) {
-                $records = $this->fetch_all_using_this();
-                if ($records && count($records) > 0) {
-                    $this->assign_to_this(current($records));
-                }
+        if (!empty($params) and (is_array($params) or is_object($params))) {
+            if ($fetch and $data = $this->fetch($params)) {
+                grade_object::set_properties($this, $data);
+
+            } else {
+                grade_object::set_properties($this, $params);
+            }
+        }
+    }
+
+    /**
+     * Finds and returns a grade_object instance based on params.
+     * @static abstract
+     *
+     * @param array $params associative arrays varname=>value
+     * @return object grade_object instance or false if none found.
+     */
+    function fetch($params) {
+        error('Abstract method fetch() not overrided in '.get_class($this));
+    }
+
+    /**
+     * Finds and returns all grade_object instances based on params.
+     * @static abstract
+     *
+     * @param array $params associative arrays varname=>value
+     * @return array array of grade_object insatnces or false if none found.
+     */
+    function fetch_all($params) {
+        error('Abstract method fetch_all() not overrided in '.get_class($this));
+    }
+
+    /**
+     * Factory method - uses the parameters to retrieve matching instance from the DB.
+     * @static final protected
+     * @return mixed object insatnce or false if not found
+     */
+    function fetch_helper($table, $classname, $params) {
+        // we have to do use this hack because of the incomplete OOP implementation in PHP4 :-(
+        // in PHP5 we could do it much better
+        if ($instances = grade_object::fetch_all_helper($table, $classname, $params)) {
+            if (count($instances) > 1) {
+                // we should not tolerate any errors here - proplems might appear later
+                error('Found more than one record in fetch() !');
             }
+            return reset($instances);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Factory method - uses the parameters to retrieve all matching instances from the DB.
+     * @static final protected
+     * @return mixed array of object instances or false if not found
+     */
+    function fetch_all_helper($table, $classname, $params) {
+        // we have to do use this hack because of the incomplete OOP implementation in PHP4 :-(
+        // in PHP5 we could do it much better
+        $instance = new $classname();
+
+        $classvars = (array)$instance;
+        $params    = (array)$params;
+
+        $wheresql = array();
+
+        // remove incorrect params - warn developer if needed
+        foreach ($params as $var=>$value) {
+            if (!array_key_exists($var, $classvars) or in_array($var, $instance->nonfields)) {
+                debugging("Incorrect property name $var for class $classname");
+                continue;
+            }
+            if (is_null($value)) {
+                $wheresql[] = " $var IS NULL ";
+            } else {
+                $value = addslashes($value);
+                $wheresql[] = " $var = '$value' ";
+            }
+        }
+
+        if (empty($wheresql)) {
+            $wheresql = '';
+        } else {
+            $wheresql = implode("AND", $wheresql);
+        }
+
+        if ($datas = get_records_select($table, $wheresql, 'id')) {
+            $result = array();
+            foreach($datas as $data) {
+                $instance = new $classname();
+                grade_object::set_properties($instance, $data);
+                $result[$instance->id] = $instance;
+            }
+            return $result;
+
+        } else {
+            return false;
         }
     }
 
@@ -86,7 +174,7 @@ class grade_object {
 
         $this->timemodified = time();
 
-        if (empty($this->usermodified)) {
+        if (array_key_exists('usermodified', $this)) {
             $this->usermodified = $USER->id;
         }
 
@@ -116,20 +204,11 @@ class grade_object {
 
         $this->timecreated = $this->timemodified = time();
 
-        if (empty($this->usermodified)) {
+        if (array_key_exists('usermodified', $this)) {
             $this->usermodified = $USER->id;
         }
 
-        $clonethis = fullclone($this);
-
-        // Unset non-set and null fields
-        foreach ($clonethis as $var => $val) {
-            if (!isset($val)) {
-                unset($clonethis->$var);
-            }
-        }
-
-        if (!$this->id = insert_record($this->table, addslashes_recursive($clonethis), true)) {
+        if (!$this->id = insert_record($this->table, addslashes_recursive($this))) {
             debugging("Could not insert object into db");
             return false;
         }
@@ -157,54 +236,21 @@ class grade_object {
             return false;
         }
 
-        $this->assign_to_this($params);
+        grade_object::set_properties($this, $params);
 
         return true;
     }
 
-    /**
-     * Uses the variables of this object to retrieve all matching objects from the DB.
-     * @return array $objects
-     */
-    function fetch_all_using_this() {
-        $variables = get_object_vars($this);
-        $wheresql = '';
-
-        foreach ($variables as $var => $value) {
-            if (!empty($value) && !in_array($var, $this->nonfields)) {
-                $value = addslashes($value);
-                $wheresql .= " $var = '$value' AND ";
-            }
-        }
-
-        // Trim trailing AND
-        $wheresql = substr($wheresql, 0, strrpos($wheresql, 'AND'));
-
-        $objects = get_records_select($this->table, $wheresql, 'id');
-
-        if (!empty($objects)) {
-            $full_objects = array();
-
-            // Convert the stdClass objects returned by the get_records_select method into proper objects
-            $classname = get_class($this);
-            foreach ($objects as $id => $stdobject) {
-                $full_objects[$id] = new $classname($stdobject, false);
-            }
-            return $full_objects;
-        } else {
-            return $objects;
-        }
-    }
-
-
     /**
      * Given an associated array or object, cycles through each key/variable
      * and assigns the value to the corresponding variable in this object.
+     * @static final
      */
-    function assign_to_this($params) {
-        foreach ($params as $param => $value) {
-            if (in_object_vars($param, $this)) {
-                $this->$param = $value;
+    function set_properties(&$instance, $params) {
+        $classvars = (array)$instance;
+        foreach ($params as $var => $value) {
+            if (array_key_exists($var, $classvars)) {
+                $instance->$var = $value;
             }
         }
     }
index bbda5954a42b607b4298b8a36f89eff7318c5e2d..1127f101f740ff5084eec291848b3b936de9dd58 100644 (file)
@@ -79,36 +79,41 @@ class grade_outcome extends grade_object {
     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.
+     * Finds and returns a grade_outcome instance based on params.
+     * @static
+     *
+     * @param array $params associative arrays varname=>value
+     * @return object grade_outcome instance or false if none found.
      */
-    function grade_outcome($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();
+    function fetch($params) {
+        if ($outcome = grade_object::fetch_helper('grade_outcomes', 'grade_outcome', $params)) {
+            if (!empty($outcome->scaleid)) {
+                $outcome->scale = new grade_scale(array('id'=>$outcome->scaleid));
+                $outcome->scale->load_items();
+            }
+            return $outcome;
+
+        } else {
+            return false;
         }
     }
 
     /**
-     * Finds and returns a grade_outcome object based on 1-3 field values.
+     * Finds and returns all grade_outcome instances based on params.
      * @static
      *
-     * @param boolean $static Unless set to true, this method will also set $this object with the returned values.
-     * @param string $field1
-     * @param string $value1
-     * @param string $field2
-     * @param string $value2
-     * @param string $field3
-     * @param string $value3
-     * @param string $fields
-     * @return object grade_outcome object or false if none found.
+     * @param array $params associative arrays varname=>value
+     * @return array array of grade_outcome insatnces or false if none found.
      */
-    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
-        if ($grade_outcome = get_record('grade_outcomes', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
-            $grade_outcome = new grade_outcome($grade_outcome);
-            return $grade_outcome;
+    function fetch_all($params) {
+        if ($outcomes = grade_object::fetch_all_helper('grade_outcomes', 'grade_outcome', $params)) {
+            foreach ($outcomes as $key=>$value) {
+                if (!empty($outcomes[$key]->scaleid)) {
+                    $outcomes[$key]->scale = new grade_scale(array('id'=>$outcomes[$key]->scaleid));
+                    $outcomes[$key]->scale->load_items();
+                }
+            }
+            return $outcomes;
 
         } else {
             return false;
index 59d6f7999d7905a1df2be1142c61b789907fcb13..d49986626d715ceabe160c50e9dfd5152da08943 100644 (file)
@@ -48,6 +48,8 @@ class grade_scale extends grade_object {
      */
     var $courseid;
 
+    var $userid;
+
     /**
      * The name of the scale.
      * @var string $name
@@ -73,26 +75,25 @@ class grade_scale extends grade_object {
     var $description;
 
     /**
-     * Finds and returns a grade_scale object based on 1-3 field values.
+     * Finds and returns a grade_scale instance based on params.
      * @static
      *
-     * @param string $field1
-     * @param string $value1
-     * @param string $field2
-     * @param string $value2
-     * @param string $field3
-     * @param string $value3
-     * @param string $fields
-     * @return object grade_scale object or false if none found.
+     * @param array $params associative arrays varname=>value
+     * @return object grade_scale instance or false if none found.
      */
-    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") {
-        if ($grade_scale = get_record('scale', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
-            $grade_scale = new grade_scale($grade_scale);
-            return $grade_scale;
+    function fetch($params) {
+        return grade_object::fetch_helper('scale', 'grade_scale', $params);
+    }
 
-        } else {
-            return false;
-        }
+    /**
+     * Finds and returns all grade_scale instances based on params.
+     * @static
+     *
+     * @param array $params associative arrays varname=>value
+     * @return array array of grade_scale insatnces or false if none found.
+     */
+    function fetch_all($params) {
+        return grade_object::fetch_all_helper('scale', 'grade_scale', $params);
     }
 
     /**
index c8dafb4e1180f5a90b52bced65a85ab711025028..e07df04dc61c0a6041e8f821a7a36505c7c10f02 100644 (file)
@@ -576,12 +576,9 @@ class grade_tree {
                 $itemtree = array();
 
                 foreach ($children as $element) {
-                    $finals = array();
 
-                    if ($this->include_grades) {
-                        $final = new grade_grades();
-                        $final->itemid = $element['object']->id;
-                        $finals = $final->fetch_all_using_this();
+                    if (!$this->include_grades or !$finals = grade_grades::fetch_all(array('itemid'=>$element['object']->id))) {
+                        $finals = array();
                     }
 
                     $itemtree[$element['object']->sortorder] = array('object' => $element['object'], 'finalgrades' => $finals);
@@ -740,12 +737,8 @@ class grade_tree {
                 }
 
                 foreach ($items as $itemid => $item) {
-                    $finals = array();
-
-                    if ($this->include_grades) {
-                        $final = new grade_grades();
-                        $final->itemid = $itemid;
-                        $finals = $final->fetch_all_using_this();
+                    if (!$this->include_grades or !$finals = grade_grades::fetch_all(array('itemid'=>$itemid))) {
+                        $finals = array();
                     }
 
                     $sortorder = $item->sortorder;
index 0804fa639a78119e6e9d758ca2e76efbace67e74..7b30ed7cb895ab0c036098ecb789b9c9b07741da 100644 (file)
@@ -95,8 +95,7 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance,
         return GRADE_UPDATE_FAILED;
     }
 
-    $grade_item = new grade_item(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'), false);
-    if (!$grade_items = $grade_item->fetch_all_using_this()) {
+    if (!$grade_items = grade_item::fetch_all(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'))) {
         // create a new one
         $grade_item = false;
 
@@ -277,8 +276,7 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance,
 */
 function grade_is_locked($courseid, $itemtype, $itemmodule, $iteminstance, $itemnumber, $userid=NULL) {
 
-    $grade_item = new grade_item(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'), false);
-    if (!$grade_items = $grade_item->fetch_all_using_this()) {
+    if (!$grade_items = grade_item::fetch_all(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'))) {
         return false;
 
     } else if (count($grade_items) == 1){
@@ -299,31 +297,6 @@ function grade_is_locked($courseid, $itemtype, $itemmodule, $iteminstance, $item
 /***** END OF PUBLIC API *****/
 
 
-/**
-* Extracts from the gradebook all the grade items attached to the calling object.
-* For example, an assignment may want to retrieve all the grade_items for itself,
-* and get three outcome scales in return. This will affect the grading interface.
-*
-* Note: Each parameter refines the search. So if you only give the courseid,
-*       all the grade_items for this course will be returned. If you add the
-*       itemtype 'mod', all grade_items for this courseif AND for the 'mod'
-*       type will be returned, etc...
-*
-* @param int $courseid The id of the course to which the grade items belong
-* @param string $itemtype 'mod', 'blocks', 'import', 'calculated' etc
-* @param string $itemmodule 'forum, 'quiz', 'csv' etc
-* @param int $iteminstance id of the item module
-* @param int $itemnumber Can be used to distinguish multiple grades for an activity
-* @param string $itemname The name of the grade item
-* @param int $idnumber grade item Primary Key
-* @return array An array of grade items
-*/
-function grade_get_items($courseid, $itemtype=NULL, $itemmodule=NULL, $iteminstance=NULL, $itemnumber=NULL, $itemname=NULL, $idnumber=NULL) {
-    $grade_item = new grade_item(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemname', 'itemnumber', 'idnumber'), false);
-    $grade_items = $grade_item->fetch_all_using_this();
-    return $grade_items;
-}
-
 /**
  * Updates all final grades in course.
  *
@@ -338,9 +311,7 @@ function grade_update_final_grades($courseid, $regradeall=false) {
         set_field('grade_items', 'needsupdate', 1, 'courseid', $courseid);
     }
 
-    $grade_item = new grade_item(array('courseid'=>$courseid), false);
-
-    if (!$grade_items = $grade_item->fetch_all_using_this()) {
+    if (!$grade_items = $grade_item->fetch_all(array('courseid'=>$courseid))) {
         return true;
     }
 
@@ -617,7 +588,7 @@ function grade_update_mod_grades($modinstance) {
 function grade_get_legacy_grade_item($modinstance, $grademax, $scaleid) {
 
     // does it already exist?
-    if ($grade_items = grade_get_items($modinstance->course, 'mod', $modinstance->modname, $modinstance->id, 0)) {
+    if ($grade_items = grade_grades::fetch_all(array('courseid'=>$modinstance->course, 'itemtype'=>'mod', 'itemmodule'=>$modinstance->modname, 'iteminstance'=>$modinstance->id, 'itemnumber'=>0))) {
         if (count($grade_items) > 1) {
             debugging('Multiple legacy grade_items found.');
             return false;
index 5fa8ed6af2614230157b4f3f2afeb1a86c6a7745..323fd82d751bb0212678478ffe3740546a4ff31b 100644 (file)
@@ -99,12 +99,12 @@ class grade_test extends UnitTestCase {
             $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
             $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
             $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
-            $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
+            $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
             $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
-            $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
+            $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
             $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
             $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
-            $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
+            $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
             $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
             $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
             $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1');
@@ -118,11 +118,12 @@ class grade_test extends UnitTestCase {
             $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
-            $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
+            $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
             $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
+
             $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
             $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
             $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));
@@ -142,13 +143,14 @@ class grade_test extends UnitTestCase {
             $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
             $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
             $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
-            $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
+            $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
             $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
             $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
             $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
             $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
+
             $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
             $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
             $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
@@ -256,7 +258,6 @@ class grade_test extends UnitTestCase {
             $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
             $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
 
-        /// Adding keys to table grade_grades
             $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, 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'));
@@ -316,11 +317,11 @@ class grade_test extends UnitTestCase {
         $scale->scale       = 'Way off topic, Not very helpful, Fairly neutral, Fairly helpful, Supportive, Some good information, Perfect answer!';
         $scale->description = 'This scale defines some of qualities that make posts helpful within the Moodle help forums.\n Your feedback will help others see how their posts are being received.';
         $scale->timemodified = mktime();
-        $temp  = explode(',', $scale->scale);
-        $scale->max         = count($temp) -1;
 
         if ($scale->id = insert_record('scale', $scale)) {
             $this->scale[0] = $scale;
+            $temp = explode(',', $scale->scale);
+            $this->scalemax[0] = count($temp) -1;
         }
 
         $scale = new stdClass();
@@ -331,11 +332,11 @@ class grade_test extends UnitTestCase {
         $scale->scale       = 'Distinction, Very Good, Good, Pass, Fail';
         $scale->description = 'This scale is used to mark standard assignments.';
         $scale->timemodified = mktime();
-        $temp  = explode(',', $scale->scale);
-        $scale->max         = count($temp) -1;
 
         if ($scale->id = insert_record('scale', $scale)) {
             $this->scale[1] = $scale;
+            $temp = explode(',', $scale->scale);
+            $this->scalemax[1] = count($temp) -1;
         }
 
         $scale = new stdClass();
@@ -351,6 +352,8 @@ class grade_test extends UnitTestCase {
 
         if ($scale->id = insert_record('scale', $scale)) {
             $this->scale[2] = $scale;
+            $temp = explode(',', $scale->scale);
+            $this->scalemax[2] = count($temp) -1;
         }
 
         $scale->name        = 'unittestscale4';
@@ -364,6 +367,8 @@ class grade_test extends UnitTestCase {
 
         if ($scale->id = insert_record('scale', $scale)) {
             $this->scale[3] = $scale;
+            $temp = explode(',', $scale->scale);
+            $this->scalemax[3] = count($temp) -1;
         }
 
         $scale->name        = 'unittestscale5';
@@ -377,6 +382,8 @@ class grade_test extends UnitTestCase {
 
         if ($scale->id = insert_record('scale', $scale)) {
             $this->scale[4] = $scale;
+            $temp = explode(',', $scale->scale);
+            $this->scalemax[4] = count($temp) -1;
         }
     }
 
@@ -391,7 +398,6 @@ class grade_test extends UnitTestCase {
         $grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
         $grade_category->keephigh    = 100;
         $grade_category->droplow     = 0;
-        $grade_category->hidden      = 0;
         $grade_category->timecreated = mktime();
         $grade_category->timemodified = mktime();
         $grade_category->depth = 1;
@@ -407,7 +413,6 @@ class grade_test extends UnitTestCase {
         $grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
         $grade_category->keephigh    = 100;
         $grade_category->droplow     = 0;
-        $grade_category->hidden      = 0;
         $grade_category->parent      = $this->grade_categories[0]->id;
         $grade_category->timecreated = mktime();
         $grade_category->timemodified = mktime();
@@ -424,7 +429,6 @@ class grade_test extends UnitTestCase {
         $grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
         $grade_category->keephigh    = 100;
         $grade_category->droplow     = 0;
-        $grade_category->hidden      = 0;
         $grade_category->parent      = $this->grade_categories[0]->id;
         $grade_category->timecreated = mktime();
         $grade_category->timemodified = mktime();
@@ -443,7 +447,6 @@ class grade_test extends UnitTestCase {
         $grade_category->aggregation = GRADE_AGGREGATE_MEAN_GRADED;
         $grade_category->keephigh    = 100;
         $grade_category->droplow     = 0;
-        $grade_category->hidden      = 0;
         $grade_category->timecreated = mktime();
         $grade_category->timemodified = mktime();
         $grade_category->depth = 1;
@@ -515,7 +518,7 @@ class grade_test extends UnitTestCase {
         $grade_item->gradetype = GRADE_TYPE_SCALE;
         $grade_item->scaleid = $this->scale[0]->id;
         $grade_item->grademin = 0;
-        $grade_item->grademax = $this->scale[0]->max;
+        $grade_item->grademax = $this->scalemax[0];
         $grade_item->iteminfo = 'Grade item used for unit testing';
         $grade_item->timecreated = mktime();
         $grade_item->timemodified = mktime();
@@ -622,7 +625,7 @@ class grade_test extends UnitTestCase {
         $grade_item->gradetype = GRADE_TYPE_SCALE;
         $grade_item->scaleid = $this->scale[0]->id;
         $grade_item->grademin = 0;
-        $grade_item->grademax = $this->scale[0]->max;
+        $grade_item->grademax = $this->scalemax[0];
         $grade_item->iteminfo = 'Grade item used for unit testing';
         $grade_item->timecreated = mktime();
         $grade_item->timemodified = mktime();
@@ -923,7 +926,6 @@ class grade_test extends UnitTestCase {
     function load_grade_outcomes() {
         // Calculation for grade_item 1
         $grade_outcome = new stdClass();
-        $grade_outcome->itemid = $this->grade_items[0]->id;
         $grade_outcome->shortname = 'Team work';
         $grade_outcome->timecreated = mktime();
         $grade_outcome->timemodified = mktime();
@@ -935,7 +937,6 @@ class grade_test extends UnitTestCase {
 
         // Calculation for grade_item 2
         $grade_outcome = new stdClass();
-        $grade_outcome->itemid = $this->grade_items[1]->id;
         $grade_outcome->shortname = 'Complete circuit board';
         $grade_outcome->timecreated = mktime();
         $grade_outcome->timemodified = mktime();
@@ -947,7 +948,6 @@ class grade_test extends UnitTestCase {
 
         // Calculation for grade_item 3
         $grade_outcome = new stdClass();
-        $grade_outcome->itemid = $this->grade_items[2]->id;
         $grade_outcome->shortname = 'Debug Java program';
         $grade_outcome->timecreated = mktime();
         $grade_outcome->timemodified = mktime();
index d1e1a8d20021ea137055c401c2cc3d5c4eaf960d..35e6a46739f4b156e7cf482c2a9e87fba5abdef5 100755 (executable)
@@ -87,6 +87,8 @@ class grade_category_test extends grade_test {
 
         $grade_category->insert();
 
+        $this->assertEqual('/'.$this->grade_categories[0]->id.'/'.$grade_category->id, $grade_category->path);
+
         $last_grade_category = end($this->grade_categories);
 
         $this->assertFalse(empty($grade_category->grade_item));
@@ -121,11 +123,19 @@ class grade_category_test extends grade_test {
         $grade_category = new grade_category();
         $this->assertTrue(method_exists($grade_category, 'fetch'));
 
-        $grade_category = grade_category::fetch('id', $this->grade_categories[0]->id);
+        $grade_category = grade_category::fetch(array('id'=>$this->grade_categories[0]->id));
         $this->assertEqual($this->grade_categories[0]->id, $grade_category->id);
         $this->assertEqual($this->grade_categories[0]->fullname, $grade_category->fullname);
     }
 
+    function test_grade_category_fetch_all() {
+        $grade_category = new grade_category();
+        $this->assertTrue(method_exists($grade_category, 'fetch_all'));
+
+        $grade_categories = grade_category::fetch_all(array('courseid'=>$this->courseid));
+        $this->assertEqual(count($this->grade_categories), count($grade_categories));
+    }
+
     function test_grade_category_get_children() {
         $category = new grade_category($this->grade_categories[0]);
         $this->assertTrue(method_exists($category, 'get_children'));
@@ -244,6 +254,8 @@ class grade_category_test extends grade_test {
         $child2 = new grade_item();
         $child1->itemname = 'new grade_item';
         $child2->itemname = 'new grade_item';
+        $child1->itemtype = 'something';
+        $child2->itemtype = 'something';
         $child1->sortorder = 1;
         $child2->sortorder = 2;
         $child1->courseid = $grade_category->courseid;
index 0caaa17d53bef02889ced8246d893c20314b2018..9fc632a890d73168a57aa4637570637dffa50125 100755 (executable)
@@ -85,9 +85,17 @@ class grade_grades_test extends grade_test {
         $grade_grades = new grade_grades();
         $this->assertTrue(method_exists($grade_grades, 'fetch'));
 
-        $grade_grades = grade_grades::fetch('id', $this->grade_grades[0]->id);
-        $this->assertEqual($this->grade_grades[0]->id, $grade_grades->id);
-        $this->assertEqual($this->grade_grades[0]->rawgrade, $grade_grades->rawgrade);
+        $grades = grade_grades::fetch(array('id'=>$this->grade_grades[0]->id));
+        $this->assertEqual($this->grade_grades[0]->id, $grades->id);
+        $this->assertEqual($this->grade_grades[0]->rawgrade, $grades->rawgrade);
+    }
+
+    function test_grade_grades_fetch_all() {
+        $grade_grades = new grade_grades();
+        $this->assertTrue(method_exists($grade_grades, 'fetch_all'));
+
+        $grades = grade_grades::fetch_all(array());
+        $this->assertEqual(count($this->grade_grades), count($grades));
     }
 
     function test_grade_raw_update_feedback() {
similarity index 92%
rename from lib/simpletest/grade/simpletest/testgradetext.php
rename to lib/simpletest/grade/simpletest/testgradegradestext.php
index e49bf3d5a8c8b7faa02c6e75cf8c31d3fb90c13d..48062db2c536750aa3df8d11d6ef66b03666fb7b 100755 (executable)
@@ -102,11 +102,19 @@ class grade_text_test extends grade_test {
         $grade_grades_text = new grade_grades_text();
         $this->assertTrue(method_exists($grade_grades_text, 'fetch'));
 
-        $grade_grades_text = grade_grades_text::fetch('id', $this->grade_grades_text[0]->id);
+        $grade_grades_text = grade_grades_text::fetch(array('id'=>$this->grade_grades_text[0]->id));
         $this->assertEqual($this->grade_grades_text[0]->id, $grade_grades_text->id);
         $this->assertEqual($this->grade_grades_text[0]->information, $grade_grades_text->information);
     }
 
+    function test_grade_grades_text_fetch_all() {
+        $grade_grades_text = new grade_grades_text();
+        $this->assertTrue(method_exists($grade_grades_text, 'fetch_all'));
+
+        $grade_grades_texts = grade_grades_text::fetch_all(array());
+        $this->assertEqual(count($this->grade_grades_text[0]), count($grade_grades_texts));
+    }
+
     function test_grade_grades_text_load_grade_item() {
         $grade_grades_text = new grade_grades_text($this->grade_grades_text[0]);
         $this->assertTrue(method_exists($grade_grades_text, 'load_grade_item'));
index 2b69044d6e1f80e29f9118ac70560fe95509c429..d9cb433108c5a800e25b7bffa4e5dd60420c3a06 100644 (file)
@@ -95,9 +95,18 @@ class grade_history_test extends grade_test {
         $grade_history = new grade_history();
         $this->assertTrue(method_exists($grade_history, 'fetch'));
 
-        $grade_history = grade_history::fetch('id', $this->grade_history[0]->id);
+        $grade_history = grade_history::fetch(array('id'=>$this->grade_history[0]->id));
         $this->assertEqual($this->grade_history[0]->id, $grade_history->id);
         $this->assertEqual($this->grade_history[0]->note, $grade_history->note);
     }
+
+    function test_grade_history_fetch_all() {
+        $grade_history = new grade_history();
+        $this->assertTrue(method_exists($grade_history, 'fetch_all'));
+
+        $histories = grade_history::fetch(array());
+        $this->assertEqual(count($this->grade_history), count($histories));
+    }
+
 }
 ?>
index f61f68ad1c6634a20738acba0a1d9d5d3ac25e90..2d1e323fb097ef23e0af8e06d91ad159ea259144 100755 (executable)
@@ -189,27 +189,23 @@ class grade_item_test extends grade_test {
         $grade_item = new grade_item();\r
         $this->assertTrue(method_exists($grade_item, 'fetch'));\r
 \r
-        $grade_item = grade_item::fetch('id', $this->grade_items[0]->id);\r
+        $grade_item = grade_item::fetch(array('id'=>$this->grade_items[0]->id));\r
         $this->assertEqual($this->grade_items[0]->id, $grade_item->id);\r
         $this->assertEqual($this->grade_items[0]->iteminfo, $grade_item->iteminfo);\r
 \r
-        $grade_item = grade_item::fetch('itemtype', $this->grade_items[1]->itemtype, 'itemmodule', $this->grade_items[1]->itemmodule);\r
+        $grade_item = grade_item::fetch(array('itemtype'=>$this->grade_items[1]->itemtype, 'itemmodule'=>$this->grade_items[1]->itemmodule));\r
         $this->assertEqual($this->grade_items[1]->id, $grade_item->id);\r
         $this->assertEqual($this->grade_items[1]->iteminfo, $grade_item->iteminfo);\r
     }\r
 \r
-    function test_grade_item_fetch_all_using_this() {\r
+    function test_grade_item_fetch_all() {\r
         $grade_item = new grade_item();\r
-        $grade_item->itemtype = 'mod';\r
-        $this->assertTrue(method_exists($grade_item, 'fetch_all_using_this'));\r
+        $this->assertTrue(method_exists($grade_item, 'fetch_all'));\r
 \r
-        $grade_items = $grade_item->fetch_all_using_this();\r
-        $this->assertEqual(5, count($grade_items));\r
-        $first_grade_item = reset($grade_items);\r
-        $this->assertEqual($this->grade_items[0]->id, $first_grade_item->id);\r
+        $grade_items = grade_item::fetch_all(array('courseid'=>$this->courseid));\r
+        $this->assertEqual(count($this->grade_items), count($grade_items));\r
     }\r
 \r
-\r
     /**\r
      * Retrieve all final scores for a given grade_item.\r
      */\r
@@ -428,20 +424,20 @@ class grade_item_test extends grade_test {
         $grade_item = new grade_item($this->grade_items[1]);\r
         $this->assertTrue(method_exists($grade_item, 'compute'));\r
 \r
-        $grade_grades = grade_grades::fetch('id', $this->grade_grades[3]->id);\r
+        $grade_grades = grade_grades::fetch(array('id'=>$this->grade_grades[3]->id));\r
         $grade_grades->delete();\r
-        $grade_grades = grade_grades::fetch('id', $this->grade_grades[4]->id);\r
+        $grade_grades = grade_grades::fetch(array('id'=>$this->grade_grades[4]->id));\r
         $grade_grades->delete();\r
-        $grade_grades = grade_grades::fetch('id', $this->grade_grades[5]->id);\r
+        $grade_grades = grade_grades::fetch(array('id'=>$this->grade_grades[5]->id));\r
         $grade_grades->delete();\r
 \r
         $grade_item->compute();\r
 \r
-        $grade_grades = grade_grades::fetch('userid', $this->grade_grades[3]->userid, 'itemid', $this->grade_grades[3]->itemid);\r
+        $grade_grades = grade_grades::fetch(array('userid'=>$this->grade_grades[3]->userid, 'itemid'=>$this->grade_grades[3]->itemid));\r
         $this->assertEqual($this->grade_grades[3]->finalgrade, $grade_grades->finalgrade);\r
-        $grade_grades = grade_grades::fetch('userid', $this->grade_grades[4]->userid, 'itemid', $this->grade_grades[4]->itemid);\r
+        $grade_grades = grade_grades::fetch(array('userid'=>$this->grade_grades[4]->userid, 'itemid'=>$this->grade_grades[4]->itemid));\r
         $this->assertEqual($this->grade_grades[4]->finalgrade, $grade_grades->finalgrade);\r
-        $grade_grades = grade_grades::fetch('userid', $this->grade_grades[5]->userid, 'itemid', $this->grade_grades[5]->itemid);\r
+        $grade_grades = grade_grades::fetch(array('userid'=>$this->grade_grades[5]->userid, 'itemid'=>$this->grade_grades[5]->itemid));\r
         $this->assertEqual($this->grade_grades[5]->finalgrade, $grade_grades->finalgrade);\r
     }\r
 \r
index e4164707cb044cb78c9ee705bb40e4a2f22a989f..8f7c35a6c02723ccc107c68b2d2c2fd3c6484e59 100644 (file)
@@ -55,7 +55,8 @@ class grade_outcome_test extends grade_test {
         $this->assertTrue(method_exists($grade_outcome, 'insert'));
 
         $grade_outcome->courseid = $this->courseid;
-        $grade_outcome->shortname = 'Team work';
+        $grade_outcome->shortname = 'tw';
+        $grade_outcome->fullname = 'Team work';
 
         $grade_outcome->insert();
 
@@ -87,9 +88,19 @@ class grade_outcome_test extends grade_test {
         $grade_outcome = new grade_outcome();
         $this->assertTrue(method_exists($grade_outcome, 'fetch'));
 
-        $grade_outcome = grade_outcome::fetch('id', $this->grade_outcomes[0]->id);
+        $grade_outcome = grade_outcome::fetch(array('id'=>$this->grade_outcomes[0]->id));
         $this->assertEqual($this->grade_outcomes[0]->id, $grade_outcome->id);
         $this->assertEqual($this->grade_outcomes[0]->shortname, $grade_outcome->shortname);
+
+        $this->assertEqual($this->scale[2]->id, $grade_outcome->scale->id);
+    }
+
+    function test_grade_outcome_fetch_all() {
+        $grade_outcome = new grade_outcome();
+        $this->assertTrue(method_exists($grade_outcome, 'fetch_all'));
+
+        $grade_outcomes = grade_outcome::fetch_all(array());
+        $this->assertEqual(count($this->grade_outcomes), count($grade_outcomes));
     }
 }
 ?>
index c6bfc9d367b44aadb60b2549c18652dc6bbfd236..c284c4971e7653397d872ef11313201e357349b2 100755 (executable)
@@ -98,7 +98,7 @@ class grade_scale_test extends grade_test {
         $grade_scale = new grade_scale();
         $this->assertTrue(method_exists($grade_scale, 'fetch'));
 
-        $grade_scale = grade_scale::fetch('id', $this->scale[0]->id);
+        $grade_scale = grade_scale::fetch(array('id'=>$this->scale[0]->id));
         $this->assertEqual($this->scale[0]->id, $grade_scale->id);
         $this->assertEqual($this->scale[0]->name, $grade_scale->name);
     }
index 162864f730955cf6e8522061b968df272491d8a5..51201acda3d99a65d29964784ab5a557115f1bab 100644 (file)
@@ -356,13 +356,13 @@ class grade_tree_test extends grade_test {
         $tree->remove_element(7);
         $tree->renumber();
         $tree->update_db();
-        $item = grade_item::fetch('id', $this->grade_items[6]->id);
+        $item = grade_item::fetch(array('id'=>$this->grade_items[6]->id));
         $this->assertTrue(empty($item->id));
 
         $tree->move_element(4, 9);
         $tree->renumber();
         $tree->update_db();
-        $item = grade_item::fetch('id', $this->grade_items[1]->id);
+        $item = grade_item::fetch(array('id'=>$this->grade_items[1]->id));
         $this->assertFalse(empty($item->id));
         $this->assertEqual(8, $item->sortorder);
 
index 64c4753bfafb46ef6ea0b944967cf41c0510f9af..8f5dc9411173510e52f1e7778f224a2d7e3095de 100644 (file)
@@ -43,39 +43,6 @@ require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');
  * 3 users for 3 grade_items
  */
 class gradelib_test extends grade_test {
-
-    function test_grade_get_items() {
-        if (get_class($this) == 'gradelib_test') {
-            $grade_items = grade_get_items($this->courseid);
-
-            $this->assertTrue(is_array($grade_items));
-            $this->assertEqual(count($grade_items), 10);
-        }
-    }
-
-/*
-// obsolted function, should be replaced by grade_update() or removed completely
-    function test_grade_create_category() {
-        if (get_class($this) == 'gradelib_test') {
-            $grade_category = new stdClass();
-            $grade_category->timecreated = mktime();
-            $grade_category->timemodified = mktime();
-
-            $items = array(new grade_item(), new grade_item());
-
-            $grade_category->id = grade_create_category($this->courseid, 'unittestcategory4', $items, GRADE_AGGREGATE_MEAN);
-
-            $last_grade_category = end($this->grade_categories);
-            $this->assertEqual($grade_category->id, $last_grade_category->id + 1);
-
-            $db_grade_category = get_record('grade_categories', 'id', $grade_category->id);
-            $db_grade_category = new grade_category($db_grade_category);
-            $db_grade_category->load_grade_item();
-            $this->grade_categories[] = $db_grade_category;
-            $this->grade_items[] = $db_grade_category->grade_item;
-        }
-    }
-*/
     function test_grade_is_locked() {
         if (get_class($this) == 'gradelib_test') {
             $grade_item = $this->grade_items[0];
diff --git a/tags b/tags
index 5de5db0b18a921a9adbcf578d82b6f2ff2e9cc31..caeaaff8113ff392a144d300537ccb0528405906 100644 (file)
--- a/tags
+++ b/tags
@@ -5404,15 +5404,15 @@ fail    lib/simpletestlib/test_case.php /^        function fail($message = "Fail")
 fatal  mod/chat/chatd.php      /^    function fatal($message) {$/;"    f
 fault  lib/soap/nusoap.php     /^      function fault($faultcode,$faultstring,$faultactor='',$faultdetail=''){$/;"     f
 fcFPP  auth/fc/fcFPP.php       /^    function fcFPP($host="localhost", $port="3333")$/;"       f
-fetch  lib/grade/grade_calculation.php /^    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;"      f
-fetch  lib/grade/grade_category.php    /^    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;"      f
-fetch  lib/grade/grade_grades_final.php        /^    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;"      f
-fetch  lib/grade/grade_grades_raw.php  /^    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;"      f
-fetch  lib/grade/grade_grades_text.php /^    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;"      f
-fetch  lib/grade/grade_history.php     /^    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;"      f
-fetch  lib/grade/grade_item.php        /^    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;"      f
-fetch  lib/grade/grade_outcome.php     /^    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;"      f
-fetch  lib/grade/grade_scale.php       /^    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { $/;"      f
+fetch  lib/grade/grade_calculation.php /^    function fetch($params) { $/;"    f
+fetch  lib/grade/grade_category.php    /^    function fetch($params) { $/;"    f
+fetch  lib/grade/grade_grades_final.php        /^    function fetch($params) { $/;"    f
+fetch  lib/grade/grade_grades_raw.php  /^    function fetch($params) { $/;"    f
+fetch  lib/grade/grade_grades_text.php /^    function fetch($params) { $/;"    f
+fetch  lib/grade/grade_history.php     /^    function fetch($params) { $/;"    f
+fetch  lib/grade/grade_item.php        /^    function fetch($params) { $/;"    f
+fetch  lib/grade/grade_outcome.php     /^    function fetch($params) { $/;"    f
+fetch  lib/grade/grade_scale.php       /^    function fetch($params) { $/;"    f
 fetch  lib/simpletestlib/http.php      /^        function &fetch($timeout) {$/;"       f
 fetch  lib/smarty/Smarty.class.php     /^    function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)$/;"        f
 fetchResponse  lib/simpletestlib/user_agent.php        /^        function &fetchResponse($url, $encoding) {$/;"        f
@@ -12106,7 +12106,7 @@ write   lib/adodb/session/adodb-encrypt-secret.php      /^      function write($data, $key)
 write  lib/adodb/session/adodb-encrypt-sha1.php        /^      function write($data, $key) $/;"        f
 write  lib/adodb/session/adodb-session.php     /^      function write($key, $val) $/;" f
 write  lib/adodb/session/adodb-session2.php    /^      function write($key, $val) $/;" f
-write  lib/excel/OLEwriter.php /^    function write($data) \/\/por ahora sólo a STDOUT$/;"     f
+write  lib/excel/OLEwriter.php /^    function write($data) \/\/por ahora s�lo a STDOUT$/;"   f
 write  lib/excel/Worksheet.php /^    function write($row, $col, $token, $format = 0)$/;"       f
 write  lib/excellib.class.php  /^    function write($row, $col, $token, $format=0) {$/;"       f
 write  lib/odslib.class.php    /^    function write($row, $col, $token, $format=0) {$/;"       f
index 5c17d344283fbeab3359031976b8eb7e425d4c1a..82db24949cc2f7bb096cd86de26f39873358b485 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-   $version = 2007062301;  // YYYYMMDD = date
+   $version = 2007062401;  // YYYYMMDD = date
                            //       XY = increments within a single day
 
    $release = '1.9 dev';    // Human-friendly version name