MDL-12140, making most common non-weighted settings easy for teachers
This commit is contained in:
@@ -54,7 +54,10 @@ if ($id) {
|
||||
$category = $grade_category->get_record_data();
|
||||
// Get Category preferences
|
||||
$category->pref_aggregationview = grade_report::get_pref('aggregationview', $id);
|
||||
|
||||
//GVA Patch
|
||||
$grade_item = $grade_category->load_grade_item();
|
||||
$category->aggregationcoef = $grade_item->aggregationcoef;
|
||||
//End Patch
|
||||
} else {
|
||||
$grade_category = new grade_category();
|
||||
$grade_category->courseid = $course->id;
|
||||
@@ -89,7 +92,25 @@ if ($mform->is_cancelled()) {
|
||||
error("Could not set preference aggregationview to $value for this grade category");
|
||||
}
|
||||
}
|
||||
//GVA Patch
|
||||
|
||||
if (isset($data->weightcourse)) {
|
||||
global $COURSE;
|
||||
$course_category = grade_category::fetch_course_category($COURSE->id);
|
||||
$course_category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN;
|
||||
$course_category->update();
|
||||
}
|
||||
|
||||
if (!isset($grade_item)) {
|
||||
$grade_item = $grade_category->load_grade_item();
|
||||
}
|
||||
if (isset($data->aggregationcoef)){
|
||||
$data_item->aggregationcoef = $data->aggregationcoef;
|
||||
grade_item::set_properties($grade_item, $data_item);
|
||||
$grade_item->update();
|
||||
}
|
||||
|
||||
//End Patch
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,14 @@ 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'));
|
||||
|
||||
//GVA Patch
|
||||
$mform->addElement('checkbox', 'weightcourse', 'Weight grades for course'); //To Do Localize
|
||||
$mform->addElement('text', 'aggregationcoef', get_string('aggregationcoefweight', 'grades'));
|
||||
$mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoefweight', 'grades'),
|
||||
false, true, false, get_string('aggregationcoefweighthelp', 'grades')));
|
||||
$mform->disabledIf('aggregationcoef', 'weightcourse', 'notchecked');
|
||||
//End Patch
|
||||
|
||||
$mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
|
||||
$mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'),
|
||||
false, true, false, get_string('aggregateonlygradedhelp', 'grades')));
|
||||
@@ -116,7 +124,7 @@ class edit_category_form extends moodleform {
|
||||
|
||||
/// tweak the form - depending on existing data
|
||||
function definition_after_data() {
|
||||
global $CFG;
|
||||
global $CFG, $COURSE;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
@@ -144,11 +152,52 @@ class edit_category_form extends moodleform {
|
||||
$mform->removeElement('droplow');
|
||||
}
|
||||
}
|
||||
|
||||
//GVA Patch
|
||||
if (!$id = $mform->getElementValue('id')) {
|
||||
$mform->setDefault('aggregateonlygraded',1);
|
||||
$parent_category = grade_category::fetch_course_category($COURSE->id);
|
||||
if ($parent_category->is_aggregationcoef_used()) {
|
||||
if ($mform->elementExists('weightcourse')) {
|
||||
$mform->removeElement('weightcourse');
|
||||
}
|
||||
}
|
||||
}
|
||||
//End Patch
|
||||
|
||||
if ($id = $mform->getElementValue('id')) {
|
||||
$grade_category = grade_category::fetch(array('id'=>$id));
|
||||
$grade_item = $grade_category->load_grade_item();
|
||||
|
||||
//GVA Patch
|
||||
$category = $grade_item->get_item_category();
|
||||
if(!$category->aggregateonlygraded) {
|
||||
$mform->setAdvanced('aggregateonlygraded', false);
|
||||
}
|
||||
if ($grade_item->is_course_item()) { //An actual course, not a category, etc.
|
||||
|
||||
if ($mform->elementExists('aggregationcoef')) {
|
||||
$mform->removeElement('aggregationcoef');
|
||||
}
|
||||
if ($mform->elementExists('weightcourse')) {
|
||||
$mform->removeElement('weightcourse');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$grade_item->is_category_item()) {
|
||||
if ($mform->elementExists('weightcourse')) {
|
||||
$mform->removeElement('weightcourse');
|
||||
}
|
||||
} else {
|
||||
$category = $grade_item->get_item_category();
|
||||
$parent_category = $category->get_parent_category();
|
||||
if ($parent_category->is_aggregationcoef_used()) {
|
||||
if ($mform->elementExists('weightcourse')) {
|
||||
$mform->removeElement('weightcourse');
|
||||
}
|
||||
}
|
||||
}
|
||||
//End Patch
|
||||
if ($grade_item->is_calculated()) {
|
||||
// following elements are ignored when calculation formula used
|
||||
if ($mform->elementExists('aggregation')) {
|
||||
|
||||
@@ -454,6 +454,7 @@ $string['useweighted'] = 'Use weighted';
|
||||
$string['viewbygroup'] = 'Group';
|
||||
$string['viewgrades'] = 'View grades';
|
||||
$string['weight'] = 'weight';
|
||||
$string['weightcourse'] = 'Use weighted grades for course';
|
||||
$string['weightedascending'] = 'Sort by weighted percent ascending';
|
||||
$string['weighteddescending'] = 'Sort by weighted percent descending';
|
||||
$string['weightedpct'] = 'weighted %%';
|
||||
|
||||
Reference in New Issue
Block a user