mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-28728 SCORM - add capability to allow users to delete own attempts - given to no-one by default.
This commit is contained in:
parent
f89a83b87b
commit
d32e353e35
@ -76,6 +76,12 @@ $capabilities = array(
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
'mod/scorm:deleteownresponses' => array(
|
||||
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array()
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -73,6 +73,7 @@ $string['defaultgradesettings'] = 'Default grade settings';
|
||||
$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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -20,6 +20,7 @@ require_once($CFG->dirroot.'/mod/scorm/locallib.php');
|
||||
$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_title($pagetitle);
|
||||
$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 @@ require($CFG->dirroot . '/mod/scorm/tabs.php');
|
||||
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');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user