Skip to content

Commit

Permalink
MDL-28728 SCORM - add capability to allow users to delete own attempt…
Browse files Browse the repository at this point in the history
…s - given to no-one by default.
  • Loading branch information
danmarsden committed Dec 11, 2011
1 parent f89a83b commit d32e353
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions mod/scorm/db/access.php
Expand Up @@ -76,6 +76,12 @@
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
'mod/scorm:deleteownresponses' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array()
)
);

1 change: 1 addition & 0 deletions mod/scorm/lang/en/scorm.php
Expand Up @@ -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';
Expand Down
13 changes: 11 additions & 2 deletions mod/scorm/locallib.php
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/version.php
Expand Up @@ -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;
17 changes: 16 additions & 1 deletion mod/scorm/view.php
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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');

Expand Down

0 comments on commit d32e353

Please sign in to comment.