]> git.mjollnir.org Git - moodle.git/commitdiff
Merged fixes for MDL-2583
authorvyshane <vyshane>
Thu, 5 Oct 2006 03:18:29 +0000 (03:18 +0000)
committervyshane <vyshane>
Thu, 5 Oct 2006 03:18:29 +0000 (03:18 +0000)
mod/forum/lib.php
mod/forum/rate.php

index 2e2eb949b97e7381677ada6e114b1881d615f2dd..722b83c56ad31c14262e0612bd0c561550b0b135 100644 (file)
@@ -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, '');
 }
 
 /**
index 96a93e45690c7111bc0a03cca50cacf0fc902442..bf79444d0774e5d92fd186a5ba14923f61818c6b 100644 (file)
             $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