Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-29662 quiz overrides: update dates during course reset.

Also, fix duplicate SQL clause in similar code in lib,
and fix error when saving overrides.
  • Loading branch information...
commit c8f9a0b63a9c21039270bc3e2e752c2aa040ccce 1 parent bac15e5
@timhunt timhunt authored
Showing with 18 additions and 2 deletions.
  1. +1 −1  lib/moodlelib.php
  2. +17 −1 mod/quiz/lib.php
View
2  lib/moodlelib.php
@@ -4767,7 +4767,7 @@ function shift_course_mod_dates($modname, $fields, $timeshift, $courseid) {
foreach ($fields as $field) {
$updatesql = "UPDATE {".$modname."}
SET $field = $field + ?
- WHERE course=? AND $field<>0 AND $field<>0";
+ WHERE course=? AND $field<>0";
$return = $DB->execute($updatesql, array($timeshift, $courseid)) && $return;
}
View
18 mod/quiz/lib.php
@@ -1150,8 +1150,14 @@ function quiz_update_events($quiz, $override = null) {
$addopen = empty($current->id) || !empty($current->timeopen);
$addclose = empty($current->id) || !empty($current->timeclose);
+ if (!empty($quiz->coursemodule)) {
+ $cmid = $quiz->coursemodule;
+ } else {
+ $cmid = get_coursemodule_from_instance('quiz', $quiz->id, $courseid)->id;
+ }
+
$event = new stdClass();
- $event->description = format_module_intro('quiz', $quiz, $quiz->coursemodule);
+ $event->description = format_module_intro('quiz', $quiz, $cmid);
// Events module won't show user events when the courseid is nonzero.
$event->courseid = ($userid) ? 0 : $quiz->course;
$event->groupid = $groupid;
@@ -1341,8 +1347,18 @@ function quiz_reset_userdata($data) {
// Updating dates - shift may be negative too.
if ($data->timeshift) {
+ $DB->execute("UPDATE {quiz_overrides}
+ SET timeopen = timeopen + ?
+ WHERE quiz IN (SELECT id FROM {quiz} WHERE course = ?)
+ AND timeopen <> 0", array($data->timeshift, $data->courseid));
+ $DB->execute("UPDATE {quiz_overrides}
+ SET timeclose = timeclose + ?
+ WHERE quiz IN (SELECT id FROM {quiz} WHERE course = ?)
+ AND timeclose <> 0", array($data->timeshift, $data->courseid));
+
shift_course_mod_dates('quiz', array('timeopen', 'timeclose'),
$data->timeshift, $data->courseid);
+
$status[] = array(
'component' => $componentstr,
'item' => get_string('openclosedatesupdated', 'quiz'),
Please sign in to comment.
Something went wrong with that request. Please try again.