Skip to content

Commit

Permalink
MDL-43985 Assign: Allow teachers to skip notifying students about gra…
Browse files Browse the repository at this point in the history
…de update.

Backport of MDL-33600

Conflicts:
	mod/assign/locallib.php
  • Loading branch information
Damyon Wiese committed Mar 21, 2014
1 parent c2066a0 commit f9323c7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions mod/assign/lang/en/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@
$string['saveallquickgradingchanges'] = 'Save all quick grading changes';
$string['savenext'] = 'Save and show next';
$string['scale'] = 'Scale';
$string['sendstudentnotifications'] = 'Notify students';
$string['sendstudentnotifications_help'] = 'If enabled, students receive a message about the updated grade or feedback.';
$string['sendnotifications'] = 'Notify graders about submissions';
$string['sendnotifications_help'] = 'If enabled, graders (usually teachers) receive a message whenever a student submits an assignment, early, on time and late. Message methods are configurable.';
$string['selectlink'] = 'Select...';
Expand Down
14 changes: 11 additions & 3 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4573,7 +4573,10 @@ protected function process_save_quick_grades() {
}

$this->update_grade($grade);
$this->notify_grade_modified($grade);
// Allow teachers to skip sending notifications.
if (optional_param('sendstudentnotifications', true, PARAM_BOOL)) {
$this->notify_grade_modified($grade);
}

// Save outcomes.
if ($CFG->enableoutcomes) {
Expand Down Expand Up @@ -5215,6 +5218,8 @@ public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data,
$mform->setDefault('addattempt', 0);
}
}
$mform->addElement('selectyesno', 'sendstudentnotifications', get_string('sendstudentnotifications', 'assign'));
$mform->setDefault('sendstudentnotifications', 1);

$mform->addElement('hidden', 'action', 'submitgrade');
$mform->setType('action', PARAM_ALPHA);
Expand Down Expand Up @@ -5531,8 +5536,11 @@ protected function apply_grade_to_user($formdata, $userid, $attemptnumber) {
}
}
$this->update_grade($grade);
$this->notify_grade_modified($grade);
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
// Note the default if not provided for this option is true (e.g. webservices).
// This is for backwards compatibility.
if (!isset($formdata->sendstudentnotifications) || $formdata->sendstudentnotifications) {
$this->notify_grade_modified($grade);
}

$this->add_to_log('grade submission', $this->format_grade_for_log($grade));
}
Expand Down
4 changes: 4 additions & 0 deletions mod/assign/quickgradingform.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function definition() {
$mform->addElement('hidden', 'action', 'quickgrade');
$mform->setType('action', PARAM_ALPHA);

// Skip notifications option.
$mform->addElement('selectyesno', 'sendstudentnotifications', get_string('sendstudentnotifications', 'assign'));
$mform->setDefault('sendstudentnotifications', 1);

// Buttons.
$savemessage = get_string('saveallquickgradingchanges', 'assign');
$mform->addElement('submit', 'savequickgrades', $savemessage);
Expand Down
4 changes: 4 additions & 0 deletions mod/assign/tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ public function test_cron() {
$assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
$assign->testable_apply_grade_to_user($data, $this->students[1]->id, 0);

$data->sendstudentnotifications = false;
$assign->testable_apply_grade_to_user($data, $this->students[2]->id, 0);

// Now run cron and see that one message was sent.
$this->preventResetByRollback();
$sink = $this->redirectMessages();
Expand All @@ -490,6 +493,7 @@ public function test_cron() {
assign::cron();

$messages = $sink->get_messages();
// The sent count should be 2, because the 3rd one was marked as do not send notifications.
$this->assertEquals(2, count($messages));
$this->assertEquals(1, $messages[0]->notification);
$this->assertEquals($assign->get_instance()->name, $messages[0]->contexturlname);
Expand Down

0 comments on commit f9323c7

Please sign in to comment.