Permalink
Browse files

MDL-28728 SCORM - add capability to allow users to delete own attempt…

…s - given to no-one by default.
  • Loading branch information...
1 parent f89a83b commit d32e353e355142a7780781954a41647ca22e4318 @danmarsden danmarsden committed Dec 2, 2011
Showing with 35 additions and 4 deletions.
  1. +6 −0 mod/scorm/db/access.php
  2. +1 −0 mod/scorm/lang/en/scorm.php
  3. +11 −2 mod/scorm/locallib.php
  4. +1 −1 mod/scorm/version.php
  5. +16 −1 mod/scorm/view.php
View
6 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()
)
);
View
1 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';
View
13 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 .= '<p><font color="#cc0000">'.get_string('exceededmaxattempts', 'scorm').'</font></p>';
}
+ 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;
}
View
2 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;
View
17 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,14 +84,28 @@
$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');
// Print the main part of the page
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');

0 comments on commit d32e353

Please sign in to comment.