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'),
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, '');
}
/**
$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();
error("Could not update an old rating ($postid = $rating)");
}
}
- } else if ($rating) {
+ } else {
unset($newrating);
$newrating->userid = $USER->id;
$newrating->time = time();
error("This page was not accessed correctly");
}
-?>
+?>
\ No newline at end of file