From dafbc521ba568000aaf5092a6e21b6f3c119da72 Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 28 Sep 2007 11:08:44 +0000 Subject: [PATCH] MDL-11495 removed GRADE_DECIMALS_DEFAULT null constant, is_null() used instead for tests, -1 used in menu options --- grade/edit/gradedisplay/gradedisplay_form.php | 2 +- grade/edit/gradedisplay/index.php | 2 +- grade/edit/tree/item.php | 2 +- grade/edit/tree/item_form.php | 11 ++++------- lib/grade/constants.php | 1 - lib/grade/grade_item.php | 6 +++--- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/grade/edit/gradedisplay/gradedisplay_form.php b/grade/edit/gradedisplay/gradedisplay_form.php index 5c4f04a7db..ab332611ca 100644 --- a/grade/edit/gradedisplay/gradedisplay_form.php +++ b/grade/edit/gradedisplay/gradedisplay_form.php @@ -27,7 +27,7 @@ class edit_grade_display_form extends moodleform { $mform->setDefault('display', $coursegradedisplaytype); $mform->setType($coursegradedisplaytype, PARAM_INT); - $options = array(GRADE_DECIMALS_DEFAULT => get_string('default', 'grades'), 0, 1, 2, 3, 4, 5); + $options = array(-1=>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'))); diff --git a/grade/edit/gradedisplay/index.php b/grade/edit/gradedisplay/index.php index e0ab28c94a..a06cc8c23d 100644 --- a/grade/edit/gradedisplay/index.php +++ b/grade/edit/gradedisplay/index.php @@ -57,7 +57,7 @@ if ($mform->is_cancelled()) { // Update course item's decimals type if (isset($data->decimals)) { - if (strlen($data->decimals) < 1) { + if ($data->decimals < 0) { $data->decimals = null; } set_field('grade_items', 'decimals', $data->decimals, 'courseid', $courseid, 'itemtype', 'course'); diff --git a/grade/edit/tree/item.php b/grade/edit/tree/item.php index a44b87e63f..e48199d0e1 100644 --- a/grade/edit/tree/item.php +++ b/grade/edit/tree/item.php @@ -83,7 +83,7 @@ if ($data = $mform->get_data(false)) { $grade_item->outcomeid = null; // Handle null decimals value - if (strlen($data->decimals) < 1) { + if (!array_key_exists('decimals', $data) or $data->decimals < 0) { $grade_item->decimals = null; } diff --git a/grade/edit/tree/item_form.php b/grade/edit/tree/item_form.php index 4a62973069..2254dd7e67 100644 --- a/grade/edit/tree/item_form.php +++ b/grade/edit/tree/item_form.php @@ -98,14 +98,11 @@ class edit_item_form extends moodleform { 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; + $default_gradedecimals = get_field('grade_items', 'decimals', 'courseid', $COURSE->id, 'itemtype', 'course'); + if (is_null($default_gradedecimals)) { + $default_gradedecimals = $CFG->grade_report_decimalpoints; } - $options = array(GRADE_DECIMALS_DEFAULT => get_string('default', 'grades'), 0, 1, 2, 3, 4, 5); + $options = array(-1=>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'), diff --git a/lib/grade/constants.php b/lib/grade/constants.php index 3ca326b414..b56b0f33d8 100644 --- a/lib/grade/constants.php +++ b/lib/grade/constants.php @@ -64,7 +64,6 @@ 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_AGGREGATION_POSITION_LEFT', 0); define('GRADE_REPORT_AGGREGATION_POSITION_RIGHT', 1); diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 26b20e908e..c3e4b46431 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -212,7 +212,7 @@ class grade_item extends grade_object { * 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; + var $decimals = null; /** * 0 if visible, 1 always hidden or date not visible until @@ -1722,14 +1722,14 @@ class grade_item extends grade_object { global $CFG; static $cache = array(); - if ($this->decimals == GRADE_DECIMALS_DEFAULT) { + if (is_null($this->decimals)) { if (array_key_exists($this->courseid, $cache)) { return $cache[$this->courseid]; } else if (count($cache) > 100) { $cache = array(); // cache size limit } $gradedecimals = get_field('grade_items', 'decimals', 'courseid', $this->courseid, 'itemtype', 'course'); - if ($gradedecimals == GRADE_DECIMALS_DEFAULT) { + if (is_null($gradedecimals)) { $gradedecimals = $CFG->grade_report_decimalpoints; } $cache[$this->courseid] = $gradedecimals; -- 2.39.5