MyBB Community Forums

Full Version: Vote a thread "up" ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was wondering if there is a plugin or mod I can do that would enable users to vote on a thread. When that thread gets to something (like 3 stars) the thread would automatically be moved into a "best" forum.

Reason I ask this is because my freebie/deal website requires something like this. People could vote up deals and they would display on the front page under "best deals" (by being put into the best deals forum).

Hello there,

open ./forumdisplay.php

find
else
{
	$ratingadd = "";
	$lpbackground = "trow1";
	$colspan = "7";
} 

below add

$rates = $db->query("SELECT tid,fid, totalratings FROM ".TABLE_PREFIX."threads");
while($mov = $db->fetch_array($rates))
{
	if($mov['fid'] != x)
	{
		if($mov['totalratings'] == y)
			{
				$db->query("UPDATE ".TABLE_PREFIX."threads SET fid='x' WHERE tid='".$mov['tid']."'");
			}
	}
} 

Replace X by the forum id you want the threads to be moved to.
Replace Y by the amount of rates(stars) before moving that forum.

regards
Ok it works. But it wont show up on the latest page because Its not moving them there.

I can see them under best deals forum..but when I click move and move them to best deals it actually shows up under latest.

I checked the mysql database before I did the move and it was set to "6" after the move it was set to "19".

This is strange.
right after

$rates = $db->query("SELECT tid,fid, totalratings FROM ".TABLE_PREFIX."threads");
while($mov = $db->fetch_array($rates))
{
    if($mov['fid'] != x)
    {
        if($mov['totalratings'] == y)
            {
                $db->query("UPDATE ".TABLE_PREFIX."threads SET fid='x' WHERE tid='".$mov['tid']."'");

put the following code:

$db->query("UPDATE ".TABLE_PREFIX."forums SET lastpost = '{$mov['dateline']}', lastposter = '{$mov['username']}', lastposttid='{$mov['tid']}' WHERE fid='{$mov['fid']}'");

Also, change:
$rates = $db->query("SELECT tid,fid, totalratings FROM ".TABLE_PREFIX."threads");

to

$rates = $db->query("SELECT * FROM ".TABLE_PREFIX."threads");

Cheers
You should just call updateforumcount for both forums, as ratings can be made to a very old thread Smile



Here's a more server-friendly script. If you have hundreds of threads on your forum, you don't need to look at each one Toungue

$move_to_fid = x; // new fid
$ratings_minimum = y; // minimum rating points (something like 15 for 3 5-star ratings)

$rates = $db->query("SELECT tid FROM ".TABLE_PREFIX."threads WHERE fid!='{$move_to_fid}' AND totalratings > '{$ratings_minimum}'");
while($t = $db->fetch_array($rates))
{
	$move[] = $t['tid'];
}
if(is_array($move))
{
	$movelist = implode(',', $move);
	$db->query("UPDATE ".TABLE_PREFIX."threads SET fid='{$move_to_fid}' WHERE tid IN ({$movelist})");
	$db->query("UPDATE ".TABLE_PREFIX."posts SET fid='{$move_to_fid}' WHERE tid IN ({$movelist})");
	updateforumcount($fid);
	updateforumcount($move_to_fid);
	$cache->updateforums();
}