]> git.mjollnir.org Git - moodle.git/commitdiff
add time restriction MDL-12588 - add ability to restrict the viewing of SCORM objects...
authordanmarsden <danmarsden>
Fri, 28 Nov 2008 09:20:59 +0000 (09:20 +0000)
committerdanmarsden <danmarsden>
Fri, 28 Nov 2008 09:20:59 +0000 (09:20 +0000)
lang/en_utf8/help/scorm/timerestrict.html [new file with mode: 0644]
lang/en_utf8/scorm.php
mod/scorm/db/install.xml
mod/scorm/db/upgrade.php
mod/scorm/lib.php
mod/scorm/loadSCO.php
mod/scorm/mod_form.php
mod/scorm/player.php
mod/scorm/version.php
mod/scorm/view.php

diff --git a/lang/en_utf8/help/scorm/timerestrict.html b/lang/en_utf8/help/scorm/timerestrict.html
new file mode 100644 (file)
index 0000000..ca87068
--- /dev/null
@@ -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>
\ No newline at end of file
index 748b88aa11add980062ab67e2023a0bc6e097a6a..4b01d1e458beb6ed712348be5a8447a18fb6916c 100644 (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';
index a0d047d5f62393a08d8646fdf9e27c0ee388669c..de8118e07624147276dfd8e73667f7ed1bca0cd2 100644 (file)
         <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"/>
index 57a6a55777f100cb2bed35f02bf342dbf3049638..57462ac547be9bfc5df5b29ef98c445eb2f2b617 100644 (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;
 }
 
index 00a7dbbc5f93ad42fd1ff6dd1ac962e27a3cc904..8247b1bd3b48279df51e6dc0d73f1f755907a936 100755 (executable)
@@ -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;
index db062e206c220448b634ae7c54f6da183056e37f..c954105b4aff372d955c9c6773ab48b1ba1bf807 100755 (executable)
     }
 
     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)) {
index 9c41f1eaef8f2b9d83cd1607dbfc0434637977ac..5dcb8c53424569d4e727458e287105d8b53777ee 100644 (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) {
index 2029122fafba0d7f51059dd177e71323259cf304..cc9b85890f8392bc66d3ffefdfb150bdd86650c5 100755 (executable)
         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
     //
index 8ac61d8a4c042e2fb462dec4964c92395d7646ce..163d51b9c88911da0c1d842cf8cc10c126911c14 100755 (executable)
@@ -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)?
 
index 4ccdc3c579804b501ed4b62339b094016f08a662..a61d54a2edf7630618e63dd08f14e78c6d5fa57f 100755 (executable)
         $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);
-?>
+?>
\ No newline at end of file