Merge branch 'wip-MDL-44971-2.7-submission_reopen_hook' of https://github.com/catalyst/moodle

This commit is contained in:
Sam Hemelryk
2014-04-09 10:15:50 +12:00
2 changed files with 26 additions and 8 deletions
+17 -8
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;
}
+9
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) {
}
}