From: hylom Date: Thu, 20 Oct 2016 12:35:16 +0000 (+0900) Subject: Model: add 'Moderations' X-Git-Tag: v0.1.0~177 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=80ef5fb0dbeb838e14712aab751012e896ee5139;p=newslash%2Fnewslash.git Model: add 'Moderations' --- diff --git a/src/newslash_web/lib/Newslash/Model/Moderations.pm b/src/newslash_web/lib/Newslash/Model/Moderations.pm new file mode 100644 index 00000000..9fbb4f5b --- /dev/null +++ b/src/newslash_web/lib/Newslash/Model/Moderations.pm @@ -0,0 +1,78 @@ +package Newslash::Model::Moderations; +use Newslash::Model::Base -base; + +# parameters + +my $karma_posting_penalty_style = 0; +my $badkarma = -10; +my $goodkarma = 25; +my $comment_minscore = -1; +my $comment_maxscore = 5; + + +#======================================================================== + +=head2 score_for_comment_post(\%user) + +calculate score for comment post + +=over 4 + +=item Parameters + +=over 4 + +=item \%user + +user + +=back + +=item Return value + +HASH of scores + +=back + +=cut + +sub score_for_comment_post { + my ($self, $user) = @_; + + my $users = $self->new_instance_of("Newslash::Model::Users"); + my $user_comment = $users->select(uid => $user->{uid}, 'comments'); + my $user_info = $users->select(uid => $user->{uid}, 'info'); + + my $pts = $user_comment->{defaultpoints}; + my $karma_bonus = 'no'; + my $tweak = 0; + + + if ($user->{login}) { + my $karma = $user_info->{karma}; + if ($karma_posting_penalty_style == 0) { + $pts-- if $karam < 0; + $pts-- if $karma < $badkarma; + } + else { + $tweak-- if $karma < 0; + $tweak-- if $karma < $badkarma; + } + + # check if point is valid range + if ($pts < $comment_minscore) { + $pts = $comment_minscore; + } + elsif ($pts > $comment_maxscore) { + $pts = $comment_maxscore; + } + + if ($pts >= 1 && $karma > $goodkarma) { + $karma_bonus = 'yes'; + } + } + + return {points => $pts, karma_bonus => $karma_bonus, tweak => $tweak}; +} + +1;