MDL-86369 mod_scorm: fix attempt deletion behaviour on submit/redirect.
Standard after a POST submission is to redirect back to where user came from (in this case), to avoid awkward page reload behaviour. Also fix bug where deleting an attempt for a user, where the attempt didn't exist would delete all attempts for that user.
This commit is contained in:
@@ -1487,6 +1487,11 @@ function scorm_delete_attempt($userid, $scorm, $attemptornumber) {
|
||||
$attempt = $attemptornumber;
|
||||
} else {
|
||||
$attempt = scorm_get_attempt($userid, $scorm->id, $attemptornumber, false);
|
||||
|
||||
// The attempt doesn't exist.
|
||||
if ($attempt === null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
scorm_delete_tracks($scorm->id, null, $userid, $attempt->id);
|
||||
|
||||
@@ -31,6 +31,8 @@ define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2);
|
||||
$id = required_param('id', PARAM_INT);// Course Module ID, or ...
|
||||
$download = optional_param('download', '', PARAM_RAW);
|
||||
$mode = optional_param('mode', '', PARAM_ALPHA); // Report mode.
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$attemptids = optional_param_array('attemptid', [], PARAM_RAW);
|
||||
|
||||
$cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
@@ -56,6 +58,12 @@ $PAGE->set_pagelayout('report');
|
||||
|
||||
require_capability('mod/scorm:viewreport', $contextmodule);
|
||||
|
||||
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
|
||||
if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
|
||||
redirect($PAGE->url, get_string('scormresponsedeleted', 'scorm'), null, \core\output\notification::NOTIFY_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
// Activate the secondary nav tab.
|
||||
navigation_node::override_active_url(new moodle_url('/mod/scorm/report.php', ['id' => $id]));
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ class report extends \mod_scorm\report {
|
||||
global $CFG, $DB, $OUTPUT, $PAGE;
|
||||
|
||||
$contextmodule = \context_module::instance($cm->id);
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
|
||||
$attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
|
||||
$PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
|
||||
|
||||
@@ -50,11 +48,6 @@ class report extends \mod_scorm\report {
|
||||
echo $renderer->report_actionbar($actionbar);
|
||||
}
|
||||
|
||||
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
|
||||
if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
|
||||
echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
|
||||
}
|
||||
}
|
||||
// Find out current groups mode.
|
||||
$currentgroup = groups_get_activity_group($cm, true);
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ class report extends \mod_scorm\report {
|
||||
global $CFG, $DB, $OUTPUT, $PAGE;
|
||||
|
||||
$contextmodule = \context_module::instance($cm->id);
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
|
||||
$attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
|
||||
$PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
|
||||
|
||||
@@ -51,11 +49,6 @@ class report extends \mod_scorm\report {
|
||||
echo $renderer->report_actionbar($actionbar);
|
||||
}
|
||||
|
||||
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
|
||||
if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
|
||||
echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
|
||||
}
|
||||
}
|
||||
// Find out current groups mode.
|
||||
$currentgroup = groups_get_activity_group($cm, true);
|
||||
|
||||
|
||||
@@ -45,8 +45,6 @@ class report extends \mod_scorm\report {
|
||||
global $CFG, $DB, $OUTPUT, $PAGE;
|
||||
|
||||
$contextmodule = \context_module::instance($cm->id);
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
|
||||
$attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
|
||||
$PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
|
||||
|
||||
@@ -57,11 +55,6 @@ class report extends \mod_scorm\report {
|
||||
echo $renderer->report_actionbar($actionbar);
|
||||
}
|
||||
|
||||
if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
|
||||
if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
|
||||
echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
|
||||
}
|
||||
}
|
||||
// Find out current groups mode.
|
||||
$currentgroup = groups_get_activity_group($cm, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user