OSDN Git Service

Model: add 'Moderations'
authorhylom <hylom@users.sourceforge.jp>
Thu, 20 Oct 2016 12:35:16 +0000 (21:35 +0900)
committerhylom <hylom@users.sourceforge.jp>
Thu, 20 Oct 2016 12:35:16 +0000 (21:35 +0900)
src/newslash_web/lib/Newslash/Model/Moderations.pm [new file with mode: 0644]

diff --git a/src/newslash_web/lib/Newslash/Model/Moderations.pm b/src/newslash_web/lib/Newslash/Model/Moderations.pm
new file mode 100644 (file)
index 0000000..9fbb4f5
--- /dev/null
@@ -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;