Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

plugin to calculate "points" for users

Quote Reply
plugin to calculate "points" for users
I've seen a lot of sites gives users "points" for contributing to the site, so I decided to work up a plugin to do the same.

It creates a User column called "Points" that stores the value, rather than calculate it each time it's requested.

When this sub is ran, it will recalculate the points the user has. There are admin options to assign how many points for each review and each link.

Obviously I'm a complete perl newbie. My code below works, but I didn't know if there was a more efficient way to do it?

Also, I'd like to have this hooked into the system to run when the site is built, preferably at the beginning of the build so that the new points values can be used through the site. What hook would I need for this?

Thanks!


Code:

sub recalculate {
# -------------------------------------------------------------------
# This subroutine will be called whenever the user clicks on 'Recalculate' in the
# admin menu. Remember, you need to print your own HTTP header; to do so you
# can use:
#
print $IN->header();

print q|Starting...<br>|;

my ($Total_Links_Points,$Total_Reviews_Points,$Total_Points,$total_links,$total_reviews);

my $cfg = Links::Plugins::get_plugin_user_cfg ('Points');
my $ppl = $cfg->{'Links_Points'};
my $ppr = $cfg->{'Reviews_Points'};

my $users_db = $DB->table('Users');
my $reviews_db = $DB->table('Reviews');
my $links_db = $DB->table('Links');

my $sth = $users_db->select('Username');
while (my $hit = $sth->fetchrow_hashref()) {
print $hit->{Username};
print q| <br>|;

$total_links = $links_db->count({ LinkOwner => $hit->{Username} });
$Total_Links_Points = $total_links*$ppl;

$total_reviews = $reviews_db->count({ Review_Owner => $hit->{Username} });
$Total_Reviews_Points = $total_reviews*$ppr;

$Total_Points = $Total_Links_Points+$Total_Reviews_Points;
$users_db->update({ Points => $Total_Points}, { Username => $hit->{Username} });

print $Total_Points;
print q| <br><br>|;
}

print 'Finished';

}

Robert
http://www.pcprofiles.com
PC Profiles and hardware reviews
Subject Author Views Date
Thread plugin to calculate "points" for users Robert_B 3238 Jun 30, 2006, 3:08 PM
Thread Re: [Robert_B] plugin to calculate "points" for users
rascal 3168 Jun 30, 2006, 8:49 PM
Thread Re: [rascal] plugin to calculate "points" for users
Robert_B 3119 Jul 3, 2006, 4:51 PM
Post Re: [Robert_B] plugin to calculate "points" for users
fuzzy logic 3116 Jul 3, 2006, 6:52 PM
Post Re: [Robert_B] plugin to calculate "points" for users
afinlr 3066 Jul 19, 2006, 10:45 AM
Post Re: [Robert_B] plugin to calculate "points" for users
pugdog 3051 Jul 19, 2006, 2:21 PM