]> git.mjollnir.org Git - moodle.git/commitdiff
Support for events.
authormoodler <moodler>
Wed, 28 Apr 2004 02:56:40 +0000 (02:56 +0000)
committermoodler <moodler>
Wed, 28 Apr 2004 02:56:40 +0000 (02:56 +0000)
Ouch - I thought I'd checked this in days ago

mod/quiz/db/mysql.php
mod/quiz/db/oci8po.php
mod/quiz/db/postgres7.php
mod/quiz/lib.php
mod/quiz/version.php

index 145987b7cab6528ba3a33c895d61273661f7597f..0d5ae9bc204bdd8ddaed89799a492dfe9cc8fb4f 100644 (file)
@@ -190,6 +190,11 @@ function quiz_upgrade($oldversion) {
         modify_database("","INSERT INTO prefix_log_display VALUES ('quiz', 'update', 'quiz', 'name');");
     }
 
+    if ($oldversion < 2004042501) {
+        include_once("$CFG->dirroot/mod/quiz/lib.php");
+        quiz_refresh_events();
+    }
+
     return true;
 }
 
index 25b6c06ef7b5ddba300c2884fc094c1de199606c..d2b0461c7f7fca137646096447880282190e01ea 100755 (executable)
@@ -5,6 +5,12 @@ function quiz_upgrade($oldversion) {
 // older versions to match current functionality
 
     global $CFG;
+
+    if ($oldversion < 2004042501) {
+        include_once("$CFG->dirroot/mod/quiz/lib.php");
+        quiz_refresh_events();
+    }
+
     return true;
 }
 
index bc6a0488ae62007b2f2c6526dbcf9838c51300a6..8cc3e248a43396f3351f2acd537ea24994b1812a 100644 (file)
@@ -145,6 +145,11 @@ function quiz_upgrade($oldversion) {
         modify_database("","INSERT INTO prefix_log_display VALUES ('quiz', 'update', 'quiz', 'name');");
     }
 
+    if ($oldversion < 2004042501) {
+        include_once("$CFG->dirroot/mod/quiz/lib.php");
+        quiz_refresh_events();
+    }
+
     return true;
 }
 
index 46c75fc9f8b748653c89082d5ce8d41af2348bf5..697b85c21de73022f50b26fa9c0289e08f4e89ec 100644 (file)
@@ -40,6 +40,8 @@ define("QUIZ_PICTURE_MAX_WIDTH",  "600");   // Not currently implemented
 
 define("QUIZ_MAX_NUMBER_ANSWERS", "10");
 
+define("QUIZ_MAX_EVENT_LENGTH", "43200");   // 5 days maximum
+
 /// FUNCTIONS ///////////////////////////////////////////////////////////////////
 
 function quiz_add_instance($quiz) {
@@ -73,7 +75,23 @@ function quiz_add_instance($quiz) {
             }
         }
     }
-    
+
+    $event = NULL;
+    $event->name        = $quiz->name;
+    $event->description = $quiz->intro;
+    $event->courseid    = $quiz->course;
+    $event->groupid     = 0;
+    $event->userid      = 0;
+    $event->modulename  = 'quiz';
+    $event->instance    = $quiz->id;
+    $event->eventtype   = 'start';
+    $event->timestart   = $quiz->timeopen;
+    $event->timeduration = ($quiz->timeclose - $quiz->timeopen);
+    if ($event->timeduration > QUIZ_MAX_EVENT_LENGTH) {  /// Ignore long durations
+        $event->timeduration = 1;
+    }
+    add_event($event);
+
     return $quiz->id;
 }
 
@@ -122,7 +140,22 @@ function quiz_update_instance($quiz) {
             }
         }
     }
-    
+
+    $event = NULL;
+
+    if ($event->id = get_field('event', 'id', 'modulename', 'quiz', 'instance', $quiz->id)) {
+
+        $event->name        = $quiz->name;
+        $event->description = $quiz->intro;
+        $event->timestart   = $quiz->timeopen;
+        $event->timeduration = ($quiz->timeclose - $quiz->timeopen);
+        if ($event->timeduration > QUIZ_MAX_EVENT_LENGTH) {  /// Ignore long durations
+            $event->timeduration = 1;
+        }
+
+        update_event($event);
+    }
+
     return true;
 }
 
@@ -256,6 +289,50 @@ function quiz_get_participants($quizid) {
                                   u.id = a.userid");
 }
 
+function quiz_refresh_events($courseid = 0) {
+// This standard function will check all instances of this module
+// and make sure there are up-to-date events created for each of them.
+// If courseid = 0, then every assignment event in the site is checked, else
+// only assignment events belonging to the course specified are checked.
+// This function is used, in its new format, by restore_refresh_events()
+
+    if ($courseid == 0) {
+        if (! $quizzes = get_records("quiz")) {
+            return true;
+        }
+    } else {
+        if (! $quizzes = get_records("quiz", "course", $courseid)) {
+            return true;
+        }
+    }
+
+    foreach ($quizzes as $quiz) {
+        $event = NULL;
+        $event->name        = addslashes($quiz->name);
+        $event->description = addslashes($quiz->intro);
+        $event->timestart   = $quiz->timeopen;
+        $event->timeduration = ($quiz->timeclose - $quiz->timeopen);
+        if ($event->timeduration > QUIZ_MAX_EVENT_LENGTH) {  /// Ignore long durations
+            $event->timeduration = 1;
+        }
+
+        if ($event->id = get_field('event', 'id', 'modulename', 'quiz', 'instance', $quiz->id)) {
+            update_event($event);
+
+        } else {
+            $event->courseid    = $quiz->course;
+            $event->groupid     = 0;
+            $event->userid      = 0;
+            $event->modulename  = 'quiz';
+            $event->instance    = $quiz->id;
+            $event->eventtype   = 'start';
+
+            add_event($event);
+        }
+    }
+    return true;
+}
+
 /// SQL FUNCTIONS ////////////////////////////////////////////////////////////////////
 
 function quiz_move_questions($category1, $category2) {
index 22163505244e6d08f230d31c8e16f260bfaa75b8..c206d5d7d247a934f7a768f5a6bfa392c007a404 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004022000;   // The (date) version of this module
+$module->version  = 2004042501;   // The (date) version of this module
 $module->requires = 2004013101;   // Requires this Moodle version
 $module->cron     = 0;            // How often should cron check this module (seconds)?