Permalink
Browse files

Fixes for MDL-2583

  • Loading branch information...
1 parent 14a60a0 commit 718647bcb1b9b416b8280a578ab88f43fb4323f5 vyshane committed Oct 5, 2006
Showing with 11 additions and 6 deletions.
  1. +5 −3 mod/forum/lib.php
  2. +6 −3 mod/forum/rate.php
View
@@ -17,6 +17,8 @@
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'),
@@ -2247,14 +2249,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, '');
}
function forum_print_mode_form($discussion, $mode) {
View
@@ -39,15 +39,18 @@
$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();
if (! update_record("forum_ratings", $oldrating)) {
error("Could not update an old rating ($postid = $rating)");
}
}
- } else if ($rating) {
+ } else {
unset($newrating);
$newrating->userid = $USER->id;
$newrating->time = time();
@@ -73,4 +76,4 @@
error("This page was not accessed correctly");
}
-?>
+?>

0 comments on commit 718647b

Please sign in to comment.