From 91f9a62c3fe2f63aa8279230fcfd64e5f89d58d0 Mon Sep 17 00:00:00 2001 From: skodak Date: Mon, 3 Mar 2008 11:03:54 +0000 Subject: [PATCH] MDL-13730 site setting for aggregation of scales; merged from MOODLE_19_STABLE --- admin/settings/grades.php | 6 ++++-- lang/en_utf8/grades.php | 2 ++ lib/adminlib.php | 17 +++++++++++++++++ lib/db/upgrade.php | 4 ++++ lib/grade/grade_category.php | 11 +++++------ lib/grade/grade_item.php | 12 +++++++++--- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/admin/settings/grades.php b/admin/settings/grades.php index 668e15e3ac..05ea2f682d 100644 --- a/admin/settings/grades.php +++ b/admin/settings/grades.php @@ -24,10 +24,12 @@ if (has_capability('moodle/grade:manage', $systemcontext) array(GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'), GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades')))); - $temp->add(new admin_setting_configcheckbox('grade_hiddenasdate', get_string('hiddenasdate', 'grades'), get_string('confighiddenasdate', 'grades'), 0, PARAM_INT)); + $temp->add(new admin_setting_regradingcheckbox('grade_includescalesinaggregation', get_string('includescalesinaggregation', 'grades'), get_string('configincludescalesinaggregation', 'grades'), 1)); + + $temp->add(new admin_setting_configcheckbox('grade_hiddenasdate', get_string('hiddenasdate', 'grades'), get_string('confighiddenasdate', 'grades'), 0)); // enable publishing in exports/imports - $temp->add(new admin_setting_configcheckbox('gradepublishing', get_string('gradepublishing', 'grades'), get_string('configgradepublishing', 'grades'), 0, PARAM_INT)); + $temp->add(new admin_setting_configcheckbox('gradepublishing', get_string('gradepublishing', 'grades'), get_string('configgradepublishing', 'grades'), 0)); $temp->add(new admin_setting_configselect('grade_export_displaytype', get_string('gradeexportdisplaytype', 'grades'), get_string('configgradeexportdisplaytype', 'grades'), GRADE_DISPLAY_TYPE_REAL, diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index 8bc775967a..c5dae01d41 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -79,6 +79,7 @@ $string['configgradeletter'] = 'A letter or other symbol used to represent a ran $string['configgradeletterdefault'] = 'A letter or other symbol used to represent a range of grades. Leave this field empty to use the site default (currently $a).'; $string['configgradepublishing'] = 'Enable publishing in exports and imports: Exported grades can be accessed by accessing a URL, without having to log on to a Moodle site. Grades can be imported by accessing such a URL (which means that a Moodle site can import grades published by another site). By default only administrators may use this feature, please educate users before adding required capabilities to other roles (dangers of bookmark sharing and download accelerators, IP restrictions, etc.).'; $string['confighiddenasdate'] = 'If user can not see hidden grades show date of submission instead of \'-\'.'; +$string['configincludescalesinaggregation'] = 'You can change whether scales are to be included as numbers in all aggregated grades across all gradebooks in all courses. CAUTION: changing this setting will force all aggregated grades to be recalculated.'; $string['configmeanselection'] = 'Whether cells with no grade should be included when calculating the mean for each column.'; $string['configprofilereport'] = 'Grade report used on user profile page.'; $string['configshowquickfeedback'] = 'Quick Feedback adds a text input element in each grade cell on the grader report, allowing you to edit the feedback for many grades at once. You can then click the Update button to perform all these changes at once, instead of one at a time.'; @@ -257,6 +258,7 @@ $string['importskippednomanagescale'] = 'You don\'t have permission to add a new $string['importskippedoutcome'] = 'An outcome with shortname \"$a\" already exists in this context, the one in the imported file was skipped.'; $string['importsuccess'] = 'Grade import success'; $string['importxml'] = 'Import XML'; +$string['includescalesinaggregation'] = 'Include scales in aggregation'; $string['incorrectcourseid'] = 'Course ID was incorrect'; $string['incorrectminmax'] = 'The minimum must be lower than the maximum'; $string['inherit'] = 'Inherit'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 092985354e..39f1dba823 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3243,6 +3243,23 @@ class admin_setting_special_gradebookroles extends admin_setting_configmultichec } } +class admin_setting_regradingcheckbox extends admin_setting_configcheckbox { + function write_setting($data) { + global $CFG; + + $oldvalue = $this->config_read($this->name); + $return = parent::write_setting($data); + $newvalue = $this->config_read($this->name); + + if ($oldvalue !== $newvalue) { + // force full regrading + set_field('grade_items', 'needsupdate', 1, 'needsupdate', 0); + } + + return $return; + } +} + /** * Which roles to show on course decription page */ diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 9c377d8688..40d5fa16cf 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2945,6 +2945,10 @@ function xmldb_main_upgrade($oldversion=0) { upgrade_main_savepoint($result, 2007101508.08); } + if ($result && $oldversion < 2007101509) { + // force full regrading + set_field('grade_items', 'needsupdate', 1, 'needsupdate', 0); + } return $result; } diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 495001b6b5..545f9343ff 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -697,16 +697,15 @@ class grade_category extends grade_object { //find max grade foreach ($items as $item) { - if ($item->gradetype != GRADE_TYPE_VALUE) { - // sum only items with value grades, no scales and outcomes! - unset($grade_values[$item->id]); - continue; - } if ($item->aggregationcoef > 0) { // extra credit from this activity - does not affect total continue; } - $max += $item->grademax; + if ($item->gradetype == GRADE_TYPE_VALUE) { + $max += $item->grademax; + } else if ($item->gradetype == GRADE_TYPE_SCALE) { + $max += $item->grademax - 1; // scales min is 1 + } } if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE){ diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 86b01b7761..8ad789c34d 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -1236,11 +1236,17 @@ class grade_item extends grade_object { $outcomes_sql = "AND gi.outcomeid IS NULL"; } + if (empty($CFG->grade_includescalesinaggregation)) { + $gtypes = "gi.gradetype = ".GRADE_TYPE_VALUE; + } else { + $gtypes = "(gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.")"; + } + if ($grade_category->aggregatesubcats) { // return all children excluding category items $sql = "SELECT gi.id FROM {$CFG->prefix}grade_items gi - WHERE (gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.") + WHERE $gtypes $outcomes_sql AND gi.categoryid IN ( SELECT gc.id @@ -1251,7 +1257,7 @@ class grade_item extends grade_object { $sql = "SELECT gi.id FROM {$CFG->prefix}grade_items gi WHERE gi.categoryid = {$grade_category->id} - AND (gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.") + AND $gtypes $outcomes_sql UNION @@ -1260,7 +1266,7 @@ class grade_item extends grade_object { FROM {$CFG->prefix}grade_items gi, {$CFG->prefix}grade_categories gc WHERE (gi.itemtype = 'category' OR gi.itemtype = 'course') AND gi.iteminstance=gc.id AND gc.parent = {$grade_category->id} - AND (gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.") + AND $gtypes $outcomes_sql"; } -- 2.39.5