package Newslash::Model::Moderations;
use Newslash::Model::Base -base;
+use Data::Dumper;
+
# parameters
my $karma_posting_penalty_style = 0;
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 $user_comment = $users->select(uid => $user->{uid}, target => 'comments');
+ my $user_info = $users->select(uid => $user->{uid}, target => '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 < 0;
$pts-- if $karma < $badkarma;
}
else {
sub undo_moderation {
my ($self, $type, $id, $uid) = @_;
# type = sid or stoid or discussion_id
+ my $sid; # sid is discussion_id!
+
+ if ($type eq 'sid'
+ || $type eq 'stoid') {
+ my $stories = $self->new_instance_of("Newslash::Model::Stories");
+ my $story = $stories->select($type => $id);
+ $sid = $story->{discussion};
+ }
+ elsif ($type eq 'discussion_id') {
+ $sid = $id;
+ }
+ else {
+ return;
+ }
my $dbh = $self->connect_db({AutoCommit => 0,});
my $sql = <<"EOSQL";
SELECT id, cid, val, active, cuid, reason FROM moderatorlog
- WHERE sid = ? AND uid = ?
+ WHERE ? = ? AND uid = ?
EOSQL
my $sth = $dbh->prepare($sql);
- $sth->execute($sid, $uid);
+ $sth->execute($type, $id, $uid);
my $target = $sth->fetchall_arrayref({});
for my $mod (@$target) {
next if !$mod->{active};
+ my $cid = $mod->{cid};
$self->removeModTags($uid, $cid);
sub removeModTags {
my($self, $uid, $cid) = @_;
- my $globjid = $self->new_instance_of("Newslash::Model::Globjids");
+ my $globjids = $self->new_instance_of("Newslash::Model::Globjids");
my $comment_globjid = $globjids->getGlobjidFromTargetIfExists('comments', $cid);
if ($comment_globjid) {
my $rs = $sth->fetchall_hashref('id');
$dbh->disconnect;
- if (!%rs) {
+ if (!%$rs) {
return;
}
#my $table_cache = "_reasons_cache";