Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…s - given to no-one by default.
  • Loading branch information...
commit 7d919d8f277571fada7bbd96a356715be8e3956d 1 parent 324ea4d
Dan Marsden danmarsden authored nebgor committed
6 mod/scorm/db/access.php
@@ -76,6 +76,12 @@
76 76 'editingteacher' => CAP_ALLOW,
77 77 'manager' => CAP_ALLOW
78 78 )
  79 + ),
  80 + 'mod/scorm:deleteownresponses' => array(
  81 +
  82 + 'captype' => 'write',
  83 + 'contextlevel' => CONTEXT_MODULE,
  84 + 'archetypes' => array()
79 85 )
80 86 );
81 87
1  mod/scorm/lang/en/scorm.php
@@ -73,6 +73,7 @@
73 73 $string['defaultothersettings'] = 'Other default settings';
74 74 $string['deleteattemptcheck'] = 'Are you absolutely sure you want to completely delete these attempts?';
75 75 $string['deleteallattempts'] = 'Delete all SCORM attempts';
  76 +$string['deleteuserattemptcheck'] = 'Are you absolutely sure you want to completely delete all your attempts?';
76 77 $string['details'] = 'Track details';
77 78 $string['directories'] = 'Show the directory links';
78 79 $string['disabled'] = 'Disabled';
13 mod/scorm/locallib.php
@@ -1031,8 +1031,8 @@ function scorm_element_cmp($a, $b) {
1031 1031 * @param object $scorm a moodle scrom object - mdl_scorm
1032 1032 * @return string - Attempt status string
1033 1033 */
1034   -function scorm_get_attempt_status($user, $scorm) {
1035   - global $DB;
  1034 +function scorm_get_attempt_status($user, $scorm, $cm='') {
  1035 + global $DB, $PAGE, $OUTPUT;
1036 1036
1037 1037 $attempts = scorm_get_attempt_count($user->id, $scorm, true);
1038 1038 if (empty($attempts)) {
@@ -1108,6 +1108,15 @@ function scorm_get_attempt_status($user, $scorm) {
1108 1108 if ($attemptcount >= $scorm->maxattempt and $scorm->maxattempt > 0) {
1109 1109 $result .= '<p><font color="#cc0000">'.get_string('exceededmaxattempts', 'scorm').'</font></p>';
1110 1110 }
  1111 + if (!empty($cm)) {
  1112 + $context = context_module::instance($cm->id);
  1113 + if (has_capability('mod/scorm:deleteownresponses', $context)) {
  1114 + $deleteurl = new moodle_url($PAGE->url, array('action'=>'delete', 'sesskey' => sesskey()));
  1115 + $result .= $OUTPUT->single_button($deleteurl, get_string('deleteallattempts', 'scorm'));
  1116 + }
  1117 + }
  1118 +
  1119 +
1111 1120 return $result;
1112 1121 }
1113 1122
2  mod/scorm/version.php
@@ -25,7 +25,7 @@
25 25
26 26 defined('MOODLE_INTERNAL') || die();
27 27
28   -$module->version = 2011112900; // The current module version (Date: YYYYMMDDXX)
  28 +$module->version = 2011112901; // The current module version (Date: YYYYMMDDXX)
29 29 $module->requires = 2011112900; // Requires this Moodle version
30 30 $module->component = 'mod_scorm'; // Full name of the plugin (used for diagnostics)
31 31 $module->cron = 300;
17 mod/scorm/view.php
@@ -20,6 +20,7 @@
20 20 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
21 21 $a = optional_param('a', '', PARAM_INT); // scorm ID
22 22 $organization = optional_param('organization', '', PARAM_INT); // organization ID
  23 +$action = optional_param('action', '', PARAM_ALPHA);
23 24
24 25 if (!empty($id)) {
25 26 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
@@ -83,6 +84,20 @@
83 84 $PAGE->set_heading($course->fullname);
84 85 echo $OUTPUT->header();
85 86
  87 +if (!empty($action) && confirm_sesskey() && has_capability('mod/scorm:deleteownresponses', $contextmodule)) {
  88 + if ($action == 'delete') {
  89 + $confirmurl = new moodle_url($PAGE->url, array('action'=>'deleteconfirm'));
  90 + echo $OUTPUT->confirm(get_string('deleteuserattemptcheck', 'scorm'), $confirmurl, $PAGE->url);
  91 + echo $OUTPUT->footer();
  92 + exit;
  93 + } else if ($action == 'deleteconfirm') {
  94 + //delete this users attempts.
  95 + $DB->delete_records('scorm_scoes_track', array('userid' => $USER->id, 'scormid' => $scorm->id));
  96 + scorm_update_grades($scorm, $USER->id, true);
  97 + echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
  98 + }
  99 +}
  100 +
86 101 $currenttab = 'info';
87 102 require($CFG->dirroot . '/mod/scorm/tabs.php');
88 103
@@ -90,7 +105,7 @@
90 105 echo $OUTPUT->heading(format_string($scorm->name));
91 106 $attemptstatus = '';
92 107 if ($scorm->displayattemptstatus == 1) {
93   - $attemptstatus = scorm_get_attempt_status($USER, $scorm);
  108 + $attemptstatus = scorm_get_attempt_status($USER, $scorm, $cm);
94 109 }
95 110 echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'generalbox boxaligncenter boxwidthwide', 'intro');
96 111

0 comments on commit 7d919d8

Please sign in to comment.
Something went wrong with that request. Please try again.