From f2b2832524ad0998376ec9fcd3e490897c111985 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 28 Feb 2006 17:28:44 +0000 Subject: [PATCH] added a karma ranking system to cs threads for conducting popularity contests --- docs/changelog/6.x.x.txt | 4 ++ docs/upgrades/upgrade_6.8.7-6.99.0.pl | 9 ++++ lib/WebGUI/Asset/Post.pm | 5 ++ lib/WebGUI/Asset/Post/Thread.pm | 53 ++++++++++++++++++- lib/WebGUI/Asset/Wobject/Collaboration.pm | 15 ++++++ lib/WebGUI/Help/Asset_Collaboration.pm | 5 ++ .../i18n/English/Asset_Collaboration.pm | 26 +++++++-- lib/WebGUI/i18n/English/Asset_Post.pm | 4 ++ lib/WebGUI/i18n/English/Asset_Thread.pm | 18 ++++++- 9 files changed, 133 insertions(+), 6 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index d5fc496fc..1a9fca980 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -42,12 +42,16 @@ - [ 1433525 ] 6.9: Compilation errors - base36 removed from Utility.t because it no longer exists in WebGUI::Utility.pm - Add tests that verify the integrity of the WebGUI Database. + - Added a karma ranking system to CS threads for conducting popularity + contests. 6.8.8 - fix [ 1437186 ] 6.8.7 deploy DataForm package does not copy fields - fix [ 1437563 ] Data picker intermittent for Admin - fix broken link to top of CS Assets configured as FAQs - fix [ 1437977 ] richeditor selectbox options not versioned, trashed appear + - fixed a bug in the rich editor where the page chooser didn't have scroll + bars 6.8.7 - fix [ 1431098 ] op=becomeUser can become non-existent userIds diff --git a/docs/upgrades/upgrade_6.8.7-6.99.0.pl b/docs/upgrades/upgrade_6.8.7-6.99.0.pl index d496890e5..4b21a6ff2 100644 --- a/docs/upgrades/upgrade_6.8.7-6.99.0.pl +++ b/docs/upgrades/upgrade_6.8.7-6.99.0.pl @@ -39,6 +39,15 @@ addDatabaseCache(); finish($session); # this line required +#------------------------------------------------- +sub addCsPopularityContest { + print "\tAdding collaboration system popularity system based upon karma.\n"; + $session->db->write("alter table Collaboration add column defaultKarmaScale integer not null default 1"); + $session->db->write("alter table Thread add column karma integer not null default 0"); + $session->db->write("alter table Thread add column karmaScale integer not null default 1"); + $session->db->write("alter table Thread add column karmaRank decimal(5,6) not null default 0"); +} + #------------------------------------------------- sub addDatabaseCache { print "\tAdding database cache.\n"; diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index f8d6a5da0..e7cbe0fce 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -1133,6 +1133,11 @@ sub www_edit { $var{'form.submit'} = WebGUI::Form::submit($self->session, { extras=>"onclick=\"this.value='".$i18n->get(452)."'; this.form.func.value='editSave'; this.form.submit();return false;\"" }); + $var{'karmaScale.form'} = WebGUI::Form::integer($self->session, { + name=>"karmaScale", + value=>$self->getValue("karmaScale"), + defaultValue=>1 + }); $var{'form.preview'} = WebGUI::Form::submit($self->session, { value=>$i18n->get("preview","Asset_Collaboration") }); diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index 4540072c9..7c7392bcf 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -108,8 +108,23 @@ sub definition { }, lastPostDate => { noFormPost=>1, - fieldType=>"hidden", + fieldType=>"dateTime", defaultValue=>undef + }, + karma => { + noFormPost=>1, + fieldType=>"integer", + defaultValue=>0 + }, + karmaRank => { + noFormPost=>1, + fieldType=>"hidden", + defaultValue=>0 + }, + karmaScale => { + noFormPost=>1, + fieldType=>"integer", + defaultValue=>1 } }, }); @@ -489,6 +504,10 @@ sub processPropertiesFromFormPost { if ($self->get("subscriptionGroupId") eq "") { $self->createSubscriptionGroup; } + if ($self->getParent->canModerate) { + my $karmaScale = $self->session->form("karmaScale","integer") || 1; + $self->update({karmaScale=>$karmaScale, karmaRank=>$self->get("karma")/$karmaScale}); + } } @@ -730,6 +749,18 @@ sub view { $var->{'lock.url'} = $self->getLockUrl; $var->{'unlock.url'} = $self->getUnlockUrl; + $var->{'transfer.karma.form'} = WebGUI::Form::formHeader($self->session, {action=>$self->getUrl}) + .WebGUI::Form::hidden($self->session, { + name=>"func", + value=>"transferKarma" + }) + .WebGUI::Form::integer($self->session, { + name=>"karma", + value=>10 + }) + .WebGUI::Form::submit($self->session) + .WebGUI::Form::formFooter($self->session); + my $p = WebGUI::Paginator->new($self->session,$self->getUrl,$self->getParent->get("postsPerPage")); my $sql = "select asset.assetId, asset.className, assetData.revisionDate as revisionDate, assetData.url as url from asset left join assetData on assetData.assetId=asset.assetId @@ -843,6 +874,26 @@ sub www_subscribe { #------------------------------------------------------------------- +=head2 www_transferKarma ( ) + +Transfers karma from the current user to this thread. + +=cut + +sub www_transferKarma { + my $self = shift; + my $amount = $self->session->form->get("karma","integer"); + # cant have them giving more karma then they have + if ($amount <= $self->session->user->karma) { + $self->session->user->karma($amount, "Thread ".$self->getId, "Transferring karma to a thread."); + my $newKarma = $self->get("karma")+$amount; + $self->update({karma=>$newKarma,karmaRank=>$newKarma/$self->get("karmaScale")}); + } + return $self->www_view; +} + +#------------------------------------------------------------------- + =head2 www_unarchive ( ) The web method to unarchive all the posts in this thread. diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 5049af9a9..532e9a6b9 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -405,6 +405,10 @@ sub definition { postGroupId =>{ fieldType=>"group", defaultValue=>'2' + }, + defaultKarmaScale => { + fieldType=>"integer", + defaultValue=>1 } } }); @@ -515,7 +519,17 @@ sub getEditForm { -hoverHelp=>$i18n->get('karma rating multiplier description'), -value=>$self->getValue("karmaRatingMultiplier") ); + $tabform->getTab("properties")->integer( + -name=>"defaultKarmaScale", + $i18n->get("default karma scale"), + -hoverHelp=>$i18n->get('default karma scale help'), + -value=>$self->getValue("defaultKarmaScale") + ); } else { + $tabform->getTab("properties")->hidden( + -name=>"defaultKarmaScale", + -value=>$self->getValue("defaultKarmaScale") + ); $tabform->getTab("properties")->hidden( -name=>"karmaPerPost", -value=>$self->getValue("karmaPerPost") @@ -548,6 +562,7 @@ sub getEditForm { userDefined4=>$i18n->get('user defined 4'), userDefined5=>$i18n->get('user defined 5'), ); + $options{karmaRank} = $i18n->get("karma rank") if ($self->session->setting->get("useKarma")); $tabform->getTab("display")->selectBox( -name=>"sortBy", -value=>[$self->getValue("sortBy")], diff --git a/lib/WebGUI/Help/Asset_Collaboration.pm b/lib/WebGUI/Help/Asset_Collaboration.pm index 055423d0f..6fc19cbcc 100644 --- a/lib/WebGUI/Help/Asset_Collaboration.pm +++ b/lib/WebGUI/Help/Asset_Collaboration.pm @@ -60,6 +60,11 @@ our $HELP = { description => 'posts/page description', namespace => 'Asset_Collaboration', }, + { + title => 'default karma scale', + description => 'default karma scale help', + namespace => 'Asset_Collaboration', + }, { title => 'karma/post', description => 'karma/post description', diff --git a/lib/WebGUI/i18n/English/Asset_Collaboration.pm b/lib/WebGUI/i18n/English/Asset_Collaboration.pm index 1a45bc0cf..02dca5e12 100644 --- a/lib/WebGUI/i18n/English/Asset_Collaboration.pm +++ b/lib/WebGUI/i18n/English/Asset_Collaboration.pm @@ -2,6 +2,24 @@ package WebGUI::i18n::English::Asset_Collaboration; our $I18N = { + 'karma rank' => { + message => q|Karma Rank|, + context => q|a label used in sorting threads by karma divided by karma scale|, + lastUpdated => 0, + }, + + 'default karma scale' => { + message => q|Default Karma Scale|, + context => q|a label indicating the default scale of all threads in the system|, + lastUpdated => 0, + }, + + 'default karma scale help' => { + message => q|This is the default value that will be assigned to the karma scale field in threads. Karma scale is a weighting mechanism for karma sorting that can be used for handicaps, difficulty, etc.|, + context => q|hover help for the default karma scale field|, + lastUpdated => 0, + }, + 'assetName' => { message => q|Collaboration System|, context => q|label for Asset Manager|, @@ -19,8 +37,8 @@ our $I18N = { }, 'karma rating multiplier' => { - message => q|Karma Rating Multiplier|, - lastUpdated => 0, + message => q|Karma Given To Poster on Rating|, + lastUpdated => 1141142205, }, 'delete file warning' => { @@ -891,8 +909,8 @@ submitted by a user.|, }, 'karma rating multiplier description' => { - message => q|If karma is enabled on your site, this amount multiplied by the rating the user gives a post will be the amount of karma the original author of the post receives.|, - lastUpdated => 1119070429, + message => q|If karma is enabled on your site, this will be the amount of karma the original author of the post receives when another user rates the post.|, + lastUpdated => 1141142205, }, 'filter code description' => { diff --git a/lib/WebGUI/i18n/English/Asset_Post.pm b/lib/WebGUI/i18n/English/Asset_Post.pm index b465c90c5..9d5baa223 100644 --- a/lib/WebGUI/i18n/English/Asset_Post.pm +++ b/lib/WebGUI/i18n/English/Asset_Post.pm @@ -61,6 +61,10 @@ A yes/no button to lock the thread, so that no posts can be added or edited. A conditional that is true if the user is editing an existing post.

+karmaScale.form
+A form element that allows moderators to set the scale of an individual thread. This is only available for threads. +

+ preview.title
The web safe title for previewing a post.

diff --git a/lib/WebGUI/i18n/English/Asset_Thread.pm b/lib/WebGUI/i18n/English/Asset_Thread.pm index d7f1362de..2c2404158 100644 --- a/lib/WebGUI/i18n/English/Asset_Thread.pm +++ b/lib/WebGUI/i18n/English/Asset_Thread.pm @@ -11,6 +11,22 @@ our $I18N = { message => q|The variables below are available in the Thread template. In addition, all variables from the Post Template can be used. Labels for URLs for actions like unlock.url, stick.url, etc. are provided by the Collaboration Labels. The Pagination Template variables are also available to display multiple pages of posts and threads.

+karma.transfer.form
+A variable that displays a small form that allows a user to transfer an amount of karma from their account to the thread. +

+ +karma
+Indicates the amount of karma this thread has. +

+ +karmaScale
+A weighting factor for difficulty, complexity, or handicap in contests. +

+ +karmaRank
+This is karma divided by karma scale. +

+ user.isVisitor
A conditional indicating that the current user is a Visitor.

@@ -175,7 +191,7 @@ The description of the collaboration system that this post is a part of.

|, - lastUpdated => 1140982574, + lastUpdated => 1141142205, }, 'assetName' => {