Index: mod/choice/lib.php =================================================================== --- mod/choice/lib.php (revision 29) +++ mod/choice/lib.php (working copy) @@ -75,6 +75,23 @@ insert_record("choice_options", $option); } } + + if ($choice->timeclose) { + $event = new object(); + $event->name = $choice->name; + $event->description = $choice->text; + $event->courseid = $choice->course; + $event->groupid = 0; + $event->userid = 0; + $event->modulename = 'choice'; + $event->instance = $choice->id; + $event->eventtype = 'close'; + $event->timestart = $choice->timeclose; + $event->timeduration = 0; + + add_event($event); + } + } return $choice->id; } @@ -118,8 +135,40 @@ } } - return update_record('choice', $choice); + if (!update_record('choice', $choice)) { + return false; + } + if ($choice->timeclose) { + $event = new object(); + + if ($event->id = get_field('event', 'id', 'modulename', 'choice', 'instance', $choice->id)) { + + $event->name = $choice->name; + $event->description = $choice->text; + $event->timestart = $choice->timeclose; + + update_event($event); + } else { + $event = new object(); + $event->name = $choice->name; + $event->description = $choice->text; + $event->courseid = $choice->course; + $event->groupid = 0; + $event->userid = 0; + $event->modulename = 'choice'; + $event->instance = $choice->id; + $event->eventtype = 'close'; + $event->timestart = $choice->timeclose; + $event->timeduration = 0; + + add_event($event); + } + } else { + delete_records('event', 'modulename', 'choice', 'instance', $choice->id); + } + + return true; } function choice_show_form($choice, $user, $cm, $allresponses) { @@ -602,6 +651,10 @@ $result = false; } + if (! delete_records('event', 'modulename', 'choice', 'instance', $choice->id)) { + $result = false; + } + return $result; }