MDL-35963: Assignment - do not accept empty submissions

This commit is contained in:
Damyon Wiese 2012-11-19 16:56:02 +08:00 committed by Damyon Wiese
parent 8068fcb5b6
commit 34b8f3a83d
2 changed files with 29 additions and 9 deletions

View File

@ -101,6 +101,7 @@ $string['download all submissions'] = 'Download all submissions in a zip file.';
$string['duedate'] = 'Due date';
$string['duedate_help'] = 'This is when the assignment is due. Submissions will still be allowed after this date but any assignments submitted after this date are marked as late. To prevent submissions after a certain date - set the assignment cut off date.';
$string['duedateno'] = 'No due date';
$string['submissionempty'] = 'Nothing was submitted';
$string['duedatereached'] = 'The due date for this assignment has now passed';
$string['duedatevalidation'] = 'Due date must be after the allow submissions from date.';
$string['editsubmission'] = 'Edit my submission';

View File

@ -320,11 +320,12 @@ class assign {
$o = '';
$mform = null;
$notices = array();
// handle form submissions first
// Handle form submissions first.
if ($action == 'savesubmission') {
$action = 'editsubmission';
if ($this->process_save_submission($mform)) {
if ($this->process_save_submission($mform, $notices)) {
$action = 'view';
}
} else if ($action == 'lock') {
@ -384,7 +385,7 @@ class assign {
$returnparams = array('rownum'=>optional_param('rownum', 0, PARAM_INT));
$this->register_return_link($action, $returnparams);
// now show the right view page
// Now show the right view page.
if ($action == 'previousgrade') {
$mform = null;
$o .= $this->view_single_grade_page($mform, -1);
@ -401,7 +402,7 @@ class assign {
} else if ($action == 'viewpluginassignsubmission') {
$o .= $this->view_plugin_content('assignsubmission');
} else if ($action == 'editsubmission') {
$o .= $this->view_edit_submission_page($mform);
$o .= $this->view_edit_submission_page($mform, $notices);
} else if ($action == 'grading') {
$o .= $this->view_grading_page();
} else if ($action == 'downloadall') {
@ -2400,9 +2401,10 @@ class assign {
* View edit submissions page.
*
* @param moodleform $mform
* @param array $notices A list of notices to display at the top of the edit submission form (e.g. from plugins).
* @return void
*/
private function view_edit_submission_page($mform) {
private function view_edit_submission_page($mform, $notices) {
global $CFG;
$o = '';
@ -2426,6 +2428,10 @@ class assign {
$mform = new mod_assign_submission_form(null, array($this, $data));
}
foreach ($notices as $notice) {
$o .= $this->get_renderer()->notification($notice);
}
$o .= $this->get_renderer()->render(new assign_form('editsubmissionform',$mform));
$o .= $this->view_footer();
@ -3699,15 +3705,16 @@ class assign {
* save assignment submission
*
* @param moodleform $mform
* @param array $notices Any error messages that should be shown to the user at the top of the edit submission form.
* @return bool
*/
private function process_save_submission(&$mform) {
private function process_save_submission(&$mform, &$notices) {
global $USER, $CFG;
// Include submission form
// Include submission form.
require_once($CFG->dirroot . '/mod/assign/submission_form.php');
// Need submit permission to submit an assignment
// Need submit permission to submit an assignment.
require_capability('mod/assign:submit', $this->context);
require_sesskey();
@ -3735,13 +3742,25 @@ class assign {
}
$allempty = true;
$pluginerror = false;
foreach ($this->submissionplugins as $plugin) {
if ($plugin->is_enabled()) {
if (!$plugin->save($submission, $data)) {
print_error($plugin->get_error());
$notices[] = $plugin->get_error();
$pluginerror = true;
}
if (!$allempty || !$plugin->is_empty($submission)) {
$allempty = false;
}
}
}
if ($pluginerror || $allempty) {
if ($allempty) {
$notices[] = get_string('submissionempty', 'mod_assign');
}
return false;
}
$this->update_submission($submission, $USER->id, true, $this->get_instance()->teamsubmission);