From: skodak Date: Wed, 14 Nov 2007 11:52:21 +0000 (+0000) Subject: MDL-12146 grade category defaults, forced settings and advanced options, merged from... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=190af29fef22b0cbddb67417598f52707afa93e2;p=moodle.git MDL-12146 grade category defaults, forced settings and advanced options, merged from MOODLE_19_STABLE --- diff --git a/admin/settings/grades.php b/admin/settings/grades.php index 8cb2a2795b..7ee35a555a 100644 --- a/admin/settings/grades.php +++ b/admin/settings/grades.php @@ -67,33 +67,36 @@ $temp->add(new admin_setting_configcheckbox('grade_hideforcedsettings', get_stri $strnoforce = get_string('noforce', 'grades'); // Aggregation type -$options = array(-1 =>$strnoforce, - GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', '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')); -$temp->add(new admin_category_regrade_select('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_category_regrade_select('grade_aggregateonlygraded', get_string('aggregateonlygraded', 'grades'), - get_string('aggregateonlygradedhelp', 'grades'), -1, $options)); -$temp->add(new admin_category_regrade_select('grade_aggregateoutcomes', get_string('aggregateoutcomes', 'grades'), - get_string('aggregateoutcomeshelp', 'grades'), -1, $options)); -$temp->add(new admin_category_regrade_select('grade_aggregatesubcats', get_string('aggregatesubcats', 'grades'), - get_string('aggregatesubcatshelp', 'grades'), -1, $options)); - -$options = array(-1 => $strnoforce, 0 => get_string('none')); + GRADE_AGGREGATE_EXTRACREDIT_MEAN=>get_string('aggregateextracreditmean', 'grades'), + GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades')); +$defaults = array('value'=>GRADE_AGGREGATE_MEAN, 'forced'=>false, 'adv'=>false); +$temp->add(new admin_setting_gradecat_combo('grade_aggregation', get_string('aggregation', 'grades'), get_string('aggregationhelp', 'grades'), $defaults, $options)); + +$options = array(0 => get_string('no'), 1 => get_string('yes')); + +$defaults = array('value'=>0, 'forced'=>false, 'adv'=>true); +$temp->add(new admin_setting_gradecat_combo('grade_aggregateonlygraded', get_string('aggregateonlygraded', 'grades'), + get_string('aggregateonlygradedhelp', 'grades'), $defaults, $options)); +$temp->add(new admin_setting_gradecat_combo('grade_aggregateoutcomes', get_string('aggregateoutcomes', 'grades'), + get_string('aggregateoutcomeshelp', 'grades'), $defaults, $options)); +$temp->add(new admin_setting_gradecat_combo('grade_aggregatesubcats', get_string('aggregatesubcats', 'grades'), + get_string('aggregatesubcatshelp', 'grades'), $defaults, $options)); + +$options = array(0 => get_string('none')); for ($i=1; $i<=20; $i++) { $options[$i] = $i; } -$temp->add(new admin_category_regrade_select('grade_keephigh', get_string('keephigh', 'grades'), - get_string('keephighhelp', 'grades'), -1, $options)); -$temp->add(new admin_category_regrade_select('grade_droplow', get_string('droplow', 'grades'), - get_string('droplowhelp', 'grades'), -1, $options)); +$temp->add(new admin_setting_gradecat_combo('grade_keephigh', get_string('keephigh', 'grades'), + get_string('keephighhelp', 'grades'), $defaults, $options)); +$temp->add(new admin_setting_gradecat_combo('grade_droplow', get_string('droplow', 'grades'), + get_string('droplowhelp', 'grades'), $defaults, $options)); $ADMIN->add('grades', $temp); diff --git a/grade/edit/tree/category.php b/grade/edit/tree/category.php index 857da30b71..1ba1165428 100644 --- a/grade/edit/tree/category.php +++ b/grade/edit/tree/category.php @@ -61,6 +61,7 @@ if ($id) { } else { $grade_category = new grade_category(); $grade_category->courseid = $course->id; + $grade_category->apply_default_settings(); $grade_category->apply_forced_settings(); $category = $grade_category->get_record_data(); } diff --git a/grade/edit/tree/category_form.php b/grade/edit/tree/category_form.php index 9a137b70da..3c68c949f9 100644 --- a/grade/edit/tree/category_form.php +++ b/grade/edit/tree/category_form.php @@ -47,6 +47,9 @@ class edit_category_form extends moodleform { $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $options); $mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade')); + if ((int)$CFG->grade_aggregation_flag & 2) { + $mform->setAdvanced('aggregation'); + } //GVA Patch $mform->addElement('checkbox', 'weightcourse', 'Weight grades for course'); //To Do Localize @@ -60,6 +63,9 @@ class edit_category_form extends moodleform { $mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'), false, true, false, get_string('aggregateonlygradedhelp', 'grades'))); $mform->disabledIf('aggregateonlygraded', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); + if ((int)$CFG->grade_aggregateonlygraded_flag & 2) { + $mform->setAdvanced('aggregateonlygraded'); + } if (empty($CFG->enableoutcomes)) { $mform->addElement('hidden', 'aggregateoutcomes'); @@ -69,11 +75,17 @@ class edit_category_form extends moodleform { $mform->setHelpButton('aggregateoutcomes', array(false, get_string('aggregateoutcomes', 'grades'), false, true, false, get_string('aggregateoutcomeshelp', 'grades'))); $mform->disabledIf('aggregateoutcomes', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); + if ((int)$CFG->grade_aggregateoutcomes_flag & 2) { + $mform->setAdvanced('aggregateoutcomes'); + } } $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 ((int)$CFG->grade_aggregatesubcats_flag & 2) { + $mform->setAdvanced('aggregatesubcats'); + } $options = array(0 => get_string('none')); for ($i=1; $i<=20; $i++) { @@ -83,11 +95,17 @@ class edit_category_form extends moodleform { $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'))); + if ((int)$CFG->grade_keephigh_flag & 2) { + $mform->setAdvanced('keephigh'); + } $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 ((int)$CFG->grade_droplow_flag & 2) { + $mform->setAdvanced('droplow'); + } $mform->disabledIf('keephigh', 'droplow', 'noteq', 0); $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); @@ -104,6 +122,7 @@ class edit_category_form extends moodleform { $mform->setHelpButton('pref_aggregationview', array(false, get_string('aggregationview', 'grades'), false, true, false, get_string('configaggregationview', 'grades'))); $mform->setDefault('pref_aggregationview', GRADE_REPORT_PREFERENCE_DEFAULT); + $mform->setAdvanced('pref_aggregationview'); // hidden params $mform->addElement('hidden', 'id', 0); @@ -130,7 +149,7 @@ class edit_category_form extends moodleform { $somecat = new grade_category(); foreach ($somecat->forceable as $property) { - if ($CFG->{"grade_$property"} != -1) { + if ((int)$CFG->{"grade_{$property}_flag"} & 1) { if ($mform->elementExists($property)) { if (empty($CFG->grade_hideforcedsettings)) { $mform->hardFreeze($property); diff --git a/lib/adminlib.php b/lib/adminlib.php index 383a073945..69490e4bdf 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -2779,30 +2779,83 @@ class admin_setting_special_debugdisplay extends admin_setting_configcheckbox { } -/** - * Select config class with regrading when setting changes. - */ -class admin_category_regrade_select extends admin_setting_configselect { - function admin_category_regrade_select($name, $visiblename, $description, $defaultsetting, $choices) { - parent::admin_setting_configselect($name, $visiblename, $description, $defaultsetting, $choices); +class admin_setting_gradecat_combo extends admin_setting { + + var $choices; + + function admin_setting_gradecat_combo($name, $visiblename, $description, $defaultsetting, $choices) { + $this->choices = $choices; + parent::admin_setting($name, $visiblename, $description, $defaultsetting); + } + + function get_setting() { + global $CFG; + + if (!isset($CFG->{$this->name}) or !isset($CFG->{$this->name.'_flag'})) { + return NULL; + } + + $flag = (int)$CFG->{$this->name.'_flag'}; + $forced = (boolean)(1 & $flag); // first bit + $adv = (boolean)(2 & $flag); // second bit + + return array('value' => $CFG->{$this->name}, 'forced' => $forced, 'adv' => $adv); } function write_setting($data) { - global $CFG; + global $CFG; - if (!in_array($data, array_keys($this->choices))) { - return 'Error setting ' . $this->visiblename . '
'; - } + $value = $data['value']; + $forced = empty($data['forced']) ? 0 : 1; + $adv = empty($data['adv']) ? 0 : 2; + $flag = ($forced | $adv); //bitwise or + + if (!in_array($value, array_keys($this->choices))) { + return 'Error setting ' . $this->visiblename . '
'; + } - $old = get_config(NULL, $this->name); - set_config($this->name, $data); - if ($old !== $data) { - require_once($CFG->libdir.'/gradelib.php'); - grade_category::updated_forced_settings(); - } + $oldvalue = get_config(NULL, $this->name); + $oldflag = (int)get_config(NULL, $this->name.'_flag'); + $oldforced = (1 & $oldflag); // first bit - return ''; + $result = (boolean)set_config($this->name, $value); + $result = $result && (boolean)set_config($this->name.'_flag', $flag); + + if ($result) { + // force regrade if needed + if ($oldforced != $forced or ($forced and $value != $oldvalue)) { + require_once($CFG->libdir.'/gradelib.php'); + grade_category::updated_forced_settings(); + } + + return ''; + } else { + return get_string('errorsetting', 'admin') . $this->visiblename . '
'; + } + } + + function output_html() { + + if ($this->get_setting() === NULL) { + $current = $this->defaultsetting; + } else { + $current = $this->get_setting(); + } + $value = $current['value']; + $forced = !empty($current['forced']); + $adv = !empty($current['adv']); + + $return = ''; // TODO: localise + $return .= ''; + $return .= ''; + + return format_admin_setting($this->name, $this->visiblename, $return, $this->description); } } diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 1800e6a5a4..e3ff22d124 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -99,7 +99,7 @@ class grade_category extends grade_object { * Aggregate only graded items * @var int $aggregateonlygraded */ - var $aggregateonlygraded = 1; + var $aggregateonlygraded = 0; /** * Aggregate outcomes together with normal items @@ -326,6 +326,7 @@ class grade_category extends grade_object { $this->parent = null; $this->aggregation = GRADE_AGGREGATE_MEAN; + $this->apply_default_settings(); $this->apply_forced_settings(); $this->timecreated = $this->timemodified = time(); @@ -1190,6 +1191,23 @@ class grade_category extends grade_object { } } + /** + * Applies default settings on this category + * @return bool true if anything changed + */ + function apply_default_settings() { + global $CFG; + + foreach ($this->forceable as $property) { + if (isset($CFG->{"grade_$property"})) { + if ($CFG->{"grade_$property"} == -1) { + continue; //temporary bc before version bump + } + $this->$property = $CFG->{"grade_$property"}; + } + } + } + /** * Applies forced settings on this category * @return bool true if anything changed @@ -1199,7 +1217,10 @@ class grade_category extends grade_object { $updated = false; foreach ($this->forceable as $property) { - if (isset($CFG->{"grade_$property"}) and $CFG->{"grade_$property"} != -1) { + if (isset($CFG->{"grade_$property"}) and isset($CFG->{"grade_{$property}_flag"}) and ((int)$CFG->{"grade_{$property}_flag"} & 1)) { + if ($CFG->{"grade_$property"} == -1) { + continue; //temporary bc before version bump + } $this->$property = $CFG->{"grade_$property"}; $updated = true; }