From daaf84ec44687ac94a30b69ef0357527679b8a49 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 31 Jul 2012 11:46:53 +0800 Subject: [PATCH 1/2] MDL-32759 Assignment 2.2: Changing grade for existing assignments will show warning that grades will not be scaled --- mod/assignment/assignment.js | 12 ++++++++++++ mod/assignment/lang/en/assignment.php | 1 + mod/assignment/mod_form.php | 17 ++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mod/assignment/assignment.js b/mod/assignment/assignment.js index 8615c4bd466..8a5844087d5 100644 --- a/mod/assignment/assignment.js +++ b/mod/assignment/assignment.js @@ -35,3 +35,15 @@ M.mod_assignment.init_tree = function(Y, expand_all, htmlid) { tree.render(); }); }; + +M.mod_assignment.init_grade_change = function(Y) { + var gradenode = Y.one('#id_grade'); + if (gradenode) { + var originalvalue = gradenode.get('value'); + gradenode.on('change', function() { + if (gradenode.get('value') != originalvalue) { + alert(M.str.mod_assignment.changegradewarning); + } + }); + } +}; \ No newline at end of file diff --git a/mod/assignment/lang/en/assignment.php b/mod/assignment/lang/en/assignment.php index 98ec8f4ec09..7aef1ae676d 100644 --- a/mod/assignment/lang/en/assignment.php +++ b/mod/assignment/lang/en/assignment.php @@ -57,6 +57,7 @@ $string['assignment:view'] = 'View assignment'; $string['availabledate'] = 'Available from'; $string['cannotdeletefiles'] = 'An error occurred and files could not be deleted'; $string['cannotviewassignment'] = 'You can not view this assignment'; +$string['changegradewarning'] = 'This assignment has graded submissions and changing the grade will not automatically re-calculate existing submission grades. You must re-grade all existing submissions, if you wish to change the grade.'; $string['comment'] = 'Comment'; $string['commentinline'] = 'Comment inline'; $string['commentinline_help'] = 'If enabled, the submission text will be copied into the feedback comment field during grading, making it easier to comment inline (using a different colour, perhaps) or to edit the original text.'; diff --git a/mod/assignment/mod_form.php b/mod/assignment/mod_form.php index 85c84238a1f..56b407d6ea6 100644 --- a/mod/assignment/mod_form.php +++ b/mod/assignment/mod_form.php @@ -9,7 +9,7 @@ class mod_assignment_mod_form extends moodleform_mod { protected $_assignmentinstance = null; function definition() { - global $CFG, $DB; + global $CFG, $DB, $PAGE; $mform =& $this->_form; // this hack is needed for different settings of each subtype @@ -76,6 +76,21 @@ class mod_assignment_mod_form extends moodleform_mod { $this->standard_coursemodule_elements(); $this->add_action_buttons(); + + // Add warning popup/noscript tag, if grades are changed by user. + if ($mform->elementExists('grade') && !empty($this->_instance) && $DB->record_exists_select('assignment_submissions', 'assignment = ? AND grade <> -1', array($this->_instance))) { + $module = array( + 'name' => 'mod_assignment', + 'fullpath' => '/mod/assignment/assignment.js', + 'requires' => array('node', 'event'), + 'strings' => array(array('changegradewarning', 'mod_assignment')) + ); + $PAGE->requires->js_init_call('M.mod_assignment.init_grade_change', null, false, $module); + + // Add noscript tag in case + $noscriptwarning = $mform->createElement('static', 'warning', null, html_writer::tag('noscript', get_string('changegradewarning', 'mod_assignment'))); + $mform->insertElementBefore($noscriptwarning, 'grade'); + } } // Needed by plugin assignment types if they include a filemanager element in the settings form From dea75f643d797bed90d43fff91e49bb839502648 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 31 Jul 2012 12:04:37 +0800 Subject: [PATCH 2/2] MDL-32759 Assignment: Grades will not be scaled for new assignment module, and added warning message for user --- lib/grade/grade_item.php | 3 ++- mod/assign/lang/en/assign.php | 1 + mod/assign/mod_form.php | 17 ++++++++++++++++- mod/assign/module.js | 12 ++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 8b1d3122f08..12afe84e393 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -742,7 +742,8 @@ class grade_item extends grade_object { // Standardise score to the new grade range // NOTE: this is not compatible with current assignment grading - if ($this->itemmodule != 'assignment' and ($rawmin != $this->grademin or $rawmax != $this->grademax)) { + $isassignmentmodule = ($this->itemmodule == 'assignment') || ($this->itemmodule == 'assign'); + if (!$isassignmentmodule && ($rawmin != $this->grademin or $rawmax != $this->grademax)) { $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax); } diff --git a/mod/assign/lang/en/assign.php b/mod/assign/lang/en/assign.php index 9ab4132b561..5550348b17f 100644 --- a/mod/assign/lang/en/assign.php +++ b/mod/assign/lang/en/assign.php @@ -65,6 +65,7 @@ $string['batchoperationconfirmreverttodraft'] = 'Revert selected submissions to $string['batchoperationlock'] = 'lock submissions'; $string['batchoperationunlock'] = 'unlock submissions'; $string['batchoperationreverttodraft'] = 'revert submissions to draft'; +$string['changegradewarning'] = 'This assignment has graded submissions and changing the grade will not automatically re-calculate existing submission grades. You must re-grade all existing submissions, if you wish to change the grade.'; $string['comment'] = 'Comment'; $string['conversionexception'] = 'Could not convert assignment. Exception was: {$a}.'; $string['configshowrecentsubmissions'] = 'Everyone can see notifications of submissions in recent activity reports.'; diff --git a/mod/assign/mod_form.php b/mod/assign/mod_form.php index afc94848644..16a20b87be9 100644 --- a/mod/assign/mod_form.php +++ b/mod/assign/mod_form.php @@ -45,7 +45,7 @@ class mod_assign_mod_form extends moodleform_mod { * @return void */ function definition() { - global $CFG, $DB; + global $CFG, $DB, $PAGE; $mform = $this->_form; $mform->addElement('header', 'general', get_string('general', 'form')); @@ -120,6 +120,21 @@ class mod_assign_mod_form extends moodleform_mod { $this->standard_coursemodule_elements(); $this->add_action_buttons(); + + // Add warning popup/noscript tag, if grades are changed by user. + if ($mform->elementExists('grade') && !empty($this->_instance) && $DB->record_exists_select('assign_grades', 'assignment = ? AND grade <> -1', array($this->_instance))) { + $module = array( + 'name' => 'mod_assign', + 'fullpath' => '/mod/assign/module.js', + 'requires' => array('node', 'event'), + 'strings' => array(array('changegradewarning', 'mod_assign')) + ); + $PAGE->requires->js_init_call('M.mod_assign.init_grade_change', null, false, $module); + + // Add noscript tag in case + $noscriptwarning = $mform->createElement('static', 'warning', null, html_writer::tag('noscript', get_string('changegradewarning', 'mod_assign'))); + $mform->insertElementBefore($noscriptwarning, 'grade'); + } } /** diff --git a/mod/assign/module.js b/mod/assign/module.js index d01c9b30318..a1cbe079237 100644 --- a/mod/assign/module.js +++ b/mod/assign/module.js @@ -127,4 +127,16 @@ M.mod_assign.init_grading_options = function(Y) { }); } }); +}; + +M.mod_assign.init_grade_change = function(Y) { + var gradenode = Y.one('#id_grade'); + if (gradenode) { + var originalvalue = gradenode.get('value'); + gradenode.on('change', function() { + if (gradenode.get('value') != originalvalue) { + alert(M.str.mod_assign.changegradewarning); + } + }); + } }; \ No newline at end of file