From: moodler Date: Wed, 28 Apr 2004 02:56:40 +0000 (+0000) Subject: Support for events. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d2f308c091dc7d5ec77a0348a7c1c2f93d6b3daf;p=moodle.git Support for events. Ouch - I thought I'd checked this in days ago --- diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index 145987b7ca..0d5ae9bc20 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -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; } diff --git a/mod/quiz/db/oci8po.php b/mod/quiz/db/oci8po.php index 25b6c06ef7..d2b0461c7f 100755 --- a/mod/quiz/db/oci8po.php +++ b/mod/quiz/db/oci8po.php @@ -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; } diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index bc6a0488ae..8cc3e248a4 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -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; } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 46c75fc9f8..697b85c21d 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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) { diff --git a/mod/quiz/version.php b/mod/quiz/version.php index 2216350524..c206d5d7d2 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -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)?