]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11433 Implemented grade_items.decimals instead of user preference in grader report.
authornicolasconnault <nicolasconnault>
Tue, 25 Sep 2007 14:40:49 +0000 (14:40 +0000)
committernicolasconnault <nicolasconnault>
Tue, 25 Sep 2007 14:40:49 +0000 (14:40 +0000)
13 files changed:
grade/edit/gradedisplay/gradedisplay_form.php
grade/edit/gradedisplay/index.php
grade/edit/tree/grade.php
grade/edit/tree/item.php
grade/edit/tree/item_form.php
grade/edit/tree/outcomeitem.php
grade/report/grader/lib.php
grade/report/grader/preferences_form.php
grade/report/user/lib.php
grade/report/user/version.php
lib/formslib.php
lib/grade/constants.php
lib/grade/grade_item.php

index c4dab1d73b73d60d845b8201623850e6c84d026e..5c4f04a7db0848252ef857ce97aa2770c2fccc8b 100644 (file)
@@ -11,6 +11,7 @@ class edit_grade_display_form extends moodleform {
         $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
         $course_has_letters = $this->_customdata['course_has_letters'];
         $coursegradedisplaytype = get_field('grade_items', 'display', 'courseid', $COURSE->id, 'itemtype', 'course');
+        $coursegradedecimals    = get_field('grade_items', 'decimals', 'courseid', $COURSE->id, 'itemtype', 'course');
 
         $mform->addElement('header', 'coursesettings', get_string('coursesettings', 'grades'));
 
@@ -18,16 +19,32 @@ class edit_grade_display_form extends moodleform {
                                    GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
                                    GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
                                    GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
-        $mform->addElement('select', 'gradedisplaytype', get_string('coursegradedisplaytype', 'grades'), $gradedisplaytypes);
-        $mform->setHelpButton('gradedisplaytype', array(false, get_string('coursegradedisplaytype', 'grades'),
+        $label = get_string('coursegradedisplaytype', 'grades') . ' (' . get_string('default', 'grades') . ': '
+                . $gradedisplaytypes[$CFG->grade_report_gradedisplaytype] . ')';
+        $mform->addElement('select', 'display', $label, $gradedisplaytypes);
+        $mform->setHelpButton('display', array(false, get_string('coursegradedisplaytype', 'grades'),
                 false, true, false, get_string('configcoursegradedisplaytype', 'grades')));
-        $mform->setDefault('gradedisplaytype', $coursegradedisplaytype);
+        $mform->setDefault('display', $coursegradedisplaytype);
         $mform->setType($coursegradedisplaytype, PARAM_INT);
 
+        $options = array(GRADE_DECIMALS_DEFAULT => get_string('default', 'grades'), 0, 1, 2, 3, 4, 5);
+        $label = get_string('decimalpoints', 'grades') . ' (' . get_string('default', 'grades') . ': ' . $options[$CFG->grade_report_decimalpoints] . ')';
+        $mform->addElement('select', 'decimals', $label, $options);
+        $mform->setHelpButton('decimals', array(false, get_string('decimalpoints', 'grades'), false, true, false, get_string("configdecimalpoints", 'grades')));
+        $mform->setDefault('decimals', $coursegradedecimals);
+
+        // Disable decimals if displaytype is not REAL or PERCENTAGE
+        $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_LETTER);
+
         $course_set_to_letters  = $coursegradedisplaytype == GRADE_DISPLAY_TYPE_LETTER;
         $course_set_to_default  = $coursegradedisplaytype == GRADE_DISPLAY_TYPE_DEFAULT;
         $site_set_to_letters = $CFG->grade_report_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER;
 
+        // Disable decimals if course displaytype is DEFAULT and site displaytype is LETTER
+        if ($site_set_to_letters) {
+            $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
+        }
+
         if ($course_set_to_letters || ($course_set_to_default && $site_set_to_letters)) {
 
             $mform->addElement('header', 'gradeletters', get_string('gradeletters', 'grades'));
index 22d035403d44259726f09882c006367cc58f2e98..e0ab28c94a105ebf80983b2285eba3092467e189 100644 (file)
@@ -51,8 +51,16 @@ if ($mform->is_cancelled()) {
     }
 
     // Update course item's gradedisplay type
-    if (isset($data->gradedisplaytype)) {
-        set_field('grade_items', 'display', $data->gradedisplaytype, 'courseid', $courseid, 'itemtype', 'course');
+    if (isset($data->display)) {
+        set_field('grade_items', 'display', $data->display, 'courseid', $courseid, 'itemtype', 'course');
+    }
+
+    // Update course item's decimals type
+    if (isset($data->decimals)) {
+        if (strlen($data->decimals) < 1) {
+            $data->decimals = null;
+        }
+        set_field('grade_items', 'decimals', $data->decimals, 'courseid', $courseid, 'itemtype', 'course');
     }
 
     // If override is present, add/update entries in grade_letters table
index 0f7dd0258621083f74ca54fb35afa91eed593351..edec72fd1795e60f909aaaa38a4801386ae01357 100644 (file)
@@ -110,8 +110,7 @@ if ($grade = get_record('grade_grades', 'itemid', $grade_item->id, 'userid', $us
             $grade->finalgrade = (int)$grade->finalgrade;
         }
     } else if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
-        $decimalpoints = grade_report::get_pref('decimalpoints', $grade_item->id);
-        $grade->finalgrade = format_float($grade->finalgrade, $decimalpoints);
+        $grade->finalgrade = format_float($grade->finalgrade, $grade_item->get_decimals());
     }
 
     $grade->oldgrade = $grade->finalgrade;
index fcdc34be988fe56b686f8c74cb98a5c051635e97..a44b87e63f00db24e93aa238d0ce4a80692a83e3 100644 (file)
@@ -26,28 +26,17 @@ if ($mform->is_cancelled()) {
     redirect($returnurl);
 }
 
-if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
+if ($item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
     // redirect if outcomeid present
     if (!empty($item->outcomeid) && !empty($CFG->enableoutcomes)) {
         $url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&amp;courseid='.$courseid;
         redirect($gpr->add_url_params($url));
     }
-    // Get Item preferences
-    $item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype', $item->id);
-    $item->pref_decimalpoints    = grade_report::get_pref('decimalpoints', $item->id);
-
-    $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
-
-    $decimalpoints = grade_report::get_pref('decimalpoints', $item->id);
-
+    $item->calculation = grade_item::denormalize_formula($item->calculation, $courseid);
 } else {
     $item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false);
-    // Get Item preferences
-    $item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype');
-    $item->pref_decimalpoints    = grade_report::get_pref('decimalpoints');
-
-    $decimalpoints = grade_report::get_pref('decimalpoints');
 }
+$decimalpoints = $item->get_decimals();
 
 if ($item->hidden > 1) {
     $item->hiddenuntil = $item->hidden;
@@ -91,9 +80,13 @@ if ($data = $mform->get_data(false)) {
 
     $grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
     grade_item::set_properties($grade_item, $data);
-
     $grade_item->outcomeid = null;
 
+    // Handle null decimals value
+    if (strlen($data->decimals) < 1) {
+        $grade_item->decimals = null;
+    }
+
     if (empty($grade_item->id)) {
         $grade_item->itemtype = 'manual'; // all new items to be manual only
         $grade_item->insert();
@@ -112,19 +105,6 @@ if ($data = $mform->get_data(false)) {
     $grade_item->set_locktime($locktime); // locktime first - it might be removed when unlocking
     $grade_item->set_locked($locked, false, true);
 
-    // Handle user preferences
-    if (isset($data->pref_gradedisplaytype)) {
-        if (!grade_report::set_pref('gradedisplaytype', $data->pref_gradedisplaytype, $grade_item->id)) {
-            error("Could not set preference gradedisplaytype to $value for this grade item");
-        }
-    }
-
-    if (isset($data->pref_decimalpoints)) {
-        if (!grade_report::set_pref('decimalpoints', $data->pref_decimalpoints, $grade_item->id)) {
-            error("Could not set preference decimalpoints to $value for this grade item");
-        }
-    }
-
     redirect($returnurl);
 }
 
index 36836e4f502ae6d711ccd2117ba23af5721f11c3..4a6297306951d6300255d42162ff6ee69259b956 100644 (file)
@@ -88,16 +88,38 @@ class edit_item_form extends moodleform {
             $default_gradedisplaytype = $site_gradedisplaytype;
         }
 
-        $options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'),
+        $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'),
                          GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
                          GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
                          GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
-        $label = get_string('gradedisplaytype', 'grades') . ' (' . get_string('default', 'grades')
-               . ': ' . $options[$default_gradedisplaytype] . ')';
+        $label = get_string('gradedisplaytype', 'grades') . ' (' . get_string('default', 'grades') . ': ' . $options[$default_gradedisplaytype] . ')';
         $mform->addElement('select', 'display', $label, $options);
         $mform->setHelpButton('display', array(false, get_string('gradedisplaytype', 'grades'),
                               false, true, false, get_string("configgradedisplaytype", 'grades')));
 
+        // Determine default value for decimalpoints (site or course)
+        $course_gradedecimals = get_field('grade_items', 'decimals', 'courseid', $COURSE->id, 'itemtype', 'course');
+        $site_gradedecimals = $CFG->grade_report_decimalpoints;
+        $default_gradedecimals = $course_gradedecimals;
+
+        if ($course_gradedecimals == GRADE_DECIMALS_DEFAULT) {
+            $default_gradedecimals = $site_gradedecimals;
+        }
+        $options = array(GRADE_DECIMALS_DEFAULT => get_string('default', 'grades'), 0, 1, 2, 3, 4, 5);
+        $label = get_string('decimalpoints', 'grades') . ' (' . get_string('default', 'grades') . ': ' . $options[$default_gradedecimals] . ')';
+        $mform->addElement('select', 'decimals', $label, $options);
+        $mform->setHelpButton('decimals', array(false, get_string('decimalpoints', 'grades'),
+                              false, true, false, get_string("configdecimalpoints", 'grades')));
+        $mform->setDefault('decimals', GRADE_REPORT_PREFERENCE_DEFAULT);
+
+        // Disable decimals if displaytype is not REAL or PERCENTAGE
+        $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_LETTER);
+
+        // Disable decimals if displaytype is DEFAULT and course or site displaytype is LETTER
+        if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
+            $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
+        }
+
         /// hiding
         /// advcheckbox is not compatible with disabledIf !!
         $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
@@ -114,17 +136,6 @@ class edit_item_form extends moodleform {
         $mform->setHelpButton('locktime', array('locktime', get_string('locktime', 'grades'), 'grade'));
         $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
 
-        // user preferences
-        $mform->addElement('header', 'general', get_string('userpreferences', 'grades'));
-
-        $options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'), 0, 1, 2, 3, 4, 5);
-        $label = get_string('decimalpoints', 'grades') . ' (' . get_string('default', 'grades')
-               . ': ' . $options[$CFG->grade_report_decimalpoints] . ')';
-        $mform->addElement('select', 'pref_decimalpoints', $label, $options);
-        $mform->setHelpButton('pref_decimalpoints', array(false, get_string('decimalpoints', 'grades'),
-                              false, true, false, get_string("configdecimalpoints", 'grades')));
-        $mform->setDefault('pref_decimalpoints', GRADE_REPORT_PREFERENCE_DEFAULT);
-
 /// hidden params
         $mform->addElement('hidden', 'id', 0);
         $mform->setType('id', PARAM_INT);
index 9c81b7feb6d6f2e600ffbc2ce30aa22e63b776c8..6bea8b76b53e9265a753937b5eb8ba76ebaac1d6 100644 (file)
@@ -33,14 +33,7 @@ if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
         $url = $CFG->wwwroot.'/grade/edit/tree/item.php?id='.$id.'&amp;courseid='.$courseid;
         redirect($gpr->add_url_params($url));
     }
-    // Get Item preferences
-    $item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype', $item->id);
-    $item->pref_decimalpoints    = grade_report::get_pref('decimalpoints', $item->id);
-
     $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
-
-    $decimalpoints = grade_report::get_pref('decimalpoints', $item->id);
-
     if ($item->itemtype == 'mod') {
         $cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
         $item->cmid = $cm->id;
@@ -50,15 +43,11 @@ if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
 
 } else {
     $item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'));
-    // Get Item preferences
-    $item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype');
-    $item->pref_decimalpoints    = grade_report::get_pref('decimalpoints');
-
-    $decimalpoints = grade_report::get_pref('decimalpoints');
-
     $item->cmid = 0;
 }
 
+$decimalpoints = $item->get_decimals();
+
 if ($item->hidden > 1) {
     $item->hiddenuntil = $item->hidden;
     $item->hidden = 0;
index edfa1acaa5faab044a1f87f6ba301f3b59f5a26b..0ceb6ee6418f5f1f5691bdda54f6d835f8bac305 100644 (file)
@@ -607,7 +607,7 @@ class grade_report_grader extends grade_report {
 
             foreach ($this->items as $itemid=>$item) {
                 // Get the decimal points preference for this item
-                $decimalpoints = $this->get_pref('decimalpoints', $item->id);
+                $decimalpoints = $item->get_decimals();
 
                 if (isset($this->finalgrades[$userid][$item->id])) {
                     $gradeval = $this->finalgrades[$userid][$item->id]->finalgrade;
@@ -896,7 +896,7 @@ class grade_report_grader extends grade_report {
                     $mean_count = $totalcount;
                 }
 
-                $decimalpoints = $this->get_pref('decimalpoints', $item->id);
+                $decimalpoints = $item->get_decimals();
 
                 // Determine which display type to use for this average
                 $gradedisplaytype = $item->get_displaytype();
@@ -909,6 +909,7 @@ class grade_report_grader extends grade_report {
                     $displaytype = $averagesdisplaytype;
                 }
 
+                // Override grade_item setting if a display preference (not inherit) was set for the averages
                 if ($averagesdecimalpoints != GRADE_REPORT_PREFERENCE_INHERIT) {
                     $decimalpoints = $averagesdecimalpoints;
                 }
@@ -974,8 +975,8 @@ class grade_report_grader extends grade_report {
             $columncount = 1;
             foreach ($this->items as $item) {
 
-                $decimalpoints = $this->get_pref('decimalpoints', $item->id);
                 // Determine which display type to use for this range
+                $decimalpoints = $item->get_decimals();
                 $gradedisplaytype = $item->get_displaytype();
 
                 if ($USER->gradeediting[$this->courseid]) {
@@ -986,6 +987,7 @@ class grade_report_grader extends grade_report {
                     $displaytype = $rangesdisplaytype;
                 }
 
+                // If ranges decimal points pref is set (but not to inherit), override grade_item setting
                 if ($rangesdecimalpoints != GRADE_REPORT_PREFERENCE_INHERIT) {
                     $decimalpoints = $rangesdecimalpoints;
                 }
index 86c2d99f27e570676193f2e860836c5576cac665..bb8d25b904d7ab6c04a1f1b924d32064f9377e0b 100644 (file)
@@ -35,7 +35,6 @@ class grader_report_preferences_form extends moodleform {
         // Initialise the preferences arrays with grade:manage capabilities
         if (has_capability('moodle/grade:manage', $context)) {
             $preferences['prefgeneral'] = array(
-                          'decimalpoints'       => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default', 0, 1, 2, 3, 4, 5),
                           'aggregationview'     => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
                                                          GRADE_REPORT_AGGREGATION_VIEW_FULL => get_string('fullmode', 'grades'),
                                                          GRADE_REPORT_AGGREGATION_VIEW_AGGREGATES_ONLY => get_string('aggregatesonly', 'grades'),
index 384d6be50ab03a7e74e302af362a84952bc45460..e65b75ee110424387c85191b4530e6bf9929369c 100644 (file)
@@ -108,10 +108,10 @@ class grade_report_user extends grade_report {
             $total = $grade_items[1];
             unset($grade_items[1]);
             $grade_items[] = $total;
-            
+
             foreach ($grade_items as $grade_item) {
 
-                $decimalpoints = $this->get_pref('decimalpoints', $grade_item->id);
+                $decimalpoints = $grade_item->get_decimals();
                 $data = array();
 
                 $grade_grade = new grade_grade(array('itemid'=>$grade_item->id, 'userid'=>$this->user->id));
@@ -138,14 +138,14 @@ class grade_report_user extends grade_report {
                     $excluded = '';
                 }
 
-                if ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {         
-                 
+                if ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {
+
                     if ((int) $grade_grade->finalgrade < 1) {
-                        $data[] = '-'; 
+                        $data[] = '-';
                     } else {
                         $data[] = get_string('gradedon', 'grades', userdate($grade_grade->timemodified));
                     }
-                 
+
                 } else {
                     if ($grade_item->scaleid) {
                         // using scales
@@ -162,8 +162,8 @@ class grade_report_user extends grade_report {
                     } else {
                         // normal grade, or text, just display
                         if ((int) $grade_grade->finalgrade < 1) {
-                            $data[] = $excluded.'-'; 
-                        } else { 
+                            $data[] = $excluded.'-';
+                        } else {
                             $data[] = $excluded.format_float($grade_grade->finalgrade, $decimalpoints);
                         }
                     }
@@ -172,7 +172,7 @@ class grade_report_user extends grade_report {
 
                 if ($grade_grade->is_hidden() && !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $grade_item->courseid))) {
                     if ((int) $grade_grade->finalgrade < 1) {
-                        $data[] = '-'; 
+                        $data[] = '-';
                     } else {
                         $data[] = get_string('gradedon', 'grades', userdate($grade_grade->timemodified));
                     }
index 55d7451372e087ddba71095d31fdce8947ce89f5..cc80428f1394192c964c5c6dbb309b7ebcc3c900 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP // $Id$
 
-$plugin->version  = 2007072500;
-$plugin->requires = 2007072402;
+$plugin->version  = 2007092500;
+$plugin->requires = 2007092501;
 
 ?>
index 05e4f9fe58095053230263df40c7f01a675cfaa4..0431b60003d6c5383b0f548c74bd6991a5e6b9a4 100644 (file)
@@ -1288,8 +1288,8 @@ function validate_' . $this->_formName . '(frm) {
      * Adds a dependency for $elementName which will be disabled if $condition is met.
      * If $condition = 'notchecked' (default) then the condition is that the $dependentOn element
      * is not checked. If $condition = 'checked' then the condition is that the $dependentOn element
-     * is checked. If $condition is something else then it is checked to see if the value
-     * of the $dependentOn element is equal to $condition.
+     * is checked. If $condition is something else (like "eq" for equals) then it is checked to see if the value
+     * of the $dependentOn element is $condition (such as equal) to $value.
      *
      * @param string $elementName the name of the element which will be disabled
      * @param string $dependentOn the name of the element whose state will be checked for
index 84e6d7b3a20f200093f3af42c264d2a7704e1f87..5569476e6745a5425fa9bc66a907b10cdf8d93f9 100644 (file)
@@ -68,6 +68,7 @@ define('GRADE_DISPLAY_TYPE_DEFAULT', 0);
 define('GRADE_DISPLAY_TYPE_REAL', 1);
 define('GRADE_DISPLAY_TYPE_PERCENTAGE', 2);
 define('GRADE_DISPLAY_TYPE_LETTER', 3);
+define('GRADE_DECIMALS_DEFAULT', null);
 define('GRADE_REPORT_PREFERENCE_DEFAULT', 'default');
 define('GRADE_REPORT_PREFERENCE_INHERIT', 'inherit');
 define('GRADE_REPORT_PREFERENCE_UNUSED', -1);
index a38d8db6d382addbafc4fb8bce807eb35f777466..e6e493ecd681553223c3abb13c735c3c0a9ee253 100644 (file)
@@ -43,7 +43,7 @@ class grade_item extends grade_object {
     var $required_fields = array('id', 'courseid', 'categoryid', 'itemname', 'itemtype', 'itemmodule', 'iteminstance',
                                  'itemnumber', 'iteminfo', 'idnumber', 'calculation', 'gradetype', 'grademax', 'grademin',
                                  'scaleid', 'outcomeid', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef',
-                                 'sortorder', 'display', 'hidden', 'locked', 'locktime', 'needsupdate', 'timecreated',
+                                 'sortorder', 'display', 'decimals', 'hidden', 'locked', 'locktime', 'needsupdate', 'timecreated',
                                  'timemodified');
 
     /**
@@ -206,7 +206,13 @@ class grade_item extends grade_object {
      * Display type of the grades (Real, Percentage, Letter, or default).
      * @var int $display
      */
-    var $display = -1;
+    var $display = GRADE_DISPLAY_TYPE_DEFAULT;
+
+    /**
+     * The number of digits after the decimal point symbol. Applies only to REAL and PERCENTAGE grade display types.
+     * @var int $decimals
+     */
+    var $decimals = GRADE_DECIMALS_DEFAULT;
 
     /**
      * 0 if visible, 1 always hidden or date not visible until
@@ -1691,13 +1697,32 @@ class grade_item extends grade_object {
         $site_gradedisplaytype = $CFG->grade_report_gradedisplaytype;
         $default_gradedisplaytype = $this->display;
 
-        if ($this->display == GRADE_REPORT_PREFERENCE_DEFAULT) {
+        if ($this->display == GRADE_DISPLAY_TYPE_DEFAULT) {
             $default_gradedisplaytype = $course_gradedisplaytype;
-            if ($course_gradedisplaytype == GRADE_REPORT_PREFERENCE_DEFAULT) {
+            if ($course_gradedisplaytype == GRADE_DISPLAY_TYPE_DEFAULT) {
                 $default_gradedisplaytype = $site_gradedisplaytype;
             }
         }
         return $default_gradedisplaytype;
     }
+
+    /**
+     * Returns the value of the decimals field. It can be set at 3 levels: grade_item, course and site. The lowest level overrides the higher ones.
+     * @return int Decimals (0 - 5)
+     */
+    function get_decimals() {
+        global $CFG;
+        $course_gradedecimals = get_field('grade_items', 'decimals', 'courseid', $this->courseid, 'itemtype', 'course');
+        $site_gradedecimals = $CFG->grade_report_decimalpoints;
+        $item_gradedecimals = $this->decimals;
+
+        if ($this->decimals == GRADE_DECIMALS_DEFAULT) {
+            $item_gradedecimals = $course_gradedecimals;
+            if ($course_gradedecimals == GRADE_DECIMALS_DEFAULT) {
+                $item_gradedecimals = $site_gradedecimals;
+            }
+        }
+        return $item_gradedecimals;
+    }
 }
 ?>