MyBB Community Forums

Full Version: Refresh page after giving thread rating
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear all,

I know that the "thread rating" feature of MyBB is not very popular, but in my own board, we use it very much (because we have a forum in which each thread is one ratable movie).

What I would really like to change is that after clicking your desired star rating, the page gets refreshed so that users can directly see the effects of their rating. (Right now, there's a small green AJAX popup that the rating has been saved, but the visible star rating only changes after a page refresh.)

Could anybody help me with this?

I figure that I need to edit the file "ratethread.php", especially somewhere after here
$plugins->run_hooks("ratethread_process");

$db->write_query("
UPDATE ".TABLE_PREFIX."threads
SET numratings=numratings+1, totalratings=totalratings+'{$mybb->input['rating']}'
WHERE tid='{$tid}'
");

I've tried adding a PHP page refresh after this code, but it didn't work. (I'm no PHP professional, though.)
Thanks so much in advance!
You don’t need to refresh the page, the styling on the rating stars is already updated to reflect the current rating after you click it. If yours isn’t doing that there must be something wrong with your theme, it’s been a feature since 1.4 came out over 14 years ago.
First of all: Thanks for your reply, Matt. I think it's incredible how you address pretty much every request and thread on this forum (even the many ones that are written less politely).

Regarding your answer: Oh, I see! I didn't know this, and that might have led me to formulate my question suboptimally. Let me try again Smile

I have already done some modifications to the forumdisplay_thread_rating template...so that there's a bit more information shown in the thread rating column:
[attachment=45701]

As you can see, I also display the total number of ratings on the left, as well as the user's own rating ("Meine Wertung: ") at the bottom. Furthermore, I have slightly modified the star CSS so that even decimal values are depicted as fragmented stars. All of these things are not updated when clicking the star rating.

As such, I would really love to find some simple way of adding a page refresh into the function in order to update all of this data immediately.

Would anyone care to help me out? I would really appreciate it Smile
Oh, you’re welcome Smile Glad to be of any help.

So the best way to do this would probably be some custom JavaScript. You can’t “refresh” a page as such in PHP as it’s server side, it would have to be a redirect, but then you’d need to know the page number to redirect to. Instead, it should be possible to extend the JavaScript to dynamically update the HTML. Do you have a URL you can share to see the markup?
Sure thing, I really appreciate your assistance, Matt Smile
[See next comment for quick'n'dirty solution.]
In case anybody else ever needs this (I doubt it), I managed to create the desired behavior (a page refresh after clicking a thread rating) by exchanging some code at the bottom of rating.js with a single line:

Quote: rating_added: function(request, element_id)
{
var json = JSON.parse(request.responseText);
if(json.hasOwnProperty("errors"))
{
$.each(json.errors, function(i, error)
{
$.jGrowl(lang.ratings_update_error + ' ' + error, {theme:'jgrowl_error'});
});
}
else if(json.hasOwnProperty("success"))
{
window.location.reload();
}

}

It's not elegant but it does the trick for my forum Smile