MyBB Community Forums

Full Version: Average Thread Ratings on Profile
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello all, 

I did something a little new on a whim. This is somewhat of a niche plugin, but it displays average thread ratings on user profiles. This makes thread ratings a little more useful and provides a general measure of a user's posting quality on their profiles. 

Features:
  • Calculates the user's average thread rating and displays on user profiles. 
  • Full usergroup permissions available. 
  • Minimum threshold setting. This allows you to ONLY display ratings if the user has a certain minimum threshold met for their rating count. (Prevents skewed averages if the user has only been rated a few times. This setting is optional). 
I'm using it and testing it on my live board, but there may be a few bugs and it is not released yet. Please report any issues on github! I'm a little tied up with the Status Manager plugin (coming soon as well), but the release will be ready in the coming weeks. Smile

Admin settings: 
[Image: WchwT.png]

On Profiles: 
[Image: VVoWU.png]


Github Link:   https://github.com/Darth-Apple/Average-Profile-Ratings
More Information:  http://makestation.net/Thread-MyBB-Plugi...le-Ratings

Note: Not released yet. Use at your own risk! See any user profile on my community for a demo in the meantime. Smile

Regards,
-Darth Apple
Don't threads already store thread rating and average rating? You could query that and that way you will be able to check for thread visibility status and forum permissions (edit: thread ratings can be disabled for specific forums also). Compared to the current code I don't think server load will increment.

Nonetheless, nice contribution, this is definitely something I would do on a whim myself.
Also, maybe you can add a helper function for building this for specific forums, I use ratings only in specific forums (reviews, showcase forum, etc) and would be nice to print this in profiles separately Smile
(2020-04-09, 02:09 AM)Omar G. Wrote: [ -> ]Don't threads already store thread rating and average rating? You could query that and that way you will be able to check for thread visibility status and forum permissions. Compared to the current code I don't think server load will increment.

Nonetheless, nice contribution, this is definitely something I would do on a whim myself.

Thank you for the kind words! 

I didn't use the pre-stored thread-based counts and values because I'm collecting an average of all threads. The queries are running very quickly on my board, but it needs to be tested on a larger board to ensure that it's optimized for performance. I'm glad you mentioned thread visibility as well, that's something that I'll add to the list. Smile

Edit: To your second post, do you mean having multiple rating averages displaying separately on profiles? I'm going to add a forum-select feature at some point before release, but that only allows for a single average. I might provide a provision to namespace some of the plugin code so that multiple averages can be added as needed before release. I can definitely see it being useful.
(2020-04-09, 02:12 AM)Darth Apple Wrote: [ -> ]I didn't use the pre-stored thread-based counts and values because I'm collecting an average of all threads.

Won't it be faster since you are already loading the threads table you could simply ditch fetching the threadratings table. You could also do calculation with PHP instead of running two queries.

Maybe it will be faster or not, it was just a idea.

(2020-04-09, 02:12 AM)Darth Apple Wrote: [ -> ]I might provide a provision to namespace some of the plugin code so that multiple averages can be added as needed before release.

I think this is what I meant, some way for building this for specific forums and then displaying in profiles separately. Global setting for core feature would suffice for most.
I've added a new forum selector setting to the ACP. I've also updated the primary function so that it can double as a helper function.
  • Create a new function for each variable/average counter in the profiles.
  • Hook appropriately into member_profile_end. Set the profile variable to global as such.
  • Call $myvariable = average_rating_parse_profile("1,2,3", "average_profile_rating");

The average_rating_parse_profile() function optionally takes two parameters that can override the plugin's defaults. The first of which is a forum list, and the second is a template (useful if you are naming the fields differently for different averages). When these parameters are passed, the function returns the result INSTEAD of evaluating into the standard variable, so this allows the variables to be named as needed as far as the profile template is concerned. Smile

Also, I ran into an unexpected issue. This plugin requires star_rating.css, but this isn't linked with member.php unless this is done manually. I need to link this successfully upon activation of the plugin, and need to also unlink it upon uninstallation without breaking inheritance in any way. I know pluginlibrary has functions for this, but I'd prefer to avoid having to use it for a tiny plugin such as this. Not really sure how to approach this one yet.
(2020-04-09, 03:27 AM)Darth Apple Wrote: [ -> ]Not really sure how to approach this one yet.

You could get insight from MySupport:
https://github.com/MattRogowski/MySuppor....php#L1407

Maybe something along the lines of:
// we can select tid=1 but that will edit the master, could be the easier approach approach
$query = $db->simple_select("themestylesheets", "sid, attachedto", "name = 'star_rating.css' AND tid != '1'"); 

while($stylesheet = $db->fetch_array($query)):
	$update = array(
		"attachedto" => $stylesheet['attachedto'].'|member.php?profile',
		"lastmodified" => TIME_NOW
	);
	$db->update_query("themestylesheets", $update, "sid = '" . intval($stylesheet['sid']) . "'");
endwhile;

$query = $db->simple_select("themes", "tid");
require_once MYBB_ADMIN_DIR . "inc/functions_themes.php";
while($tid = $db->fetch_field($query, "tid"))
{
	update_theme_stylesheet_list($tid);
}
Thank you. I've implemented something based on the code you shared above. Works like a charm.

As it turns out, the most themes inheret this particular stylesheet from the master theme. I had to modify it somewhat to handle this, but it's deactivating and undoing all changes without issues. I've got a few people testing it now. I'll release it in a few days once any remaining issues are ironed out. Smile
(2020-04-11, 02:42 PM)Darth Apple Wrote: [ -> ]most themes inheret this particular stylesheet from the master theme. I had to modify it somewhat to handle this

Yes, editing the master template is an acceptable approach if you ask me.
Nice! I would like to see a new feature - display your rating for every thread where you vote. Now you can see only the overall rating, not yours... Maybe also add a list of users who voted Smile
Pages: 1 2