Skip to content
Browse files

MDL-44971 Add hook to "add_attempt" for mod/assign/submission plugins

  • Loading branch information...
1 parent 1a727e1 commit d54404e5bb365539cd24be2c0759c380fcb7c902 @agwells agwells committed Nov 15, 2013
Showing with 26 additions and 8 deletions.
  1. +17 −8 mod/assign/locallib.php
  2. +9 −0 mod/assign/submissionplugin.php
View
25 mod/assign/locallib.php
@@ -6760,31 +6760,40 @@ protected function add_attempt($userid) {
}
if ($this->get_instance()->teamsubmission) {
- $submission = $this->get_group_submission($userid, 0, false);
+ $oldsubmission = $this->get_group_submission($userid, 0, false);
} else {
- $submission = $this->get_user_submission($userid, false);
+ $oldsubmission = $this->get_user_submission($userid, false);
}
- if (!$submission) {
+ if (!$oldsubmission) {
return false;
}
// No more than max attempts allowed.
if ($this->get_instance()->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS &&
- $submission->attemptnumber >= ($this->get_instance()->maxattempts - 1)) {
+ $oldsubmission->attemptnumber >= ($this->get_instance()->maxattempts - 1)) {
return false;
}
// Create the new submission record for the group/user.
if ($this->get_instance()->teamsubmission) {
- $submission = $this->get_group_submission($userid, 0, true, $submission->attemptnumber+1);
+ $newsubmission = $this->get_group_submission($userid, 0, true, $oldsubmission->attemptnumber + 1);
} else {
- $submission = $this->get_user_submission($userid, true, $submission->attemptnumber+1);
+ $newsubmission = $this->get_user_submission($userid, true, $oldsubmission->attemptnumber + 1);
}
// Set the status of the new attempt to reopened.
- $submission->status = ASSIGN_SUBMISSION_STATUS_REOPENED;
- $this->update_submission($submission, $userid, false, $this->get_instance()->teamsubmission);
+ $newsubmission->status = ASSIGN_SUBMISSION_STATUS_REOPENED;
+
+ // Give each submission plugin a chance to process the add_attempt.
+ $plugins = $this->get_submission_plugins();
+ foreach ($plugins as $plugin) {
+ if ($plugin->is_enabled() && $plugin->is_visible()) {
+ $plugin->add_attempt($oldsubmission, $newsubmission);
+ }
+ }
+
+ $this->update_submission($newsubmission, $userid, false, $this->get_instance()->teamsubmission);
return true;
}
View
9 mod/assign/submissionplugin.php
@@ -116,4 +116,13 @@ public function unlock($submission, stdClass $flags) {
public function revert_to_draft(stdClass $submission) {
}
+ /**
+ * Carry out any extra processing required when a student is given a new attempt
+ * (i.e. when the submission is "reopened"
+ * @param stdClass $oldsubmission The previous attempt
+ * @param stdClass $newsubmission The new attempt
+ */
+ public function add_attempt(stdClass $oldsubmission, stdClass $newsubmission) {
+ }
+
}

0 comments on commit d54404e

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