if ($data) {
+ $lastpostid = 0;
+
foreach ((array)$data as $postid => $rating) {
if ($postid == "id") {
continue;
}
+ $lastpostid = $postid;
+
if ($oldrating = get_record("forum_ratings", "userid", $USER->id, "post", $postid)) {
if ($rating != $oldrating->rating) {
$oldrating->rating = $rating;
}
}
}
- if ($post = get_record('forum_posts', 'id', $postid)) {
+ if ($post = get_record('forum_posts', 'id', $lastpostid)) { // To find discussion we're in
if ($returntoview and ($discussion = get_record('forum_discussions', 'id', $post->discussion))) {
redirect("$CFG->wwwroot/mod/forum/view.php?f=$discussion->forum", get_string("ratingssaved", "forum"));
} else {