diff --git a/mod/scorm/db/access.php b/mod/scorm/db/access.php index b91e3eb640532..b1919909f8345 100644 --- a/mod/scorm/db/access.php +++ b/mod/scorm/db/access.php @@ -76,6 +76,12 @@ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW ) + ), + 'mod/scorm:deleteownresponses' => array( + + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'archetypes' => array() ) ); diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index 5ca3aa8832e68..fa58519e768e2 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -73,6 +73,7 @@ $string['defaultothersettings'] = 'Other default settings'; $string['deleteattemptcheck'] = 'Are you absolutely sure you want to completely delete these attempts?'; $string['deleteallattempts'] = 'Delete all SCORM attempts'; +$string['deleteuserattemptcheck'] = 'Are you absolutely sure you want to completely delete all your attempts?'; $string['details'] = 'Track details'; $string['directories'] = 'Show the directory links'; $string['disabled'] = 'Disabled'; diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 727b872186c76..2a3c4b2698c47 100644 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -1031,8 +1031,8 @@ function scorm_element_cmp($a, $b) { * @param object $scorm a moodle scrom object - mdl_scorm * @return string - Attempt status string */ -function scorm_get_attempt_status($user, $scorm) { - global $DB; +function scorm_get_attempt_status($user, $scorm, $cm='') { + global $DB, $PAGE, $OUTPUT; $attempts = scorm_get_attempt_count($user->id, $scorm, true); if (empty($attempts)) { @@ -1108,6 +1108,15 @@ function scorm_get_attempt_status($user, $scorm) { if ($attemptcount >= $scorm->maxattempt and $scorm->maxattempt > 0) { $result .= '

'.get_string('exceededmaxattempts', 'scorm').'

'; } + if (!empty($cm)) { + $context = context_module::instance($cm->id); + if (has_capability('mod/scorm:deleteownresponses', $context)) { + $deleteurl = new moodle_url($PAGE->url, array('action'=>'delete', 'sesskey' => sesskey())); + $result .= $OUTPUT->single_button($deleteurl, get_string('deleteallattempts', 'scorm')); + } + } + + return $result; } diff --git a/mod/scorm/version.php b/mod/scorm/version.php index c66b90883eb06..374b9b423609f 100644 --- a/mod/scorm/version.php +++ b/mod/scorm/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$module->version = 2011112900; // The current module version (Date: YYYYMMDDXX) +$module->version = 2011112901; // The current module version (Date: YYYYMMDDXX) $module->requires = 2011112900; // Requires this Moodle version $module->component = 'mod_scorm'; // Full name of the plugin (used for diagnostics) $module->cron = 300; diff --git a/mod/scorm/view.php b/mod/scorm/view.php index 2b7775dea5164..787b8b1f1e125 100644 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -20,6 +20,7 @@ $id = optional_param('id', '', PARAM_INT); // Course Module ID, or $a = optional_param('a', '', PARAM_INT); // scorm ID $organization = optional_param('organization', '', PARAM_INT); // organization ID +$action = optional_param('action', '', PARAM_ALPHA); if (!empty($id)) { if (! $cm = get_coursemodule_from_id('scorm', $id)) { @@ -83,6 +84,20 @@ $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); +if (!empty($action) && confirm_sesskey() && has_capability('mod/scorm:deleteownresponses', $contextmodule)) { + if ($action == 'delete') { + $confirmurl = new moodle_url($PAGE->url, array('action'=>'deleteconfirm')); + echo $OUTPUT->confirm(get_string('deleteuserattemptcheck', 'scorm'), $confirmurl, $PAGE->url); + echo $OUTPUT->footer(); + exit; + } else if ($action == 'deleteconfirm') { + //delete this users attempts. + $DB->delete_records('scorm_scoes_track', array('userid' => $USER->id, 'scormid' => $scorm->id)); + scorm_update_grades($scorm, $USER->id, true); + echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess'); + } +} + $currenttab = 'info'; require($CFG->dirroot . '/mod/scorm/tabs.php'); @@ -90,7 +105,7 @@ echo $OUTPUT->heading(format_string($scorm->name)); $attemptstatus = ''; if ($scorm->displayattemptstatus == 1) { - $attemptstatus = scorm_get_attempt_status($USER, $scorm); + $attemptstatus = scorm_get_attempt_status($USER, $scorm, $cm); } echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'generalbox boxaligncenter boxwidthwide', 'intro');