Quizzes with long periods (longer than 5 days) are now handled
in the calendar as two separate events ... one for open and one for close bug 1402
This commit is contained in:
@@ -190,7 +190,7 @@ function quiz_upgrade($oldversion) {
|
||||
modify_database("","INSERT INTO prefix_log_display VALUES ('quiz', 'update', 'quiz', 'name');");
|
||||
}
|
||||
|
||||
if ($oldversion < 2004042501) {
|
||||
if ($oldversion < 2004051700) {
|
||||
include_once("$CFG->dirroot/mod/quiz/lib.php");
|
||||
quiz_refresh_events();
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ function quiz_upgrade($oldversion) {
|
||||
modify_database("","INSERT INTO prefix_log_display VALUES ('quiz', 'update', 'quiz', 'name');");
|
||||
}
|
||||
|
||||
if ($oldversion < 2004042501) {
|
||||
if ($oldversion < 2004051700) {
|
||||
include_once("$CFG->dirroot/mod/quiz/lib.php");
|
||||
quiz_refresh_events();
|
||||
}
|
||||
|
||||
+111
-24
@@ -40,7 +40,7 @@ define("QUIZ_PICTURE_MAX_WIDTH", "600"); // Not currently implemented
|
||||
|
||||
define("QUIZ_MAX_NUMBER_ANSWERS", "10");
|
||||
|
||||
define("QUIZ_MAX_EVENT_LENGTH", "43200"); // 5 days maximum
|
||||
define("QUIZ_MAX_EVENT_LENGTH", "432000"); // 5 days maximum
|
||||
|
||||
/// FUNCTIONS ///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -88,12 +88,24 @@ function quiz_add_instance($quiz) {
|
||||
$event->userid = 0;
|
||||
$event->modulename = 'quiz';
|
||||
$event->instance = $quiz->id;
|
||||
$event->eventtype = 'start';
|
||||
$event->eventtype = 'open';
|
||||
$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->timeduration > QUIZ_MAX_EVENT_LENGTH) { /// Long durations create two events
|
||||
$event2 = $event;
|
||||
|
||||
$event->name .= ' ('.get_string('quizopens', 'quiz').')';
|
||||
$event->timeduration = 0;
|
||||
|
||||
$event2->timestart = $quiz->timeclose;
|
||||
$event2->eventtype = 'close';
|
||||
$event2->timeduration = 0;
|
||||
$event2->name .= ' ('.get_string('quizcloses', 'quiz').')';
|
||||
|
||||
add_event($event2);
|
||||
}
|
||||
|
||||
add_event($event);
|
||||
|
||||
return $quiz->id;
|
||||
@@ -149,16 +161,53 @@ function quiz_update_instance($quiz) {
|
||||
}
|
||||
}
|
||||
|
||||
$event = NULL;
|
||||
if ($events = get_records_select('event', "modulename = 'quiz' AND instance = '$quiz->id' ORDER BY timestart")) {
|
||||
|
||||
if ($event->id = get_field('event', 'id', 'modulename', 'quiz', 'instance', $quiz->id)) {
|
||||
$event = array_shift($events);
|
||||
if (!empty($events)) {
|
||||
$event2old = array_shift($events);
|
||||
if (!empty($events)) {
|
||||
foreach ($events as $badevent) {
|
||||
delete_records('event', 'id', $badevent->id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$event2old = 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->visible = instance_is_visible('quiz', $quiz->id);
|
||||
$event->timestart = $quiz->timeopen;
|
||||
$event->eventtype = 'open';
|
||||
$event->timeduration = ($quiz->timeclose - $quiz->timeopen);
|
||||
if ($event->timeduration > QUIZ_MAX_EVENT_LENGTH) { /// Ignore long durations
|
||||
$event->timeduration = 1;
|
||||
|
||||
if ($event->timeduration > QUIZ_MAX_EVENT_LENGTH) { /// Set up two events
|
||||
|
||||
$event2 = $event;
|
||||
|
||||
$event->name = $quiz->name.' ('.get_string('quizopens', 'quiz').')';
|
||||
$event->timeduration = 0;
|
||||
|
||||
$event2->name = $quiz->name.' ('.get_string('quizcloses', 'quiz').')';
|
||||
$event2->timestart = $quiz->timeclose;
|
||||
$event2->eventtype = 'close';
|
||||
$event2->timeduration = 0;
|
||||
|
||||
if (empty($event2old->id)) {
|
||||
unset($event2->id);
|
||||
add_event($event2);
|
||||
} else {
|
||||
$event2->id = $event2old->id;
|
||||
update_event($event2);
|
||||
}
|
||||
} else if (!empty($event2->id)) {
|
||||
delete_event($event2->id);
|
||||
}
|
||||
|
||||
update_event($event);
|
||||
@@ -203,6 +252,10 @@ function quiz_delete_instance($id) {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if (! delete_records('event', 'modulename', 'quiz', 'instance', $quiz->id)) {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -300,8 +353,8 @@ function quiz_get_participants($quizid) {
|
||||
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.
|
||||
// If courseid = 0, then every quiz event in the site is checked, else
|
||||
// only quiz events belonging to the course specified are checked.
|
||||
// This function is used, in its new format, by restore_refresh_events()
|
||||
|
||||
if ($courseid == 0) {
|
||||
@@ -317,28 +370,62 @@ function quiz_refresh_events($courseid = 0) {
|
||||
|
||||
foreach ($quizzes as $quiz) {
|
||||
$event = NULL;
|
||||
$event2 = NULL;
|
||||
$event2old = NULL;
|
||||
|
||||
if ($events = get_records_select('event', "modulename = 'quiz' AND instance = '$quiz->id' ORDER BY timestart")) {
|
||||
$event = array_shift($events);
|
||||
if (!empty($events)) {
|
||||
$event2old = array_shift($events);
|
||||
if (!empty($events)) {
|
||||
foreach ($events as $badevent) {
|
||||
delete_records('event', 'id', $badevent->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$event->name = addslashes($quiz->name);
|
||||
$event->description = addslashes($quiz->intro);
|
||||
$event->courseid = $quiz->course;
|
||||
$event->groupid = 0;
|
||||
$event->userid = 0;
|
||||
$event->modulename = 'quiz';
|
||||
$event->instance = $quiz->id;
|
||||
$event->visible = instance_is_visible('quiz', $quiz->id);
|
||||
$event->timestart = $quiz->timeopen;
|
||||
$event->eventtype = 'open';
|
||||
$event->timeduration = ($quiz->timeclose - $quiz->timeopen);
|
||||
if ($event->timeduration > QUIZ_MAX_EVENT_LENGTH) { /// Ignore long durations
|
||||
$event->timeduration = 1;
|
||||
|
||||
if ($event->timeduration > QUIZ_MAX_EVENT_LENGTH) { /// Set up two events
|
||||
|
||||
$event2 = $event;
|
||||
|
||||
$event->name = addslashes($quiz->name).' ('.get_string('quizopens', 'quiz').')';
|
||||
$event->timeduration = 0;
|
||||
|
||||
$event2->name = addslashes($quiz->name).' ('.get_string('quizcloses', 'quiz').')';
|
||||
$event2->timestart = $quiz->timeclose;
|
||||
$event2->eventtype = 'close';
|
||||
$event2->timeduration = 0;
|
||||
|
||||
if (empty($event2old->id)) {
|
||||
unset($event2->id);
|
||||
add_event($event2);
|
||||
} else {
|
||||
$event2->id = $event2old->id;
|
||||
update_event($event2);
|
||||
}
|
||||
} else if (!empty($event2->id)) {
|
||||
delete_event($event2->id);
|
||||
}
|
||||
|
||||
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';
|
||||
$event->visible = get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $quiz->id);
|
||||
|
||||
if (empty($event->id)) {
|
||||
add_event($event);
|
||||
} else {
|
||||
update_event($event);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$module->version = 2004042501; // The (date) version of this module
|
||||
$module->version = 2004051700; // The (date) version of this module
|
||||
$module->requires = 2004013101; // Requires this Moodle version
|
||||
$module->cron = 0; // How often should cron check this module (seconds)?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user