add time restriction MDL-12588 - add ability to restrict the viewing of SCORM objects using a time/date restriction like most other modules already allow.

This commit is contained in:
danmarsden
2008-11-28 09:20:59 +00:00
parent a1442d4e3e
commit d54e2145ba
10 changed files with 112 additions and 7 deletions
@@ -0,0 +1,8 @@
<h1>Restrict times</h1>
<p>This setting allows you to define a time window within which
participants are allowed to attempt a SCORM.</p>
<p>To set an open-ended close date just set the time very far in the future.</p>
<p>If you don't need this at all then uncheck the box.</p>
+5
View File
@@ -55,6 +55,7 @@ $string['everytime']= 'Every time it\'s used';
$string['exit'] = 'Exit course';
$string['exitactivity'] = 'Exit activity';
$string['expcoll'] = 'Expand/Collide';
$string['expired'] = 'Sorry, this activity closed on $a and is no longer available';
$string['external']= 'Update external packages timing';
$string['failed'] = 'Failed';
$string['firstaccess'] = 'First access';
@@ -122,6 +123,7 @@ $string['normal'] = 'Normal';
$string['noscriptnoscorm'] = 'Your browser does not support javascript or it has javascript support disabled. This SCORM package may not play or save data correctly.';
$string['not_corr_type'] = 'Type mismatch for tag $a->tag';
$string['notattempted'] = 'Not attempted';
$string['notopenyet'] = 'Sorry, this activity is not available until $a';
$string['objectives'] = 'Objectives';
$string['onchanges']= 'Whenever it changes';
$string['organization'] = 'Organization';
@@ -152,7 +154,9 @@ $string['scorm:savetrack'] = 'Save tracks';
$string['scorm:skipview'] = 'Skip overview';
$string['scorm:viewreport'] = 'View reports';
$string['scorm:viewscores'] = 'View scores';
$string['scormclose'] = 'Until';
$string['scormcourse'] = 'Learning Course';
$string['scormopen'] = 'Open';
$string['scormtype'] = 'Type';
$string['scrollbars'] = 'Allow the window to be scrolled';
$string['sided'] = 'On the left side';
@@ -168,6 +172,7 @@ $string['suspended'] = 'Suspended';
$string['syntax'] = 'Syntax error';
$string['tag_error'] = 'Unknown tag ($a->tag) with this content: $a->value';
$string['time'] = 'Time';
$string['timerestrict'] = 'Restrict answering to this time period';
$string['title'] = 'Title';
$string['too_many_attributes'] = 'Tag $a->tag has too many attributes';
$string['too_many_children'] = 'Tag $a->tag has too many children';
+4 -2
View File
@@ -35,8 +35,10 @@
<FIELD NAME="popup" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="auto" NEXT="options"/>
<FIELD NAME="options" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="popup" NEXT="width"/>
<FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="100" SEQUENCE="false" ENUM="false" PREVIOUS="options" NEXT="height"/>
<FIELD NAME="height" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="600" SEQUENCE="false" ENUM="false" PREVIOUS="width" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="height"/>
<FIELD NAME="height" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="600" SEQUENCE="false" ENUM="false" PREVIOUS="width" NEXT="timeopen"/>
<FIELD NAME="timeopen" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="height" NEXT="timeclose"/>
<FIELD NAME="timeclose" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timeopen" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timeclose"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+14 -1
View File
@@ -328,7 +328,20 @@ function xmldb_scorm_upgrade($oldversion) {
upgrade_mod_savepoint($result, 2008090307, 'scorm');
}
if ($result && $oldversion < 2008090308) {
$table = new xmldb_table('scorm');
$field = new xmldb_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'height');
if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timeopen');
if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
/// scorm savepoint reached
upgrade_mod_savepoint($result, 2008090308, 'scorm');
}
return $result;
}
+10
View File
@@ -22,6 +22,11 @@ function scorm_add_instance($scorm, $mform=null) {
require_once('locallib.php');
if (empty($scorm->timerestrict)) {
$scorm->timeopen = 0;
$scorm->timeclose = 0;
}
$cmid = $scorm->coursemodule;
$cmidnumber = $scorm->cmidnumber;
$courseid = $scorm->course;
@@ -104,6 +109,11 @@ function scorm_update_instance($scorm, $mform=null) {
require_once('locallib.php');
if (empty($scorm->timerestrict)) {
$scorm->timeopen = 0;
$scorm->timeclose = 0;
}
$cmid = $scorm->coursemodule;
$cmidnumber = $scorm->cmidnumber;
$courseid = $scorm->course;
+11 -1
View File
@@ -33,7 +33,17 @@
}
require_login($course->id, false, $cm);
//check if scorm closed
$timenow = time();
if ($scorm->timeclose !=0) {
if ($scorm->timeopen > $timenow) {
error(get_string("notopenyet", "scorm", userdate($scorm->timeopen)));
} else if ($timenow > $scorm->timeclose) {
error(get_string("expired", "scorm", userdate($scorm->timeclose)));
}
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!empty($scoid)) {
+18
View File
@@ -66,6 +66,19 @@ class mod_scorm_mod_form extends moodleform_mod {
$mform->addElement('file', 'packagefile', get_string('package','scorm'));
$mform->disabledIf('packagefile', 'scormtype', 'noteq', SCORM_TYPE_LOCAL);
//-------------------------------------------------------------------------------
// Time restrictions
$mform->addElement('header', 'timerestricthdr', get_string('timerestrict', 'scorm'));
$mform->addElement('checkbox', 'timerestrict', get_string('timerestrict', 'scorm'));
$mform->setHelpButton('timerestrict', array("timerestrict", get_string("timerestrict","scorm"), "scorm"));
$mform->addElement('date_time_selector', 'timeopen', get_string("scormopen", "scorm"));
$mform->disabledIf('timeopen', 'timerestrict');
$mform->addElement('date_time_selector', 'timeclose', get_string("scormclose", "scorm"));
$mform->disabledIf('timeclose', 'timerestrict');
//-------------------------------------------------------------------------------
// Other Settings
$mform->addElement('header', 'advanced', get_string('othersettings', 'form'));
@@ -267,6 +280,11 @@ class mod_scorm_mod_form extends moodleform_mod {
if (isset($default_values['instance'])) {
$default_values['datadir'] = $default_values['instance'];
}
if (empty($default_values['timeopen'])) {
$default_values['timerestrict'] = 0;
} else {
$default_values['timerestrict'] = 1;
}
}
function validation($data, $files) {
+25
View File
@@ -65,7 +65,32 @@
print_header($pagetitle, $course->fullname, $navigation,
'', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);
notice(get_string("activityiscurrentlyhidden"));
print_footer($course);
die;
}
//check if scorm closed
$timenow = time();
if ($scorm->timeclose !=0) {
if ($scorm->timeopen > $timenow) {
$navlinks[] = array('name' => format_string($scorm->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header($pagetitle, $course->fullname, $navigation,
'', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);
print_simple_box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "center");
print_footer($course);
die;
} elseif ($timenow > $scorm->timeclose) {
$navlinks[] = array('name' => format_string($scorm->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header($pagetitle, $course->fullname, $navigation,
'', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);
print_simple_box(get_string("expired", "scorm", userdate($scorm->timeclose)), "center");
print_footer($course);
die;
}
}
//
// TOC processing
//
+1 -1
View File
@@ -10,7 +10,7 @@
// catch up now, so until 27th October please only increment in very tiny steps
// in HEAD, until we get past that date..
$module->version = 2008090307; // The (date) version of this module
$module->version = 2008090308; // The (date) version of this module
$module->requires = 2008090108; // The version of Moodle that is required
$module->cron = 300; // How often should cron check this module (seconds)?
+16 -2
View File
@@ -87,6 +87,20 @@
$attemptstatus = scorm_get_attempt_status($USER,$scorm);
}
print_simple_box(format_text($scorm->summary).$attemptstatus, 'center', '70%', '', 5, 'generalbox', 'intro');
scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
$scormopen = true;
$timenow = time();
if ($scorm->timeclose !=0) {
if ($scorm->timeopen > $timenow) {
print_simple_box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "center");
$scormopen = false;
} else if ($timenow > $scorm->timeclose) {
print_simple_box(get_string("expired", "scorm", userdate($scorm->timeclose)), "center");
$scormopen = false;
}
}
if ($scormopen) {
scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
}
print_footer($course);
?>
?>