From 1a7cdb11b4b1e59456b7ebf20bafc3b75aab9c20 Mon Sep 17 00:00:00 2001 From: vyshane Date: Thu, 5 Oct 2006 03:18:29 +0000 Subject: [PATCH] Merged fixes for MDL-2583 --- mod/forum/lib.php | 8 +++++--- mod/forum/rate.php | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 2e2eb949b9..722b83c56a 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -17,6 +17,8 @@ define('FORUM_TRACKING_OFF', 0); define('FORUM_TRACKING_OPTIONAL', 1); define('FORUM_TRACKING_ON', 2); +define('FORUM_UNSET_POST_RATING', -999); + $FORUM_LAYOUT_MODES = array ( FORUM_MODE_FLATOLDEST => get_string('modeflatoldestfirst', 'forum'), FORUM_MODE_FLATNEWEST => get_string('modeflatnewestfirst', 'forum'), FORUM_MODE_THREADED => get_string('modethreaded', 'forum'), @@ -2389,14 +2391,14 @@ function forum_print_rating_menu($postid, $userid, $scale) { static $strrate; if (!$rating = get_record("forum_ratings", "userid", $userid, "post", $postid)) { - $rating->rating = 0; + $rating->rating = FORUM_UNSET_POST_RATING; } if (empty($strrate)) { $strrate = get_string("rate", "forum"); } - - choose_from_menu($scale, $postid, $rating->rating, "$strrate..."); + $scale = array(FORUM_UNSET_POST_RATING => $strrate.'...') + $scale; + choose_from_menu($scale, $postid, $rating->rating, ''); } /** diff --git a/mod/forum/rate.php b/mod/forum/rate.php index 96a93e4569..bf79444d07 100644 --- a/mod/forum/rate.php +++ b/mod/forum/rate.php @@ -47,7 +47,10 @@ $postid = (int)$postid; $lastpostid = $postid; - if ($oldrating = get_record("forum_ratings", "userid", $USER->id, "post", $postid)) { + if ($rating == FORUM_UNSET_POST_RATING) { + delete_records('forum_ratings', 'post', $postid, 'userid', $USER->id); + + } else if ($oldrating = get_record("forum_ratings", "userid", $USER->id, "post", $postid)) { if ($rating != $oldrating->rating) { $oldrating->rating = $rating; $oldrating->time = time(); @@ -55,7 +58,7 @@ error("Could not update an old rating ($postid = $rating)"); } } - } else if ($rating) { + } else { unset($newrating); $newrating->userid = $USER->id; $newrating->time = time(); @@ -81,4 +84,4 @@ error("This page was not accessed correctly"); } -?> +?> \ No newline at end of file -- 2.39.5