MDL-46827 core_grades: Allow reset of weights on categories

This commit is contained in:
Frederic Massart
2014-10-03 13:51:29 +08:00
committed by Adrian Greeve
parent c93cf01da7
commit ae93f35317
4 changed files with 62 additions and 0 deletions
+31
View File
@@ -107,6 +107,37 @@ switch ($action) {
$object->set_locked(0, true, true);
}
break;
case 'resetweights':
if ($eid && confirm_sesskey()) {
// This is specific to category items with natural weight as an aggregation method, and can
// only be done by someone who can manage the grades.
if ($type != 'category' || $object->aggregation != GRADE_AGGREGATE_SUM ||
!has_capability('moodle/grade:manage', $context)) {
print_error('nopermissiontoresetweights', 'grades', $returnurl);
}
// Remove the weightoverride flag from the children.
$children = $object->get_children();
foreach ($children as $item) {
if ($item['type'] == 'category') {
$gradeitem = $item['object']->load_grade_item();
} else {
$gradeitem = $item['object'];
}
if ($gradeitem->weightoverride == false) {
continue;
}
$gradeitem->weightoverride = false;
$gradeitem->update();
}
// Force regrading.
$object->force_regrading();
}
}
redirect($returnurl);
+1
View File
@@ -170,6 +170,7 @@ class grade_edit_tree {
$actions .= $this->gtree->get_hiding_icon($element, $this->gpr);
$actions .= $this->gtree->get_locking_icon($element, $this->gpr);
$actions .= $this->gtree->get_reset_icon($element, $this->gpr);
$mode = ($USER->gradeediting[$COURSE->id]) ? 'advanced' : 'simple';
+28
View File
@@ -1465,6 +1465,34 @@ class grade_structure {
return $strparams;
}
/**
* Return a reset icon for the given element.
*
* @param array $element An array representing an element in the grade_tree
* @param object $gpr A grade_plugin_return object
* @return string
*/
public function get_reset_icon($element, $gpr) {
global $CFG, $OUTPUT;
// Limit to category items set to use the natural weights aggregation method, and users
// with the capability to manage grades.
if ($element['type'] != 'category' || $element['object']->aggregation != GRADE_AGGREGATE_SUM ||
!has_capability('moodle/grade:manage', $this->context)) {
return '';
}
$str = get_string('resetweights', 'grades', $this->get_params_for_iconstr($element));
$url = new moodle_url('/grade/edit/tree/action.php', array(
'id' => $this->courseid,
'action' => 'resetweights',
'eid' => $element['eid'],
'sesskey' => sesskey(),
));
return $OUTPUT->action_icon($gpr->add_url_params($url), new pix_icon('t/reset', $str));
}
/**
* Return edit icon for give element
*
+2
View File
@@ -469,6 +469,7 @@ $string['nonunlockableverbose'] = 'This grade cannot be unlocked until {$a->item
$string['nonweightedpct'] = 'non-weighted %';
$string['nooutcome'] = 'No outcome';
$string['nooutcomes'] = 'Outcome items must be linked to a course outcome, but there are no outcomes for this course. Would you like to add one?';
$string['nopermissiontoresetweights'] = 'No permission to reset the weights';
$string['nopublish'] = 'Do not publish';
$string['norolesdefined'] = 'No roles defined in Administration > Grades > General settings > Graded roles';
$string['noscales'] = 'Outcomes must be linked to a course scale or global scale, but there are none. Would you like to add one?';
@@ -567,6 +568,7 @@ $string['reportdefault'] = 'Report default ({$a})';
$string['reportplugins'] = 'Report plugins';
$string['reportsettings'] = 'Report settings';
$string['reprintheaders'] = 'Reprint headers';
$string['resetweights'] = 'Reset weights of {$a->itemname}';
$string['respectingcurrentdata'] = 'leaving current configuration unmodified';
$string['rowpreviewnum'] = 'Preview rows';
$string['savechanges'] = 'Save changes';