Skip to content
Browse files

MDL-35963: Assignment - do not accept empty submissions

  • Loading branch information...
1 parent 8068fcb commit 34b8f3a83dec2a92f918437013f1e8a2f430d09d Damyon Wiese committed with damyon Nov 19, 2012
Showing with 29 additions and 9 deletions.
  1. +1 −0 mod/assign/lang/en/assign.php
  2. +28 −9 mod/assign/locallib.php
View
1 mod/assign/lang/en/assign.php
@@ -101,6 +101,7 @@
$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
37 mod/assign/locallib.php
@@ -320,11 +320,12 @@ public function view($action='') {
$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 @@ public function view($action='') {
$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 @@ public function view($action='') {
} 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 @@ private function view_student_error_message() {
* 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 @@ private function view_edit_submission_page($mform) {
$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 @@ private function format_submission_for_log(stdClass $submission) {
* 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,12 +3742,24 @@ private function process_save_submission(&$mform) {
}
+ $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);

0 comments on commit 34b8f3a

Please sign in to comment.
Something went wrong with that request. Please try again.