From f09b00ffc958f2eb47cd346cc67756b16eddc364 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 24 Jun 2002 00:44:22 +0000 Subject: [PATCH] Adding karma. --- docs/upgrades/upgrade_4.0.4-4.1.0.sql | 7 +++++++ lib/WebGUI/User.pm | 2 +- lib/WebGUI/Wobject/Poll.pm | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/upgrades/upgrade_4.0.4-4.1.0.sql b/docs/upgrades/upgrade_4.0.4-4.1.0.sql index dd773055b..d30ab0c54 100644 --- a/docs/upgrades/upgrade_4.0.4-4.1.0.sql +++ b/docs/upgrades/upgrade_4.0.4-4.1.0.sql @@ -14,5 +14,12 @@ INSERT INTO international VALUES (539,'WebGUI','English','Enable Karma?'); INSERT INTO international VALUES (540,'WebGUI','English','Karma Per Login'); INSERT INTO settings VALUES ('useKarma','0'); INSERT INTO settings VALUES ('karmaPerLogin','1'); +alter table Poll add column karmaPerVote int not null default 0; +INSERT INTO international VALUES (20,'Poll','English','Karma Per Vote'); +INSERT INTO international VALUES (541,'WebGUI','English','Karma Per Post'); +INSERT INTO international VALUES (30,'UserSubmission','English','Karma Per Submission'); +alter table UserSubmission add column karmaPerSubmission int not null default 0; +alter table UserSubmission add column karmaPerPost int not null default 0; +alter table MessageBoard add column karmaPerPost int not null default 0; diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 22f3897ee..2b9931af7 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -239,7 +239,7 @@ sub identifier { sub karma { if (defined $_[1] && defined $_[2] && defined $_[3]) { WebGUI::SQL->write("update users set karma=karma+$_[1] where userId=".$_[0]->userId); - WebGUI::SQL->write("insert into karmaLog values (".$_[0]->userId,$_[1].",".quote($_[2]).",".quote($_[3]).")"); + WebGUI::SQL->write("insert into karmaLog values (".$_[0]->userId.",$_[1],".quote($_[2]).",".quote($_[3]).")"); } return $_[0]->{_user}{karma}; } diff --git a/lib/WebGUI/Wobject/Poll.pm b/lib/WebGUI/Wobject/Poll.pm index 077463b82..9b672364a 100644 --- a/lib/WebGUI/Wobject/Poll.pm +++ b/lib/WebGUI/Wobject/Poll.pm @@ -20,6 +20,7 @@ use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; use WebGUI::URL; +use WebGUI::User; use WebGUI::Utility; use WebGUI::Wobject; @@ -38,6 +39,7 @@ sub duplicate { graphWidth=>$_[0]->get("graphWidth"), voteGroup=>$_[0]->get("voteGroup"), question=>$_[0]->get("question"), + karmaPerVote=>$_[0]->get("karmaPerVote"), a1=>$_[0]->get("a1"), a2=>$_[0]->get("a2"), a3=>$_[0]->get("a3"), @@ -83,7 +85,7 @@ sub purge { #------------------------------------------------------------------- sub set { - $_[0]->SUPER::set($_[1],[qw(active graphWidth voteGroup question a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20)]); + $_[0]->SUPER::set($_[1],[qw(active karmaPerVote graphWidth voteGroup question a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20)]); } #------------------------------------------------------------------- @@ -117,6 +119,11 @@ sub www_edit { $f = WebGUI::HTMLForm->new; $f->yesNo("active",WebGUI::International::get(3,$namespace),$active); $f->group("voteGroup",WebGUI::International::get(4,$namespace),[$voteGroup]); + if ($session{setting}{useKarma}) { + $f->integer("karmaPerVote",WebGUI::International::get(20,$namespace),$_[0]->get("karmaPerVote")); + } else { + $f->hidden("karmaPerVote",$_[0]->get("karmaPerVote")); + } $f->integer("graphWidth",WebGUI::International::get(5,$namespace),$graphWidth); $f->text("question",WebGUI::International::get(6,$namespace),$_[0]->get("question")); $f->textarea("answers",WebGUI::International::get(7,$namespace).'
'.WebGUI::International::get(8,$namespace).'
',$answers); @@ -141,6 +148,7 @@ sub www_editSave { for ($i=1; $i<=20; $i++) { $property->{'a'.$i} = $answer[($i-1)]; } + $property->{karmaPerVote} = $session{form}{karmaPerVote}; $property->{voteGroup} = $session{form}{voteGroup}; $property->{graphWidth} = $session{form}{graphWidth}; $property->{active} = $session{form}{active}; @@ -214,11 +222,15 @@ sub www_view { #------------------------------------------------------------------- sub www_vote { - my ($hasVoted); + my ($hasVoted, $u); ($hasVoted) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where wobjectId=".$_[0]->get("wobjectId")." and ((userId=$session{user}{userId} and userId<>1) or (userId=1 and ipAddress='$session{env}{REMOTE_ADDR}'))"); if ($session{form}{answer} ne "" && WebGUI::Privilege::isInGroup($_[0]->get("voteGroup"),$session{user}{userId}) && !($hasVoted)) { WebGUI::SQL->write("insert into Poll_answer values (".$_[0]->get("wobjectId").", '$session{form}{answer}', $session{user}{userId}, '$session{env}{REMOTE_ADDR}')"); + if ($session{setting}{useKarma}) { + $u = WebGUI::User->new($session{user}{userId}); + $u->karma($_[0]->get("karmaPerVote"),$namespace." (".$_[0]->get("wobjectId").")","Voted on this poll."); + } } return ""; }