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

This commit is contained in:
Aaron Wells 2013-11-15 15:39:48 +13:00
parent 1a727e121e
commit d54404e5bb
2 changed files with 26 additions and 8 deletions

View File

@ -6760,31 +6760,40 @@ class assign {
}
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 File

@ -116,4 +116,13 @@ abstract class assign_submission_plugin extends assign_plugin {
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) {
}
}