diff --git a/admin/settings/grades.php b/admin/settings/grades.php
index 910104cdafb..a141bae9992 100644
--- a/admin/settings/grades.php
+++ b/admin/settings/grades.php
@@ -26,6 +26,9 @@ if (has_capability('moodle/grade:manage', $systemcontext)
// new CFG variable for gradebook (what roles to display)
$temp->add(new admin_setting_special_gradebookroles());
+ // enable outcomes checkbox
+ $temp->add(new admin_setting_configcheckbox('enableoutcomes', get_string('enableoutcomes', 'grades'), get_string('configenableoutcomes', 'grades'), 0, PARAM_INT));
+
$temp->add(new admin_setting_grade_profilereport());
$temp->add(new admin_setting_configselect('grade_aggregationposition', get_string('aggregationposition', 'grades'),
@@ -43,7 +46,6 @@ if (has_capability('moodle/grade:manage', $systemcontext)
$temp->add(new admin_setting_configselect('grade_export_displaytype', get_string('gradeexportdisplaytype', 'grades'),
get_string('configgradeexportdisplaytype', 'grades'), GRADE_DISPLAY_TYPE_REAL, $display_types));
-
$temp->add(new admin_setting_configselect('grade_export_decimalpoints', get_string('gradeexportdecimalpoints', 'grades'),
get_string('configexportdecimalpoints', 'grades'), 2,
array( '0' => '0',
@@ -58,6 +60,8 @@ if (has_capability('moodle/grade:manage', $systemcontext)
GRADE_NAVMETHOD_COMBO => get_string('combo', 'grades'))));
$temp->add(new admin_setting_special_gradeexport());
+
+ $temp->add(new admin_setting_special_gradelimiting());
}
$ADMIN->add('grades', $temp);
@@ -78,9 +82,17 @@ if (has_capability('moodle/grade:manage', $systemcontext)
GRADE_AGGREGATE_MAX =>get_string('aggregatemax', 'grades'),
GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'),
GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades'));
+
+ $defaultvisible = array(GRADE_AGGREGATE_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2,
+ GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_MEDIAN, GRADE_AGGREGATE_MIN,
+ GRADE_AGGREGATE_MAX, GRADE_AGGREGATE_MODE, GRADE_AGGREGATE_SUM);
+
$defaults = array('value'=>GRADE_AGGREGATE_WEIGHTED_MEAN2, 'forced'=>false, 'adv'=>false);
$temp->add(new admin_setting_gradecat_combo('grade_aggregation', get_string('aggregation', 'grades'), get_string('aggregationhelp', 'grades'), $defaults, $options));
+ $temp->add(new admin_setting_configmultiselect('grade_aggregations_visible', get_string('aggregationsvisible', 'grades'),
+ get_string('aggregationsvisiblehelp', 'grades'), $defaultvisible, $options));
+
$options = array(0 => get_string('no'), 1 => get_string('yes'));
$defaults = array('value'=>1, 'forced'=>false, 'adv'=>true);
@@ -151,7 +163,7 @@ if (has_capability('moodle/grade:manage', $systemcontext)
$scales = new admin_externalpage('scales', get_string('scales'), $CFG->wwwroot.'/grade/edit/scale/index.php', 'moodle/grade:manage');
$ADMIN->add('grades', $scales);
if ($CFG->enableoutcomes) {
- $outcomes = new admin_externalpage('outcomes', get_string('outcomes', 'grades'), $CFG->wwwroot.'/grade/edit/outcome/index.php', 'moodle/grade:manage', empty($CFG->enableoutcomes));
+ $outcomes = new admin_externalpage('outcomes', get_string('outcomes', 'grades'), $CFG->wwwroot.'/grade/edit/outcome/index.php', 'moodle/grade:manage');
$ADMIN->add('grades', $outcomes);
}
$letters = new admin_externalpage('letters', get_string('letters', 'grades'), $CFG->wwwroot.'/grade/edit/letter/edit.php', 'moodle/grade:manageletters');
diff --git a/grade/edit/tree/calculation_form.php b/grade/edit/tree/calculation_form.php
index 5028bc756e1..1c79bf60409 100644
--- a/grade/edit/tree/calculation_form.php
+++ b/grade/edit/tree/calculation_form.php
@@ -90,7 +90,7 @@ class edit_calculation_form extends moodleform {
// check the calculation formula
if ($data['calculation'] != '') {
$grade_item = grade_item::fetch(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
- $calculation = calc_formula::unlocalize($data['calculation']);
+ $calculation = calc_formula::unlocalize(stripslashes($data['calculation']));
$result = $grade_item->validate_formula($calculation);
if ($result !== true) {
$errors['calculation'] = $result;
diff --git a/grade/edit/tree/category_form.php b/grade/edit/tree/category_form.php
index 8b3a1d1768d..087cf589df9 100644
--- a/grade/edit/tree/category_form.php
+++ b/grade/edit/tree/category_form.php
@@ -27,6 +27,7 @@ require_once $CFG->libdir.'/formslib.php';
class edit_category_form extends moodleform {
private $aggregation_options = array();
+ private $allaggoptions;
function definition() {
global $CFG, $COURSE, $DB;
@@ -42,6 +43,8 @@ class edit_category_form extends moodleform {
GRADE_AGGREGATE_MODE =>get_string('aggregatemode', 'grades'),
GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades'));
+ $this->allaggoptions = array_keys($this->aggregation_options);
+
// visible elements
$mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades'));
$mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
@@ -49,6 +52,7 @@ class edit_category_form extends moodleform {
$mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options);
$mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade'));
+
if ((int)$CFG->grade_aggregation_flag & 2) {
$mform->setAdvanced('aggregation');
}
@@ -56,6 +60,7 @@ class edit_category_form extends moodleform {
$mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
$mform->setHelpButton('aggregateonlygraded', array('aggregateonlygraded', get_string('aggregateonlygraded', 'grades'),'grade'), true);
$mform->disabledIf('aggregateonlygraded', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
+
if ((int)$CFG->grade_aggregateonlygraded_flag & 2) {
$mform->setAdvanced('aggregateonlygraded');
}
@@ -73,11 +78,13 @@ class edit_category_form extends moodleform {
$mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
$mform->setHelpButton('aggregatesubcats', array('aggregatesubcats', get_string('aggregatesubcats', 'grades'), 'grade'), true);
+
if ((int)$CFG->grade_aggregatesubcats_flag & 2) {
$mform->setAdvanced('aggregatesubcats');
}
$options = array(0 => get_string('none'));
+
for ($i=1; $i<=20; $i++) {
$options[$i] = $i;
}
@@ -187,6 +194,7 @@ class edit_category_form extends moodleform {
$mform->setHelpButton('grade_item_decimals', array('decimalpoints', get_string('decimalpoints', 'grades'), 'grade'), true);
$mform->setDefault('grade_item_decimals', -1);
$mform->disabledIf('grade_item_decimals', 'grade_item_display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
+
if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
$mform->disabledIf('grade_item_decimals', 'grade_item_display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
}
@@ -200,7 +208,7 @@ class edit_category_form extends moodleform {
$mform->disabledIf('grade_item_hidden', 'grade_item_hiddenuntil[off]', 'notchecked');
/// locking
- $mform->addElement('advcheckbox', 'grade_item_locked', get_string('locked', 'grades'));
+ $mform->addElement('checkbox', 'grade_item_locked', get_string('locked', 'grades'));
$mform->setHelpButton('grade_item_locked', array('locked', get_string('locked', 'grades'), 'grade'));
$mform->addElement('date_time_selector', 'grade_item_locktime', get_string('locktime', 'grades'), array('optional'=>true));
@@ -212,7 +220,6 @@ class edit_category_form extends moodleform {
$options = array();
$default = '';
- $coefstring = '';
$categories = grade_category::fetch_all(array('courseid'=>$COURSE->id));
foreach ($categories as $cat) {
@@ -221,30 +228,13 @@ class edit_category_form extends moodleform {
if ($cat->is_course_category()) {
$default = $cat->id;
}
- if ($cat->is_aggregationcoef_used()) {
- if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
- $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';
-
- } else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
- $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
-
- } else {
- $coefstring = 'aggregationcoef';
- }
- } else {
- $mform->disabledIf('grade_item_aggregationcoef', 'parentcategory', 'eq', $cat->id);
- }
}
+
if (count($categories) > 1) {
$mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options);
$mform->addElement('static', 'currentparentaggregation', get_string('currentparentaggregation', 'grades'));
}
- if ($coefstring !== '') {
- $mform->addElement('text', 'grade_item_aggregationcoef', get_string($coefstring, 'grades'));
- $mform->setHelpButton('grade_item_aggregationcoef', array('aggregationcoefweight', get_string('aggregationcoef', 'grades'), 'grade'), true);
- }
-
/// user preferences
$mform->addElement('header', 'headerpreferences', get_string('myreportpreferences', 'grades'));
$options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'),
@@ -282,6 +272,7 @@ class edit_category_form extends moodleform {
$mform =& $this->_form;
$somecat = new grade_category();
+
foreach ($somecat->forceable as $property) {
if ((int)$CFG->{"grade_{$property}_flag"} & 1) {
if ($mform->elementExists($property)) {
@@ -306,10 +297,14 @@ class edit_category_form extends moodleform {
}
}
+ $current_aggregation = null;
+
if ($id = $mform->getElementValue('id')) {
$grade_category = grade_category::fetch(array('id'=>$id));
$grade_item = $grade_category->load_grade_item();
+ $current_aggregation = $grade_category->aggregation;
+
// remove agg coef if not used
if ($grade_category->is_course_category()) {
if ($mform->elementExists('parentcategory')) {
@@ -365,8 +360,23 @@ class edit_category_form extends moodleform {
if ($grade_category->is_course_category() && $mform->getElementValue('fullname') == '?') {
$mform->setDefault('fullname', '');
}
+ // remove unwanted aggregation options
+ if ($mform->elementExists('aggregation')) {
+ $agg_el =& $mform->getElement('aggregation');
+ $visible = explode(',', $CFG->grade_aggregations_visible);
+ if (!is_null($current_aggregation)) {
+ // current type is always visible
+ $visible[] = $current_aggregation;
+ }
+ foreach ($this->allaggoptions as $type) {
+ if (!in_array($type, $visible) && $grade_category->aggregation != $type) {
+ $agg_el->removeOption($type);
+ }
+ }
+ }
}
+
// no parent header for course category
if (!$mform->elementExists('aggregationcoef') and !$mform->elementExists('parentcategory')) {
$mform->removeElement('headerparent');
@@ -377,6 +387,8 @@ class edit_category_form extends moodleform {
$grade_category = grade_category::fetch(array('id'=>$id));
$grade_item = $grade_category->load_grade_item();
+ $mform->setDefault('grade_item_hidden', (int) $grade_item->hidden);
+
if (!$grade_item->is_raw_used()) {
$mform->removeElement('grade_item_plusfactor');
$mform->removeElement('grade_item_multfactor');
@@ -428,23 +440,19 @@ class edit_category_form extends moodleform {
$mform->removeElement('grade_item_aggregationcoef');
}
} else {
- //fix label if needed
- $agg_el =& $mform->getElement('grade_item_aggregationcoef');
- $aggcoef = '';
- if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
- $aggcoef = 'aggregationcoefweight';
- } else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
- $aggcoef = 'aggregationcoefextra';
+ $coefstring = $grade_item->get_coefstring();
- } else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
- $aggcoef = 'aggregationcoefextrasum';
- }
-
- if ($aggcoef !== '') {
- $agg_el->setLabel(get_string($aggcoef, 'grades'));
- $mform->setHelpButton('grade_item_aggregationcoef', array($aggcoef, get_string($aggcoef, 'grades'), 'grade'), true);
+ if ($coefstring == 'aggregationcoefextrasum') {
+ // advcheckbox is not compatible with disabledIf!
+ $element =& $mform->createElement('checkbox', 'grade_item_aggregationcoef', get_string($coefstring, 'grades'));
+ } else {
+ $element =& $mform->createElement('text', 'grade_item_aggregationcoef', get_string($coefstring, 'grades'));
}
+ $mform->insertElementBefore($element, 'parentcategory');
+ $mform->setDefault('grade_item_aggregationcoef', (int) $grade_item->aggregationcoef); // must be cast to int, otherwise "0" counts as true :S
+ $mform->setHelpButton('grade_item_aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true);
+ $mform->disabledIf('grade_item_aggregationcoef', 'grade_item_parentcategory', 'eq', $parent_category->id);
}
}
diff --git a/grade/edit/tree/grade.php b/grade/edit/tree/grade.php
index b6894f7cd9d..35937a22759 100644
--- a/grade/edit/tree/grade.php
+++ b/grade/edit/tree/grade.php
@@ -153,7 +153,7 @@ if ($mform->is_cancelled()) {
redirect($returnurl);
// form processing
-} else if ($data = $mform->get_data()) {
+} else if ($data = $mform->get_data(false)) {
$old_grade_grade = new grade_grade(array('userid'=>$data->userid, 'itemid'=>$grade_item->id), true); //might not exist yet
// fix no grade for scales
diff --git a/grade/edit/tree/index.php b/grade/edit/tree/index.php
index f1c14ceb324..11a38d22fd0 100644
--- a/grade/edit/tree/index.php
+++ b/grade/edit/tree/index.php
@@ -39,7 +39,6 @@ $aggregationtype = optional_param('aggregationtype', null, PARAM_INT);
$showadvanced = optional_param('showadvanced', -1, PARAM_BOOL); // sticky editting mode
/// Make sure they can even access this course
-
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
@@ -88,13 +87,14 @@ if (has_capability('moodle/grade:manage', $context)) {
}
// Change category aggregation if requested
-if (!is_null($category) && !is_null($aggregationtype)) {
+if (!is_null($category) && !is_null($aggregationtype) && confirm_sesskey()) {
if (!$grade_category = grade_category::fetch(array('id'=>$category, 'courseid'=>$courseid))) {
error('Incorrect category id!');
}
$data->aggregation = $aggregationtype;
grade_category::set_properties($grade_category, $data);
$grade_category->update();
+ grade_regrade_final_grades($courseid);
}
//first make sure we have proper final grades - we need it for locking changes
@@ -129,7 +129,7 @@ $grade_edit_tree = new grade_edit_tree($gtree, $moving, $gpr);
switch ($action) {
case 'delete':
- if ($eid) {
+ if ($eid && confirm_sesskey()) {
if (!$grade_edit_tree->element_deletable($element)) {
// no deleting of external activities - they would be recreated anyway!
// exception is activity without grading or misconfigured activities
@@ -189,6 +189,7 @@ switch ($action) {
case 'moveselect':
if ($eid and confirm_sesskey()) {
$grade_edit_tree->moving = $eid;
+ $moving=true;
}
break;
@@ -219,7 +220,7 @@ $form_key = optional_param('sesskey', null, PARAM_ALPHANUM);
if ($form_key && $data = data_submitted()) {
// Perform bulk actions first
- if (!empty($data->bulkmove)) {
+ if (!empty($data->bulkmove) && confirm_sesskey()) {
$elements = array();
foreach ($data as $key => $value) {
@@ -234,7 +235,7 @@ if ($form_key && $data = data_submitted()) {
// Category and item field updates
foreach ($data as $key => $value) {
// Grade category text inputs
- if (preg_match('/(aggregation|droplow|keephigh)_([0-9]*)/', $key, $matches)) {
+ if (preg_match('/(aggregation|droplow|keephigh)_([0-9]*)/', $key, $matches) && confirm_sesskey()) {
$value = required_param($matches[0], PARAM_INT);
$param = $matches[1];
$a->id = $matches[2];
@@ -243,9 +244,10 @@ if ($form_key && $data = data_submitted()) {
$grade_category->$param = $value;
$grade_category->update();
+ grade_regrade_final_grades($courseid);
// Grade item text inputs
- } elseif (preg_match('/(grademax|aggregationcoef|multfactor|plusfactor)_([0-9]*)/', $key, $matches)) {
+ } elseif (preg_match('/(grademax|aggregationcoef|multfactor|plusfactor)_([0-9]*)/', $key, $matches) && confirm_sesskey()) {
$defaults = array('grademax' => 100, 'aggregationcoef' => 1, 'multfactor' => 1, 'plusfactor' => 0);
if (is_string($_POST[$matches[0]]) && strlen($_POST[$matches[0]]) < 1) {
@@ -259,14 +261,14 @@ if ($form_key && $data = data_submitted()) {
$grade_item->$param = $value;
$grade_item->update();
+ grade_regrade_final_grades($courseid);
// Grade item checkbox inputs
- } elseif (preg_match('/extracredit_original_([0-9]*)/', $key, $matches)) { // Sum extra credit checkbox
+ } elseif (preg_match('/extracredit_original_([0-9]*)/', $key, $matches) && confirm_sesskey()) { // Sum extra credit checkbox
$extracredit = optional_param("extracredit_{$matches[1]}", null, PARAM_BOOL);
$original_value = required_param($matches[0], PARAM_BOOL);
$a->id = $matches[1];
$newvalue = null;
-
if ($original_value == 1 && is_null($extracredit)) {
$newvalue = 0;
} elseif ($original_value == 0 && $extracredit == 1) {
@@ -279,9 +281,10 @@ if ($form_key && $data = data_submitted()) {
$grade_item->aggregationcoef = $newvalue;
$grade_item->update();
+ grade_regrade_final_grades($courseid);
// Grade category checkbox inputs
- } elseif (preg_match('/aggregate(onlygraded|subcats|outcomes)_original_([0-9]*)/', $key, $matches)) {
+ } elseif (preg_match('/aggregate(onlygraded|subcats|outcomes)_original_([0-9]*)/', $key, $matches) && confirm_sesskey()) {
$setting = optional_param('aggregate'.$matches[1].'_'.$matches[2], null, PARAM_BOOL);
$original_value = required_param($matches[0], PARAM_BOOL);
$a->id = $matches[2];
@@ -299,6 +302,7 @@ if ($form_key && $data = data_submitted()) {
$grade_category->{'aggregate'.$matches[1]} = $newvalue;
$grade_category->update();
+ grade_regrade_final_grades($courseid);
}
}
}
@@ -354,7 +358,8 @@ if ($moving) {
print_single_button('outcomeitem.php', array('courseid'=>$course->id), get_string('addoutcomeitem', 'grades'), 'get');
}
- echo "
";
+ //print_single_button('index.php', array('id'=>$course->id, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get');
+ echo "
";
print_single_button('index.php', array('id'=>$course->id, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get');
helpbutton('synclegacygrades', get_string('synclegacygrades', 'grades'), 'grade');
}
diff --git a/grade/edit/tree/item_form.php b/grade/edit/tree/item_form.php
index 3d5f6ca83cf..a2c06236f9c 100644
--- a/grade/edit/tree/item_form.php
+++ b/grade/edit/tree/item_form.php
@@ -153,42 +153,16 @@ class edit_item_form extends moodleform {
foreach ($categories as $cat) {
$cat->apply_forced_settings();
$options[$cat->id] = $cat->get_name();
+
if ($cat->is_course_category()) {
$default = $cat->id;
}
-
- if ($cat->is_aggregationcoef_used()) {
- if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
- $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';
-
- } else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
- $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
-
- } else if ($cat->aggregation == GRADE_AGGREGATE_SUM) {
- $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef';
-
- } else {
- $coefstring = 'aggregationcoef';
- }
- } else {
- $mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $cat->id);
- }
}
if (count($categories) > 1) {
$mform->addElement('select', 'parentcategory', get_string('gradecategory', 'grades'), $options);
}
- if ($coefstring !== '') {
- if ($coefstring == 'aggregationcoefextrasum') {
- // advcheckbox is not compatible with disabledIf!
- $mform->addElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
- } else {
- $mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
- }
- $mform->setHelpButton('aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true);
- }
-
/// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
@@ -278,23 +252,26 @@ class edit_item_form extends moodleform {
$mform->removeElement('aggregationcoef');
}
} else {
- //fix label if needed
- $agg_el =& $mform->getElement('aggregationcoef');
- $aggcoef = '';
- if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
- $aggcoef = 'aggregationcoefweight';
-
- } else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
- $aggcoef = 'aggregationcoefextra';
-
- } else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
- $aggcoef = 'aggregationcoefextrasum';
+ if ($grade_item->is_category_item()) {
+ $parent_category = $parent_category->get_parent_category();
+ $coefstring = $parent_category->get_grade_item()->get_coefstring();
+ } else {
+ $parent_category->apply_forced_settings();
+ $coefstring = $grade_item->get_coefstring();
}
- if ($aggcoef !== '') {
- $agg_el->setLabel(get_string($aggcoef, 'grades'));
- $mform->setHelpButton('aggregationcoef', array($aggcoef, get_string($aggcoef, 'grades'), 'grade'), true);
+ if ($coefstring !== '') {
+ if ($coefstring == 'aggregationcoefextrasum') {
+ // advcheckbox is not compatible with disabledIf!
+ $element =& $mform->createElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
+ } else {
+ $element =& $mform->createElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
+ }
+ $mform->insertElementBefore($element, 'parentcategory');
+ $mform->setHelpButton('aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true);
}
+
+ $mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $parent_category->id);
}
}
diff --git a/grade/edit/tree/lib.php b/grade/edit/tree/lib.php
index a4929faf509..d800ee6d544 100755
--- a/grade/edit/tree/lib.php
+++ b/grade/edit/tree/lib.php
@@ -43,6 +43,10 @@ class grade_edit_tree {
public $deepest_level;
+ public $uses_extra_credit = false;
+
+ public $uses_weight = false;
+
/**
* Constructor
*/
@@ -53,19 +57,25 @@ class grade_edit_tree {
$this->deepest_level = $this->get_deepest_level($this->gtree->top_element);
$this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level)),
- grade_edit_tree_column::factory('aggregation', array('flag' => true)),
- grade_edit_tree_column::factory('weightorextracredit', array('adv' => 'aggregationcoef')),
- grade_edit_tree_column::factory('range'), // This is not a setting... How do we deal with it?
- grade_edit_tree_column::factory('aggregateonlygraded', array('flag' => true)),
- grade_edit_tree_column::factory('aggregatesubcats', array('flag' => true)),
- grade_edit_tree_column::factory('aggregateoutcomes', array('flag' => true)),
- grade_edit_tree_column::factory('droplow', array('flag' => true)),
- grade_edit_tree_column::factory('keephigh', array('flag' => true)),
- grade_edit_tree_column::factory('multfactor', array('adv' => true)),
- grade_edit_tree_column::factory('plusfactor', array('adv' => true)),
- grade_edit_tree_column::factory('actions'),
- grade_edit_tree_column::factory('select')
- );
+ grade_edit_tree_column::factory('aggregation', array('flag' => true)));
+
+ if ($this->uses_weight) {
+ $this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'aggregationcoef'));
+ }
+ if ($this->uses_extra_credit) {
+ $this->columns[] = grade_edit_tree_column::factory('extracredit', array('adv' => 'aggregationcoef'));
+ }
+
+ $this->columns[] = grade_edit_tree_column::factory('range'); // This is not a setting... How do we deal with it?
+ $this->columns[] = grade_edit_tree_column::factory('aggregateonlygraded', array('flag' => true));
+ $this->columns[] = grade_edit_tree_column::factory('aggregatesubcats', array('flag' => true));
+ $this->columns[] = grade_edit_tree_column::factory('aggregateoutcomes', array('flag' => true));
+ $this->columns[] = grade_edit_tree_column::factory('droplow', array('flag' => true));
+ $this->columns[] = grade_edit_tree_column::factory('keephigh', array('flag' => true));
+ $this->columns[] = grade_edit_tree_column::factory('multfactor', array('adv' => true));
+ $this->columns[] = grade_edit_tree_column::factory('plusfactor', array('adv' => true));
+ $this->columns[] = grade_edit_tree_column::factory('actions');
+ $this->columns[] = grade_edit_tree_column::factory('select');
}
/**
@@ -300,9 +310,10 @@ class grade_edit_tree {
/**
* Given a grade_item object, returns a labelled input if an aggregation coefficient (weight or extra credit) applies to it.
* @param grade_item $item
+ * @param string type "extra" or "weight": the type of the column hosting the weight input
* @return string HTML
*/
- function get_weight_input($item) {
+ function get_weight_input($item, $type) {
if (!is_object($item) || get_class($item) !== 'grade_item') {
throw new Exception('grade_edit_tree::get_weight_input($item) was given a variable that is not of the required type (grade_item object)');
return false;
@@ -313,28 +324,14 @@ class grade_edit_tree {
}
$parent_category = $item->get_parent_category();
-
- if ($item->is_category_item()) {
- $parent_category = $parent_category->get_parent_category();
- }
-
$parent_category->apply_forced_settings();
+ $aggcoef = $item->get_coefstring();
- if ($parent_category->is_aggregationcoef_used()) {
- $aggcoef = '';
-
- if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
- $aggcoef = 'aggregationcoefweight';
- } elseif ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
- $aggcoef = 'aggregationcoefextra';
- } elseif ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
- $aggcoef = 'aggregationcoefextrasum';
- }
-
- if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoefextra') {
+ if ((($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef') && $type == 'weight') ||
+ ($aggcoef == 'aggregationcoefextra' && $type == 'extra')) {
return '';
- } elseif ($aggcoef == 'aggregationcoefextrasum' ) {
+ } elseif ($aggcoef == 'aggregationcoefextrasum' && $type == 'extra') {
$checked = ($item->aggregationcoef > 0) ? 'checked="checked"' : '';
$extracredit = ($item->aggregationcoef > 0) ? 1 : 0;
@@ -344,7 +341,6 @@ class grade_edit_tree {
return '';
}
}
- }
/**
* Given an element of the grade tree, returns whether it is deletable or not (only manual grade items are deletable)
@@ -424,8 +420,14 @@ class grade_edit_tree {
$object = $element['object'];
$level++;
-
+ $coefstring = $element['object']->get_coefstring();
if ($element['type'] == 'category') {
+ if ($coefstring == 'aggregationcoefweight') {
+ $this->uses_weight = true;
+ } elseif ($coefstring == 'aggregationcoefextra' || $coefstring == 'aggregationcoefextrasum') {
+ $this->uses_extra_credit = true;
+ }
+
foreach($element['children'] as $child_el) {
if ($level > $deepest_level) {
$deepest_level = $level;
@@ -542,6 +544,7 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category
}
public function get_category_cell($category, $levelclass, $params) {
+ global $CFG;
if (empty($params['id'])) {
throw new Exception('Array key (id) missing from 3rd param of grade_edit_tree_column_aggregation::get_category_cell($category, $levelclass, $params)');
}
@@ -556,7 +559,14 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category
GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'),
GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades'));
- $script = "window.location='index.php?id={$params['id']}&category={$category->id}&aggregationtype='+this.value";
+ $visible = explode(',', $CFG->grade_aggregations_visible);
+ foreach ($options as $constant => $string) {
+ if (!in_array($constant, $visible) && $constant != $category->aggregation) {
+ unset($options[$constant]);
+ }
+ }
+
+ $script = "window.location='index.php?id={$params['id']}&category={$category->id}&aggregationtype='+this.value+'&sesskey=" . sesskey()."';";
$aggregation = choose_from_menu($options, 'aggregation_'.$category->id, $category->aggregation, get_string('choose'), $script, 0, true);
if ($this->forced) {
@@ -572,16 +582,16 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category
}
}
-class grade_edit_tree_column_weightorextracredit extends grade_edit_tree_column {
+class grade_edit_tree_column_extracredit extends grade_edit_tree_column {
public function get_header_cell() {
- return '
';
+ return '
';
} else {
return '';
diff --git a/grade/report/grader/ajaxlib.php b/grade/report/grader/ajaxlib.php
index c0e30e902b8..270043f5d17 100644
--- a/grade/report/grader/ajaxlib.php
+++ b/grade/report/grader/ajaxlib.php
@@ -184,15 +184,16 @@ class grade_report_grader_ajax extends grade_report_grader {
}
$columncount = 0;
- // Student name and link
- $user_pic = null;
- if ($showuserimage) {
- $user_pic = '