Skip to content

Commit

Permalink
Support for events.
Browse files Browse the repository at this point in the history
Ouch - I thought I'd checked this in days ago
  • Loading branch information
moodler committed Apr 28, 2004
1 parent 22c8200 commit d2f308c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
5 changes: 5 additions & 0 deletions mod/quiz/db/mysql.php
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions mod/quiz/db/oci8po.php
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions mod/quiz/db/postgres7.php
Expand Up @@ -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;
}

Expand Down
81 changes: 79 additions & 2 deletions mod/quiz/lib.php
Expand Up @@ -40,6 +40,8 @@

define("QUIZ_MAX_NUMBER_ANSWERS", "10");

define("QUIZ_MAX_EVENT_LENGTH", "43200"); // 5 days maximum

/// FUNCTIONS ///////////////////////////////////////////////////////////////////

function quiz_add_instance($quiz) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/version.php
Expand Up @@ -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)?
Expand Down

0 comments on commit d2f308c

Please sign in to comment.