From: nicolasconnault Date: Fri, 14 Sep 2007 17:21:30 +0000 (+0000) Subject: MDL-11278 Implementation is complete, but grade_categories records in DB are not... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e171963b3eb5de656665a036db651c95818277c4;p=moodle.git MDL-11278 Implementation is complete, but grade_categories records in DB are not affected by global settings. This way, when global settings are switched back to "Do not Force", the original category settings will be in place. --- diff --git a/admin/settings/grades.php b/admin/settings/grades.php index 96196dd633..689528c06d 100644 --- a/admin/settings/grades.php +++ b/admin/settings/grades.php @@ -33,14 +33,14 @@ $options = array(-1 => $strnoforce, GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN =>get_string('aggregateweightedmean', 'grades'), GRADE_AGGREGATE_EXTRACREDIT_MEAN=>get_string('aggregateextracreditmean', 'grades')); -$temp->add(new admin_setting_configselect('aggregation', get_string('aggregation', 'grades'), get_string('aggregationhelp', 'grades'), -1, $options)); +$temp->add(new admin_setting_configselect('grade_aggregation', get_string('aggregation', 'grades'), get_string('aggregationhelp', 'grades'), -1, $options)); $options = array(-1 => $strnoforce, 0 => get_string('forceoff', 'grades'), 1 => get_string('forceon', 'grades')); -$temp->add(new admin_setting_configselect('aggregateonlygraded', get_string('aggregateonlygraded', 'grades'), +$temp->add(new admin_setting_configselect('grade_aggregateonlygraded', get_string('aggregateonlygraded', 'grades'), get_string('aggregateonlygradedhelp', 'grades'), -1, $options)); -$temp->add(new admin_setting_configselect('aggregateoutcomes', get_string('aggregateoutcomes', 'grades'), +$temp->add(new admin_setting_configselect('grade_aggregateoutcomes', get_string('aggregateoutcomes', 'grades'), get_string('aggregateoutcomeshelp', 'grades'), -1, $options)); -$temp->add(new admin_setting_configselect('aggregatesubcats', get_string('aggregatesubcats', 'grades'), +$temp->add(new admin_setting_configselect('grade_aggregatesubcats', get_string('aggregatesubcats', 'grades'), get_string('aggregatesubcatshelp', 'grades'), -1, $options)); $options = array(-1 => $strnoforce, 0 => get_string('none')); @@ -48,9 +48,9 @@ for ($i=1; $i<=20; $i++) { $options[$i] = $i; } -$temp->add(new admin_setting_configselect('keephigh', get_string('keephigh', 'grades'), +$temp->add(new admin_setting_configselect('grade_keephigh', get_string('keephigh', 'grades'), get_string('keephighhelp', 'grades'), -1, $options)); -$temp->add(new admin_setting_configselect('droplow', get_string('droplow', 'grades'), +$temp->add(new admin_setting_configselect('grade_droplow', get_string('droplow', 'grades'), get_string('droplowhelp', 'grades'), -1, $options)); $ADMIN->add('grades', $temp); diff --git a/grade/edit/tree/category_form.php b/grade/edit/tree/category_form.php index 03007c6d5c..134eb525a7 100644 --- a/grade/edit/tree/category_form.php +++ b/grade/edit/tree/category_form.php @@ -3,54 +3,89 @@ require_once $CFG->libdir.'/formslib.php'; class edit_category_form extends moodleform { + var $aggregation_types = array(); + var $keepdrop_options = array(); + function definition() { global $CFG; $mform =& $this->_form; + $this->aggregation_types = array(GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', 'grades'), + GRADE_AGGREGATE_MEDIAN =>get_string('aggregatemedian', 'grades'), + GRADE_AGGREGATE_MIN =>get_string('aggregatemin', 'grades'), + GRADE_AGGREGATE_MAX =>get_string('aggregatemax', 'grades'), + GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'), + GRADE_AGGREGATE_WEIGHTED_MEAN =>get_string('aggregateweightedmean', 'grades'), + GRADE_AGGREGATE_EXTRACREDIT_MEAN=>get_string('aggregateextracreditmean', 'grades')); + // visible elements $mform->addElement('header', 'general', get_string('gradecategory', 'grades')); $mform->addElement('text', 'fullname', get_string('categoryname', 'grades')); - $options = array(GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', 'grades'), - GRADE_AGGREGATE_MEDIAN =>get_string('aggregatemedian', 'grades'), - GRADE_AGGREGATE_MIN =>get_string('aggregatemin', 'grades'), - GRADE_AGGREGATE_MAX =>get_string('aggregatemax', 'grades'), - GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'), - GRADE_AGGREGATE_WEIGHTED_MEAN =>get_string('aggregateweightedmean', 'grades'), - GRADE_AGGREGATE_EXTRACREDIT_MEAN=>get_string('aggregateextracreditmean', 'grades')); + if ($CFG->grade_aggregation == -1) { - $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $options); - $mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade')); - $mform->setDefault('gradetype', GRADE_AGGREGATE_MEAN); + $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_types); + $mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade')); + $mform->setDefault('aggregation', GRADE_AGGREGATE_MEAN); + } else { + $mform->addElement('static', 'aggregation', get_string('aggregation', 'grades')); + } - $mform->addElement('advcheckbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades')); - $mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'), - false, true, false, get_string('aggregateonlygradedhelp', 'grades'))); + if ($CFG->grade_aggregateonlygraded == -1) { + $mform->addElement('advcheckbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades')); + $mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'), + false, true, false, get_string('aggregateonlygradedhelp', 'grades'))); + } else { + $mform->addElement('static', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades')); + } - if (!empty($CFG->enableoutcomes)) { + if (!empty($CFG->enableoutcomes) && $CFG->grade_aggregateoutcomes == -1) { $mform->addElement('advcheckbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades')); $mform->setHelpButton('aggregateoutcomes', array(false, get_string('aggregateoutcomes', 'grades'), false, true, false, get_string('aggregateoutcomeshelp', 'grades'))); + } else { + $mform->addElement('static', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades')); } - $mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades')); - $mform->setHelpButton('aggregatesubcats', array(false, get_string('aggregatesubcats', 'grades'), - false, true, false, get_string('aggregatesubcatshelp', 'grades'))); + if ($CFG->grade_aggregatesubcats == -1) { + $mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades')); + $mform->setHelpButton('aggregatesubcats', array(false, get_string('aggregatesubcats', 'grades'), + false, true, false, get_string('aggregatesubcatshelp', 'grades'))); + } else { + $mform->addElement('static', 'aggregatesubcats', get_string('aggregatesubcats', 'grades')); + } - $options = array(); - $options[0] = get_string('none'); + $this->keepdrop_options = array(); + $this->keepdrop_options[0] = get_string('none'); for ($i=1; $i<=20; $i++) { - $options[$i] = $i; + $this->keepdrop_options[$i] = $i; + } + + $keepdrop_present = 0; + + if ($CFG->grade_keephigh == -1) { + $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $this->keepdrop_options); + $mform->setHelpButton('keephigh', array(false, get_string('keephigh', 'grades'), + false, true, false, get_string('keephighhelp', 'grades'))); + $keepdrop_present++; + } else { + $mform->addElement('static', 'keephigh', get_string('keephigh', 'grades')); + } + + if ($CFG->grade_droplow == -1) { + $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options); + $mform->setHelpButton('droplow', array(false, get_string('droplow', 'grades'), + false, true, false, get_string('droplowhelp', 'grades'))); + $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); + $keepdrop_present++; + } else { + $mform->addElement('static', 'droplow', get_string('droplow', 'grades')); } - $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $options); - $mform->setHelpButton('keephigh', array(false, get_string('keephigh', 'grades'), - false, true, false, get_string('keephighhelp', 'grades'))); - $mform->disabledIf('keephigh', 'droplow', 'noteq', 0); - $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options); - $mform->setHelpButton('droplow', array(false, get_string('droplow', 'grades'), - false, true, false, get_string('droplowhelp', 'grades'))); - $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); + if ($keepdrop_present == 2) { + $mform->disabledIf('keephigh', 'droplow', 'noteq', 0); + $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); + } // user preferences $mform->addElement('header', 'general', get_string('userpreferences', 'grades')); @@ -88,6 +123,38 @@ class edit_category_form extends moodleform { $mform =& $this->_form; + $checkbox_values = array(get_string('no'), get_string('yes')); + + if ($CFG->grade_aggregation != -1) { + $agg_el =& $mform->getElement('aggregation'); + $agg_el->setValue($this->aggregation_types[$CFG->grade_aggregation]); + } + + if ($CFG->grade_aggregateonlygraded != -1) { + $agg_el =& $mform->getElement('aggregateonlygraded'); + $agg_el->setValue($checkbox_values[$CFG->grade_aggregateonlygraded]); + } + + if ($CFG->grade_aggregateoutcomes != -1) { + $agg_el =& $mform->getElement('aggregateoutcomes'); + $agg_el->setValue($checkbox_values[$CFG->grade_aggregateoutcomes]); + } + + if ($CFG->grade_aggregatesubcats != -1) { + $agg_el =& $mform->getElement('aggregatesubcats'); + $agg_el->setValue($checkbox_values[$CFG->grade_aggregatesubcats]); + } + + if ($CFG->grade_keephigh != -1) { + $agg_el =& $mform->getElement('keephigh'); + $agg_el->setValue($this->keepdrop_options[$CFG->grade_keephigh]); + } + + if ($CFG->grade_droplow != -1) { + $agg_el =& $mform->getElement('droplow'); + $agg_el->setValue($this->keepdrop_options[$CFG->grade_droplow]); + } + if ($id = $mform->getElementValue('id')) { $grade_category = grade_category::fetch(array('id'=>$id)); $grade_item = $grade_category->load_grade_item(); diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 926e42b9a5..048cacbbeb 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -432,6 +432,7 @@ class grade_category extends grade_object { * internal function for category grades aggregation */ function aggregate_grades($userid, $items, $grade_values, $oldgrade, $excluded) { + global $CFG; if (empty($userid)) { //ignore first call return; @@ -488,6 +489,11 @@ class grade_category extends grade_object { $grade_values[$itemid] = grade_grade::standardise_score($v, $items[$itemid]->grademin, $items[$itemid]->grademax, 0, 1); } + // If global aggregateonlygraded is set, override category value + if ($CFG->grade_aggregateonlygraded != -1) { + $this->aggregateonlygraded = $CFG->grade_aggregateonlygraded; + } + // use min grade if grade missing for these types if (!$this->aggregateonlygraded) { foreach($items as $itemid=>$value) { @@ -619,6 +625,17 @@ class grade_category extends grade_object { * @return array Limited grades. */ function apply_limit_rules(&$grade_values) { + global $CFG; + + // If global keephigh and/or droplow are set, override category variable + if ($CFG->grade_keephigh != -1) { + $this->keephigh = $CFG->grade_keephigh; + } + + if ($CFG->grade_droplow != -1) { + $this->droplow = $CFG->grade_droplow; + } + arsort($grade_values, SORT_NUMERIC); if (!empty($this->droplow)) { for ($i = 0; $i < $this->droplow; $i++) { diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index bb2548dd21..671e06870a 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -1146,6 +1146,16 @@ class grade_item extends grade_object { return array(); } + // If global aggregateoutcomes is set, override category value + if ($CFG->grade_aggregateoutcomes != -1) { + $grade_category->aggregateoutcomes = $CFG->grade_aggregateoutcomes; + } + + // If global aggregatesubcats is set, override category value + if ($CFG->grade_aggregatesubcats != -1) { + $grade_category->aggregatesubcats = $CFG->grade_aggregatesubcats; + } + if (empty($CFG->enableoutcomes) or $grade_category->aggregateoutcomes) { $outcomes_sql = ""; } else { @@ -1153,7 +1163,7 @@ class grade_item extends grade_object { } if ($grade_category->aggregatesubcats) { - // return all children excluding category items + // 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.") @@ -1169,9 +1179,9 @@ class grade_item extends grade_object { WHERE gi.categoryid = {$grade_category->id} AND (gi.gradetype = ".GRADE_TYPE_VALUE." OR gi.gradetype = ".GRADE_TYPE_SCALE.") $outcomes_sql - + UNION - + SELECT gi.id FROM {$CFG->prefix}grade_items gi, {$CFG->prefix}grade_categories gc WHERE (gi.itemtype = 'category' OR gi.itemtype = 'course') AND gi.iteminstance=gc.id diff --git a/version.php b/version.php index 4c1000c741..a772fdffba 100644 --- a/version.php +++ b/version.php @@ -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 = 2007091400; // YYYYMMDD = date + $version = 2007091401; // YYYYMMDD = date // XY = increments within a single day $release = '1.9 Beta +'; // Human-friendly version name