MyBB Community Forums

Full Version: Help in code change/plugin to search best rated topics
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

I have asked before if there was something, code modification or plugin, to show the best rated topics in a certain period (day, week, month,always).

As I haven't got any answer, I am trying to do it myself. I thought in adding a new type of search, to show the best rated threads.

I am also trying to modify a plugin to instead of showing the last threads, to show the best rated threads.

First I wanted to ask what would be best to use to order the threads. I thought in getting the numratings*totalratings. What do you think?

- Search ordered by rate

I tried to add a new type of search, so I found the search.php and created a section (copied from the "getDaily" bit):

Quote:elseif($mybb->input['action'] == "getdailySortedbyRating")
{
...
$plugins->run_hooks("search_do_search_process");
...
redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
}

I need now to add sorting by a new field of the select that I need to add: numratings*totalratings
I couldn't find a way to add sorting , I saw there is a ("querycache" => $db->escape_string($where_sql),), but I couldn't find a way to add a new field and add sorting to it. Even if I wouldn't add a new field I could sort by "totalratings". How can I do that?

- Modifying plugin

This other approach I was successful, but not really the way I would like it to be. I changed the prostats plugin, which I can gladly give back the changes. This now shows the best ranked threads of the last 7 days.

I think Im using the versioin 1.7 of this plugin.

I changed the "ps_GetNewestPosts" function to filter and sort the posts shown on that column.

Quote:$query = $db->query ("

SELECT t.subject,t.username,t.uid,t.tid,t.fid,t.lastpost,t.lastposter,t.lastposteruid,t.replies,tr.uid AS truid,tr.dateline,f.name ,TRUNCATE(t.totalratings/t.numratings*2+t.numratings/8+tyl_tnumtyls/2,2) ranking

FROM ".TABLE_PREFIX."threads t

LEFT JOIN ".TABLE_PREFIX."threadsread tr ON (tr.tid=t.tid AND tr.uid='".$mybb->user['uid']."')

LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid = t.fid)

WHERE t.visible='1'

".ps_GetUnviewable("t")."

AND t.closed NOT LIKE 'moved|%'

AND t.dateline >=UNIX_TIMESTAMP()-(86400*7)

ORDER BY ranking DESC

LIMIT 0,".$NumOfRows);



$newestposts_cols_name = "";

$newestposts_cols = "";

$colspan = 0;

$active_cells = "";


So Im using the rating total divided by the number of ratings, pluign a factor of the number of ratings (to break the ties due) and also putting a factor of the number of thanks received for that post. It worked well, although not really the layout I wanted. TO check it out, go to :
http://forum.antinovaordemmundial.com/ and scroll down to "Tópicos mais bem classificados da semana".

I also took out a few fields (irrelevant for this scope) to open space for the ratings.


What is the plan

If someone could help me in getting this idea into a plugin, this would be fantastic. So what is the idea?

To have a plugin that will show a box on the main page with different sections (vertical or horizontal) each one with the best ranked threads of the day / of the week / of the month / of all times.

Each one of this will show the title, date of creation and author, and maybe some 100 chars extract of the first post of the thread.

I know this would be a bit database intensive, so the idea would be to cache the html at some global place, and update it every 1 hour (refresh time configurable). This way we would make sure to not overload the server Smile

The plugin would check for the "thanks/like system" plugin, and would use it or not if present.

If you like the idea vote for it to be implemented directly on mybb:
http://ideas.mybb.com/idea/show-best-rat...-main-page