MyBB Community Forums

Full Version: Order posts by "best answer"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm developing my board on MyBB 1.6.8 and I've installed MySupport 0.4.2 by MattRogowski.

All is working fine, but I'd like to build up with the help of XThreads and Pluginlibrary some forums with a stackoverflow.com-style: the main thing I would like to have is "order by: votes, best answer, normal" buttons and "best answer" set as default, so if an user post his question and then he marks an answer as best, it will be put on top, after first message. It's a intelligent way of building up support forums and I hope you will help me obtaining this target.
Hi Shade,
I clicked on your thread title expecting to say:
If you know some coding, then XThreads would be a good starting point.

Making a stackoverflow.com-style forum is a great idea.
This thread might be better off in requests or dev sub forum...
Hi Shade

If you are already using XThreads then you may have seen the ingenious XThreads powered support set up by RateU on MyBBHacks.

I would suggest having a look at how he set that up as a start point.
I did, leefish, and I know XThreads has a custom filtering system, but only for forumdisplay and not for showthread (messages), which is what I'm trying to achieve. Filtering by best answer... is that too much difficult?
aha - so you want to order the posts by the answer rating?

Hmmm. You should ask RateU, I wonder if it can be done. I bet it can you know.

Must sleep now, but I will ponder on it.
Not really, my main target is to integrate a filtering system with MySupport's best answer feature, so the best answer will be put right after first one and the stackoverflow.com-style idea will be done.

Ok then, I noticed the title of this thread was wrong. My aim is to order posts, not discussions, by votes, "MySupport best answer" and normal view (first to last), and put those 3 options together with 3 buttons in showthread.

Who can help me?
Bump!
Are you planning to avoid core file edits?

#
line 971 in 'showthread.php' looks like a good place to start

		// Get the actual posts from the database here.
		$posts = '';
		$query = $db->query("
			SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
			FROM ".TABLE_PREFIX."posts p
			LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
			LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
			LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
			WHERE $pids
			ORDER BY p.dateline
		");
		while($post = $db->fetch_array($query))
		{
			if($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0)
			{
				$post['visible'] = 0;
			}
			$posts .= build_postbit($post);
			$post = '';
		}
		$plugins->run_hooks("showthread_linear");


##
The plugin hook comes shortly after the posts are sorted BY dateline, so it looks like a choice between editing a core file, or having the plugin re-run the query,
or...

(another less than perfect option)
Start here:
$plugins->run_hooks("showthread_start"); (line 396)
...and have the plugin contain a large part of 'showthread.php'


###
It can be done if someone has the time...
Adding onto seekers suggestion, as you already have XThreads installed - try looking at how ZingaBurga's control object function makes it possible to "edit" an existing query and piggy back the query in a plugin where the query only runs in forum X. No extra queries.
Since I'm using Patches + Pluginlibrary plugins that help me organizing all core edits within ACP and a single .xml file, core editing isn't a problem, I can do it if it's necessary.

As ZingaBurga said, the marked solution would be 'stucked' below the first post with all other posts ordered normally. So SORTBY p.dateline wouldn't be changed.

The hardest thing I'm facing off is the query that I have to modify as seeker said: MySupport adds bestanswer column into ".TABLE_PREFIX."threads instead of ".TABLE_PREFIX."posts, which is actually the table the query is searching into.
Pages: 1 2