migrated the uss to the collaboration system

This commit is contained in:
JT Smith 2005-02-13 01:38:37 +00:00
parent 28730f7e36
commit 268c1cd8ba
6 changed files with 154 additions and 4267 deletions

View file

@ -1,446 +0,0 @@
package WebGUI::Asset::Wobject::USS;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use Tie::CPHash;
use WebGUI::DateTime;
use WebGUI::Grouping;
use WebGUI::HTML;
use WebGUI::HTTP;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Paginator;
use WebGUI::Privilege;
use WebGUI::Search;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Style;
use WebGUI::URL;
use WebGUI::Utility;
use WebGUI::Asset::Wobject;
use WebGUI::Asset::USS_submission;
our @ISA = qw(WebGUI::Asset::Wobject);
#-------------------------------------------------------------------
sub definition {
my $class = shift;
my $definition = shift;
push(@{$definition}, {
tableName=>'USS',
className=>'WebGUI::Asset::Wobject::USS',
properties=>{
templateId =>{
fieldType=>"template",
defaultValue=>'PBtmpl0000000000000066'
},
submissionsPerPage=>{
fieldType=>"integer",
defaultValue=>50
},
groupToContribute=>{
fieldType=>"group",
defaultValue=>2
},
groupToApprove=>{
fieldType=>"group",
defaultValue=>4
},
defaultStatus=>{
fieldType=>"selectList",
defaultValue=>"Approved"
},
submissionTemplateId=>{
fieldType=>"template",
defaultValue=>undef
},
submissionFormTemplateId=>{
fieldType=>"template",
defaultValue=>undef
},
karmaPerSubmission=>{
fieldType=>"integer",
defaultValue=>0
},
filterContent=>{
fieldType=>"filterContent",
defaultValue=>"javascript"
},
sortBy=>{
fieldType=>"selectList",
defaultValue=>"dateUpdated"
},
sortOrder=>{
fieldType=>"selectList",
defaultValue=>"desc"
},
USS_id=>{
fieldType=>"hidden",
autoId=>1
},
submissionFormTemplateId=>{
fieldType=>"template",
defaultValue=>undef
}
}
});
return $class->SUPER::definition($definition);
}
#-------------------------------------------------------------------
sub getEditForm {
my $self = shift;
my $tabform = $self->SUPER::getEditForm;
$tabform->getTab("display")->template(
-value=>$self->getValue('templateId'),
-namespace=>"USS"
);
$tabform->getTab("display")->template(
-name=>"submissionTemplateId",
-value=>$self->getValue("submissionTemplateId"),
-namespace=>"USS"."/Submission",
-label=>WebGUI::International::get(73,"USS"),
-afterEdit=>'func=edit&wid='.$self->get("wobjectId")
);
$tabform->getTab("display")->template(
-name=>"submissionFormTemplateId",
-value=>$self->getValue("submissionFormTemplateId"),
-namespace=>"USS"."/SubmissionForm",
-label=>WebGUI::International::get(87,"USS"),
-afterEdit=>'func=edit&wid='.$self->get("wobjectId")
);
$tabform->getTab("security")->group(
-name=>"groupToApprove",
-label=>WebGUI::International::get(1,"USS"),
-value=>[$self->getValue("groupToApprove")]
);
$tabform->getTab("security")->group(
-name=>"groupToContribute",
-label=>WebGUI::International::get(2,"USS"),
-value=>[$self->getValue("groupToContribute")]
);
$tabform->getTab("display")->integer(
-name=>"submissionsPerPage",
-label=>WebGUI::International::get(6,"USS"),
-value=>$self->getValue("submissionsPerPage")
);
$tabform->getTab("security")->selectList(
-name=>"defaultStatus",
-options=>{
Approved=>$self->status('Approved'),
Denied=>$self->status('Denied'),
Pending=>$self->status('Pending')
},
-label=>WebGUI::International::get(563),
-value=>[$self->getValue("defaultStatus")]
);
if ($session{setting}{useKarma}) {
$tabform->getTab("properties")->integer(
-name=>"karmaPerSubmission",
-label=>WebGUI::International::get(30,"USS"),
-value=>$self->getValue("karmaPerSubmission")
);
} else {
$tabform->getTab("properties")->hidden("karmaPerSubmission",$self->getValue("karmaPerSubmission"));
}
$tabform->getTab("display")->filterContent(
-value=>$self->getValue("filterContent")
);
$tabform->getTab("display")->selectList(
-name=>"sortBy",
-value=>[$self->getValue("sortBy")],
-options=>{
lineage=>WebGUI::International::get(88,"USS"),
dateUpdated=>WebGUI::International::get(78,"USS"),
dateSubmitted=>WebGUI::International::get(13,"USS"),
title=>WebGUI::International::get(35,"USS")
},
-label=>WebGUI::International::get(79,"USS")
);
$tabform->getTab("display")->selectList(
-name=>"sortOrder",
-value=>[$self->getValue("sortOrder")],
-options=>{
asc=>WebGUI::International::get(81,"USS"),
desc=>WebGUI::International::get(82,"USS")
},
-label=>WebGUI::International::get(80,"USS")
);
return $tabform;
}
#-------------------------------------------------------------------
sub getIcon {
my $self = shift;
my $small = shift;
return $session{config}{extrasURL}.'/assets/small/userSubmissionSystem.gif' if ($small);
return $session{config}{extrasURL}.'/assets/userSubmissionSystem.gif';
}
#-------------------------------------------------------------------
sub getIndexerParams {
my $self = shift;
my $now = shift;
return {
USS_discussion => {
sql => "select forumPost.forumPostId,
forumPost.username,
forumPost.subject,
forumPost.message,
forumPost.userId as ownerId,
forumThread.forumId as forumId,
USS_submission.USS_submissionId as sid,
wobject.namespace as namespace,
wobject.wobjectId as wid,
page.urlizedTitle as urlizedTitle,
page.languageId as languageId,
page.pageId as pageId,
page.groupIdView as page_groupIdView,
wobject.groupIdView as wobject_groupIdView,
7 as wobject_special_groupIdView
from forumPost, forumThread, USS_submission, wobject, page, USS
where forumPost.forumThreadId = forumThread.forumThreadId
and forumThread.forumId = USS_submission.forumId
and USS_submission.USS_id = USS.USS_id
and USS.wobjectId = wobject.wobjectId
and wobject.pageId = page.pageId
and wobject.startDate < $now
and wobject.endDate > $now
and page.startDate < $now
and page.endDate > $now",
fieldsToIndex => ["username", "subject", "message"],
contentType => 'discussion',
url => 'WebGUI::URL::append($data{urlizedTitle},"func=viewSubmission&wid=$data{wid}&sid=$data{sid}&forumOp=viewThread&forumPostId=$data{forumPostId}&forumId=$data{forumId}")',
headerShortcut => 'select subject from forumPost where forumPostId = \'$data{forumPostId}\'',
bodyShortcut => 'select message from forumPost where forumPostId = \'$data{forumPostId}\'',
},
USS_submission => {
sql => "select USS_submission.title as title,
USS_submission.username as username,
USS_submission.content as content,
USS_submission.image as image,
USS_submission.attachment as attachment,
USS.wobjectId as wid,
USS_submission.USS_submissionId as sid,
USS_submission.userId as ownerId,
wobject.namespace as namespace,
page.urlizedTitle as urlizedTitle,
page.languageId as languageId,
page.pageId as pageId,
page.groupIdView as page_groupIdView,
wobject.groupIdView as wobject_groupIdView,
7 as wobject_special_groupIdView
from wobject, page, USS_submission, USS
where USS_submission.USS_id = USS.USS_id
and USS.wobjectId = wobject.wobjectId
and wobject.pageId = page.pageId
and USS_submission.status = 'Approved'
and wobject.startDate < $now
and wobject.endDate > $now
and page.startDate < $now
and page.endDate > $now",
fieldsToIndex => ["username", "title", "content", "image", "attachment"],
contentType => 'wobjectDetail',
url => 'WebGUI::URL::append($data{urlizedTitle}, "func=viewSubmission&wid=$data{wid}&sid=$data{sid}")',
headerShortcut => 'select title from USS_submission where USS_submissionId = \'$data{sid}\'',
bodyShortcut => 'select content from USS_submission where USS_submissionId = \'$data{sid}\'',
}
};
}
#-------------------------------------------------------------------
sub getName {
return WebGUI::International::get(29,"USS");
}
#-------------------------------------------------------------------
sub status {
my $self = shift;
my $status = shift;
if ($status eq "Approved") {
return WebGUI::International::get(560);
} elsif ($status eq "Denied") {
return WebGUI::International::get(561);
} elsif ($status eq "Pending") {
return WebGUI::International::get(562);
}
}
#-------------------------------------------------------------------
sub view {
my $self = shift;
my $numResults = $self->get("submissionsPerPage");
my %var;
$var{"readmore.label"} = WebGUI::International::get(46,"USS");
$var{"responses.label"} = WebGUI::International::get(57,"USS");
$var{canPost} = WebGUI::Grouping::isInGroup($self->get("groupToContribute"));
$var{"post.url"} = $self->getUrl('func=add&class=WebGUI::Asset::USS_submission');
$var{"post.label"} = WebGUI::International::get(20,"USS");
$var{"addquestion.label"} = WebGUI::International::get(83,"USS");
$var{"addlink.label"} = WebGUI::International::get(89,"USS");
$var{"search.label"} = WebGUI::International::get(364);
$var{"search.Form"} = WebGUI::Search::form({func=>'view',search=>1});
$var{"search.url"} = WebGUI::Search::toggleURL("func=view");
$var{"rss.url"} = WebGUI::URL::page('func=viewRSS',1);
$var{canModerate} = WebGUI::Grouping::isInGroup($self->get("groupToApprove"),$session{user}{userId});
$var{"title.label"} = WebGUI::International::get(99);
$var{"thumbnail.label"} = WebGUI::International::get(52,"USS");
$var{"date.label"} = WebGUI::International::get(13,"USS");
$var{"date.updated.label"} = WebGUI::International::get(78,"USS");
$var{"by.label"} = WebGUI::International::get(21,"USS");
$var{"submission.edit.label"} = WebGUI::International::get(27,"USS");
WebGUI::Style::setLink($var{"rss.url"},{ rel=>'alternate', type=>'application/rss+xml', title=>'RSS' });
my $constraints;
if ($session{scratch}{search}) {
$numResults = $session{scratch}{numResults};
$constraints = WebGUI::Search::buildConstraints([qw(USS_submission.username asset.synopsis asset.title USS_submission.content USS_submission.userDefined1 USS_submission.userDefined2 USS_submission.userDefined3 USS_submission.userDefined4 USS_submission.userDefined5)]);
}
if ($constraints ne "") {
$constraints = "USS_submission.status='Approved' and ".$constraints;
} else {
$constraints = "(USS_submission.status='Approved' or (USS_submission.userId=".quote($session{user}{userId})." and USS_submission.userId<>'1')";
if ($var{canModerate}) {
$constraints .= " or USS_submission.status='Pending'";
}
$constraints .= ")";
}
my $p = WebGUI::Paginator->new($self->getUrl,$numResults);
my $sql = "select * from USS_submission left join asset on USS_submission.assetId=asset.assetId
where asset.parentId=".quote($self->getId)." and asset.state='published' and asset.className='WebGUI::Asset::USS_submission' and $constraints
order by ".$self->getValue("sortBy")." ".$self->getValue("sortOrder");
$p->setDataByQuery($sql);
my $page = $p->getPageData;
my $i = 0;
my $imageURL = "";
foreach my $row (@$page) {
my $submission = WebGUI::Asset::USS_submission->newByPropertyHashRef($row);
my $body = WebGUI::HTML::filter($submission->get("content"),$self->get("filterContent"));
$body = WebGUI::HTML::format($body,$submission->get("contentType"));
my $controls = deleteIcon('func=delete',$submission->getUrl,WebGUI::International::get(17,"USS")).editIcon('func=edit',$submission->getUrl);
if ($self->get("sortBy") eq "lineage") {
if ($self->get("sortOrder") eq "desc") {
$controls .= moveUpIcon('func=demote',$submission->getUrl).moveDownIcon('func=promote',$submission->getUrl);
} else {
$controls .= moveUpIcon('func=promote',$submission->getUrl).moveDownIcon('func=demote',$submission->getUrl);
}
}
my $inDateRange;
if ($submission->get("startDate") < WebGUI::DateTime::time() && $submission->get("endDate") > WebGUI::DateTime::time()) {
$inDateRange = 1;
} else {
$inDateRange = 0;
}
push(@{$var{submissions_loop}}, {
"submission.id"=>$submission->getId,
"submission.url"=>$submission->getUrl,
"submission.content"=>$submission->get("synopsis"),
"submission.content.full"=>$submission->get("content"),
"submission.responses"=>$submission->getResponseCount,
"submission.title"=>$submission->get("title"),
"submission.userDefined1"=>$submission->get("userDefined1"),
"submission.userDefined2"=>$submission->get("userDefined2"),
"submission.userDefined3"=>$submission->get("userDefined3"),
"submission.userDefined4"=>$submission->get("userDefined4"),
"submission.userDefined5"=>$submission->get("userDefined5"),
"submission.userId"=>$submission->get("userId"),
"submission.username"=>$submission->get('username'),
"submission.status"=>$self->status($submission->get("status")),
"submission.thumbnail"=>$submission->getThumbnailUrl,
"submission.image"=>$submission->getImageUrl,
"submission.date"=>epochToHuman($submission->get("dateSubmitted")),
"submission.date.updated"=>epochToHuman($submission->get("dateUpdated")),
"submission.userProfile"=>WebGUI::URL::page('op=viewProfile&uid='.$submission->get("userId")),
"submission.edit.url"=>$submission->getUrl("func=edit"),
"submission.secondColumn"=>(($i+1)%2==0),
"submission.thirdColumn"=>(($i+1)%3==0),
"submission.fourthColumn"=>(($i+1)%4==0),
"submission.fifthColumn"=>(($i+1)%5==0),
'submission.controls'=>$submission->getToolbar,
'submission.inDateRange'=>$inDateRange,
"submission.currentUser"=>($session{user}{userId} eq $submission->get("userId") && $session{user}{userId} ne "1")
});
$i++;
}
$p->appendTemplateVars(\%var);
return $self->processTemplate(\%var,$self->get("templateId"));
}
#-------------------------------------------------------------------
sub www_edit {
my $self = shift;
return $self->getAdminConsole->render(WebGUI::Privilege::insufficient()) unless $self->canEdit;
$self->getAdminConsole->setHelp("user submission system add/edit");
return $self->getAdminConsole->render($self->getEditForm->print,WebGUI::International::get("18","USS"));
}
#-------------------------------------------------------------------
# print out RSS 2.0 feed describing the items visible on the first page
sub www_viewRSS {
$_[0]->logView() if ($session{setting}{passiveProfilingEnabled});
my $wid = $_[0]->get("wobjectId");
my $numResults = $_[0]->get("submissionsPerPage");
my $encTitle = _xml_encode($_[0]->get("title"));
my $encDescription = _xml_encode($_[0]->get("description"));
my $encUrl = _xml_encode(WebGUI::URL::page("wid=$wid"));
my $xml = qq~<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>$encTitle</title>
<link>$encUrl</link>
<description>$encDescription</description>
~;
my $res = WebGUI::SQL->read
("select USS_submissionId, content, title, " .
"dateSubmitted, username from USS_submission " .
"where USS_id = " .quote($_[0]->get("USS_id")) . " and status='Approved' " .
"order by ".$_[0]->getValue("sortBy")." ".$_[0]->getValue("sortOrder")." limit " . $numResults,WebGUI::SQL->getSlave);
while (my $row = $res->{_sth}->fetchrow_arrayref()) {
my ($sid, $content, $title, $dateSubmitted, $username) =
@{$row};
my $encUrl = _xml_encode
(WebGUI::URL::page
("wid=$wid&func=viewSubmission&sid=$sid"));
my $encTitle = _xml_encode($title);
my $encPubDate = _xml_encode
(_get_rfc822_date($dateSubmitted));
my $encDescription = _xml_encode($content);
$xml .= qq~
<item>
<title>$encTitle</title>
<link>$encUrl</link>
<description>$encDescription</description>
<guid isPermaLink="true">$encUrl</guid>
<pubDate>$encPubDate</pubDate>
</item>
~;
}
$xml .=qq~
</channel>
</rss>
~;
WebGUI::HTTP::setMimeType("text/xml");
return $xml;
}
1;

View file

@ -1,475 +0,0 @@
package WebGUI::Forum;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2005 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use WebGUI::Forum::Thread;
use WebGUI::Grouping;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Utility;
=head1 NAME
Package WebGUI::Forum
=head1 DESCRIPTION
Data management class for forums.
=head1 SYNOPSIS
use WebGUI::Forum;
$forum = WebGUI::Forum->create(\%forumParams);
$forum = WebGUI::Forum->new($forumId);
$boolean = $forum->canPost;
$boolean = $forum->canView;
$scalar = $forum->get($param);
$obj = $forum->getThread($threadId);
$boolean = $forum->isModerator;
$boolean = $forum->isSubscribed;
$forum->decrementReplies;
$forum->decrementThreads;
$forum->incrementReplies($postDate, $postId);
$forum->incrementThreads($postDate, $postId);
$forum->incrementViews;
$forum->purge;
$forum->recalculateRating;
$forum->set(\%data);
$forum->setLastPost($epoch, $postId);
$forum->subscribe;
$forum->unsubscribe;
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 canPost ( [ userId ] )
Returns a boolean whether the user has the privileges required to post.
=head3 userId
Defaults to $session{user}{userId}. Specify a user ID to check privileges for.
=cut
sub canPost {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
return (WebGUI::Grouping::isInGroup($self->get("groupToPost"),$userId) || $self->isModerator);
}
#-------------------------------------------------------------------
=head2 canView ( [ userId ] )
Returns a boolean whether the user has the privileges required to view the forum.
=head3 userId
Defaults to $session{user}{userId}. Specify a user ID to check privileges for.
=cut
sub canView {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
return (WebGUI::Grouping::isInGroup($self->get("groupToView"),$userId) || $self->canPost);
}
#-------------------------------------------------------------------
=head2 create ( forumParams )
Creates a new forum. Returns a forum object.
=head3 forumParams
A hash reference containing a list of the parameters to default the forum to. The valid parameters are:
addEditStampToPosts - boolean
filterPosts - A valid HTML::filter string.
karmaPerPost - integer
groupToPost - Group ID
groupToModerate - Group ID
editTimeout - interval
moderatePosts - boolean
attachmentsPerPost - integer
allowRichEdit - boolean
allowReplacements - boolean
forumTemplateId - Template ID
threadTemplateId - Template ID
postTemplateId - Template ID
postFormTemplateId - Template ID
searchTemplateId - Template ID
notificationTemplateId - Template ID
archiveAfter - interval
postsPerPage - integer
masterForumId - Forum ID
=cut
sub create {
my ($self, $data) = @_;
$data->{forumId} = "new";
my $forumId = WebGUI::SQL->setRow("forum","forumId",$data);
return WebGUI::Forum->new($forumId);
}
#-------------------------------------------------------------------
=head2 decrementReplies ( )
Deccrements this forum's reply counter.
=cut
sub decrementReplies {
my ($self) = @_;
WebGUI::SQL->write("update forum set replies=replies-1 where forumId=".quote($self->get("forumId")));
}
#-------------------------------------------------------------------
=head2 decrementThreads ( )
Decrements this forum's thread counter.
=cut
sub decrementThreads {
my ($self) = @_;
WebGUI::SQL->write("update forum set threads=threads-1 where forumId=".quote($self->get("forumId")));
}
#-------------------------------------------------------------------
=head2 get ( [ param ] )
Returns a hash reference containing all of the properties of the forum.
=head3 param
If specified then this method will return the value of this one parameter as a scalar. Param is the name of the parameter to return. See the forum table for details.
=cut
sub get {
my ($self, $key) = @_;
if ($key eq "") {
return $self->{_properties};
}
return $self->{_properties}->{$key};
}
#-------------------------------------------------------------------
=head2 getThread ( threadId )
Returns a thread object.
=head3 threadId
The unique identifier of a thread in this forum.
=cut
sub getThread {
my ($self, $threadId) = @_;
unless (exists $self->{_thread}{$threadId}) {
$self->{_thread}{$threadId} = WebGUI::Forum::Thread->new($threadId);
}
return $self->{_thread}{$threadId};
}
#-------------------------------------------------------------------
=head2 isModerator ( [ userId ] )
Returns a boolean indicating whether the user is a moderator.
=head3 userId
Defaults to $session{user}{userId}. A user id to test for moderator privileges.
=cut
sub isModerator {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
return WebGUI::Grouping::isInGroup($self->get("groupToModerate"), $userId);
}
#-------------------------------------------------------------------
=head2 incrementReplies ( lastPostDate, lastPostId )
Increments this forum's reply counter.
=head3 lastPostDate
The date of the post being added.
=head3 lastPostId
The unique identifier of the post being added.
=cut
sub incrementReplies {
my ($self, $lastPostDate, $lastPostId) = @_;
WebGUI::SQL->write("update forum set replies=replies+1, lastPostId=".quote($lastPostId).", lastPostDate=$lastPostDate where forumId=".quote($self->get("forumId")));
}
#-------------------------------------------------------------------
=head2 incrementThreads ( lastPostDate, lastPostId )
Increments the thread counter for this forum.
=head3 lastPostDate
The date of the post that was just added.
=head3 lastPostId
The unique identifier of the post that was just added.
=cut
sub incrementThreads {
my ($self, $lastPostDate, $lastPostId) = @_;
WebGUI::SQL->write("update forum set threads=threads+1, lastPostId=".quote($lastPostId).", lastPostDate=$lastPostDate where forumId=".quote($self->get("forumId")));
}
#-------------------------------------------------------------------
=head2 incrementViews ( )
Increments the views counter on this forum.
=cut
sub incrementViews {
my ($self) = @_;
WebGUI::SQL->write("update forum set views=views+1 where forumId=".quote($self->get("forumId")));
}
#-------------------------------------------------------------------
=head2 isSubscribed ( [ userId ] )
Returns a boolean indicating whether the user is subscribed to the forum.
=head3 userId
The user to check for the subscription. Defaults to $session{user}{userId}.
=cut
sub isSubscribed {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
my ($isSubscribed) = WebGUI::SQL->quickArray("select count(*) from forumSubscription where forumId=".quote($self->get("forumId"))." and userId=".quote($userId));
return $isSubscribed;
}
#-------------------------------------------------------------------
=head2 new ( forumId )
Constructor.
=head3 forumId
The unique identifier of the forum to retrieve the object for.
=cut
sub new {
my ($class, $forumId) = @_;
my $properties = WebGUI::SQL->getRow("forum","forumId",$forumId);
if ($properties->{masterForumId}) {
my $master = WebGUI::SQL->getRow("forum","forumId",$properties->{masterForumId});
$properties->{forumTemplateId} = $master->{forumTemplateId};
$properties->{threadTemplateId} = $master->{threadTemplateId};
$properties->{postTemplateId} = $master->{postTemplateId};
$properties->{searchTemplateId} = $master->{searchTemplateId};
$properties->{notificationTemplateId} = $master->{notificationTemplateId};
$properties->{postFormTemplateId} = $master->{postFormTemplateId};
$properties->{postPreviewTemplateId} = $master->{postPreviewTemplateId};
$properties->{archiveAfter} = $master->{archiveAfter};
$properties->{allowRichEdit} = $master->{allowRichEdit};
$properties->{allowReplacements} = $master->{allowReplacements};
$properties->{filterPosts} = $master->{filterPosts};
$properties->{karmaPerPost} = $master->{karmaPerPost};
$properties->{groupToView} = $master->{groupToView};
$properties->{groupToPost} = $master->{groupToPost};
$properties->{groupToView} = $master->{groupToView};
$properties->{groupToModerate} = $master->{groupToModerate};
$properties->{moderatePosts} = $master->{moderatePosts};
$properties->{attachmentsPerPost} = $master->{attachmentsPerPost};
$properties->{addEditStampToPosts} = $master->{addEditStampsToPost};
$properties->{postsPerPage} = $master->{postsPerPage};
$properties->{usePreview} = $master->{usePreview};
}
bless {_properties=>$properties}, $class;
}
#-------------------------------------------------------------------
=head2 purge ( )
Destroys this forum and everything it contains.
=cut
sub purge {
my ($self) = @_;
return unless ($self->get("forumId"));
my $a = WebGUI::SQL->read("select * from forumThread where forumId=".quote($self->get("forumId")));
while (my ($threadId) = $a->array) {
my $b = WebGUI::SQL->read("select * from forumPost where forumThreadId=".quote($threadId));
while (my ($postId) = $b->array) {
WebGUI::SQL->write("delete from forumPostAttachment where forumPostId=".quote($postId));
WebGUI::SQL->write("delete from forumPostRating where forumPostId=".quote($postId));
}
$b->finish;
WebGUI::SQL->write("delete from forumThreadSubscription where forumThreadId=".quote($threadId));
WebGUI::SQL->write("delete from forumRead where forumThreadId=".quote($threadId));
WebGUI::SQL->write("delete from forumPost where forumThreadId=".quote($threadId));
}
$a->finish;
WebGUI::SQL->write("delete from forumSubscription where forumId=".quote($self->get("forumId")));
WebGUI::SQL->write("delete from forumThread where forumId=".quote($self->get("forumId")));
WebGUI::SQL->write("delete from forum where forumId=".quote($self->get("forumId")));
}
#-------------------------------------------------------------------
=head2 recalculateRating ( )
Calculates the rating of this forum from its threads and stores the new value in the forum properties.
=cut
sub recalculateRating {
my ($self) = @_;
my ($count) = WebGUI::SQL->quickArray("select count(*) from forumThread where forumId=".quote($self->get("forumId"))." and rating>0");
$count = $count || 1;
my ($sum) = WebGUI::SQL->quickArray("select sum(rating) from forumThread where forumId=".quote($self->get("forumId"))." and rating>0");
my $average = round($sum/$count);
$self->set({rating=>$average});
}
#-------------------------------------------------------------------
=head2 set ( data )
Sets the forum properties both in the object and to the database.
=head3 data
A hash reference containing the properties to set. See the forum table for details.
=cut
sub set {
my ($self, $data) = @_;
$data->{forumId} = $self->get("forumId") unless ($data->{forumId});
WebGUI::SQL->setRow("forum","forumId",$data);
foreach my $key (keys %{$data}) {
$self->{_properties}{$key} = $data->{$key};
}
}
#-------------------------------------------------------------------
=head2 setLastPost ( lastPostDate, lastPostId )
Sets the pertinent details for the last post. Can also be done directly using the set method.
=head3 lastPostDate
The epoch date of the post.
=head3 lastPostId
The unique id of the post.
=cut
sub setLastPost {
my ($self, $postDate, $postId) = @_;
$self->set({
lastPostId=>$postId,
lastPostDate=>$postDate
});
}
#-------------------------------------------------------------------
=head2 subscribe ( [ userId ] )
Subscribes a user to this forum.
=head3 userId
The unique identifier of the user to subscribe. Defaults to the current user.
=cut
sub subscribe {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
unless ($self->isSubscribed($userId)) {
WebGUI::SQL->write("insert into forumSubscription (forumId, userId) values (".quote($self->get("forumId")).",".quote($userId).")");
}
}
#-------------------------------------------------------------------
=head2 unsubscribe ( [ userId ] )
Unsubscribes a user from this forum.
=head3 userId
The unique identifier of the user to unsubscribe. Defaults to the current user.
=cut
sub unsubscribe {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
if ($self->isSubscribed($userId)) {
WebGUI::SQL->write("delete from forumSubscription where forumId=".quote($self->get("forumId"))." and userId=".quote($userId));
}
}
1;

View file

@ -1,487 +0,0 @@
package WebGUI::Forum::Post;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2005 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use WebGUI::DateTime;
use WebGUI::Forum::Thread;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Utility;
=head1 NAME
Package WebGUI::Forum::Post
=head1 DESCRIPTION
Data management class for forum posts.
=head1 SYNOPSIS
use WebGUI::Forum::Post;
$post = WebGUI::Forum::Post->create(\%params);
$post = WebGUI::Forum::Post->new($postId);
$boolean = $post->canEdit;
$boolean = $post->canView;
$scalar = $post->get("forumPostId");
$arrayRef = $post->getReplies;
$obj = $post->getThread;
$boolean = $post->hasRated;
$boolean = $post->isMarkedRead;
$boolean = $post->isReply;
$post->incrementViews;
$post->markRead;
$post->rate($rating);
$post->recalculateRating;
$post->set(\%data);
$post->setStatusApproved;
$post->setStatusArchived;
$post->setStatusDeleted;
$post->setStatusDenied;
$post->setStatusPending;
$post->unmarkRead;
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 canEdit ( [ userId ] )
Returns a boolean indicating whether the user can edit the current post.
=head3 userId
The unique identifier to check privileges against. Defaults to the current user.
=cut
sub canEdit {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
return ($self->getThread->getForum->isModerator || ($self->get("userId") eq $userId && $userId != 1
&& $self->getThread->getForum->get("editTimeout") > (WebGUI::DateTime::time() - $self->get("dateOfPost"))));
}
#-------------------------------------------------------------------
=head2 canView ( [ userId ] )
Returns a boolean indicating whether the user can view the current post.
=head3 userId
The unique identifier to check privileges against. Defaults to the current user.
=cut
sub canView {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
if ($self->get("status") eq "approved" || $self->get("status") eq "archived") {
return 1;
} elsif ($self->get("status") eq "deleted") {
return 0;
} elsif ($self->get("status") eq "denied" && $userId eq $self->get("userId")) {
return 1;
} elsif ($self->getThread->getForum->isModerator) {
return 1;
} else {
return 0;
}
}
#-------------------------------------------------------------------
=head2 create ( [ data ] )
Creates a new post.
=head3 data
A hash reference containing the data to use to create the post. See the forumPost table for details.
=cut
sub create {
my ($self, $data) = @_;
$data->{dateOfPost} = WebGUI::DateTime::time();
$data->{forumPostId} = "new";
my $forumPostId = WebGUI::SQL->setRow("forumPost","forumPostId", $data);
$self = WebGUI::Forum::Post->new($forumPostId);
return $self;
}
#-------------------------------------------------------------------
=head2 get ( [ param ] )
Returns a hash reference containing all of the parameters of this post.
=head3 param
The name of a parameter to get. If specified then the method will return only the value for this parameter as a scalar.
=cut
sub get {
my ($self, $key) = @_;
if ($key eq "") {
return $self->{_properties};
}
return $self->{_properties}->{$key};
}
#-------------------------------------------------------------------
=head2 getReplies ( )
Returns an array reference containing a list of post objects that are direct decendants to this post.
=cut
sub getReplies {
my ($self) = @_;
my @replies = ();
my $query = "select forumPostId from forumPost where parentId=".quote($self->get("forumPostId"))." and ";
if ($self->getThread->getForum->isModerator) {
$query .= "(status='approved' or status='pending' or status='denied'";
} else {
$query .= "(status='approved'";
}
$query .= " or userId=".quote($session{user}{userId}).") order by dateOfPost";
my $sth = WebGUI::SQL->read($query,WebGUI::SQL->getSlave);
while (my @data = $sth->array) {
push(@replies,WebGUI::Forum::Post->new($data[0]));
}
$sth->finish;
return \@replies;
}
#-------------------------------------------------------------------
=head2 getThread ( )
Returns the thread object that is related to this post.
=cut
sub getThread {
my ($self) = @_;
unless (exists $self->{_thread}) {
$self->{_thread} = WebGUI::Forum::Thread->new($self->get("forumThreadId"));
}
return $self->{_thread};
}
#-------------------------------------------------------------------
=head2 hasRated ( [ userId, ipAddress ] )
Returns a boolean indicating whether this user has already rated this post.
=head3 userId
A unique identifier for a user to check. Defaults to the current user.
=head3 ipAddress
If the user ID equals 1 (visitor) then an IP address is used to distinguish the user. Defaults to the current user's ip address.
=cut
sub hasRated {
my ($self, $userId, $ipAddress) = @_;
$userId = $session{user}{userId} unless ($userId);
return 1 if ($userId != 1 && $userId eq $self->get("userId")); # is poster
$ipAddress = $session{env}{REMOTE_ADDR} unless ($ipAddress);
my ($flag) = WebGUI::SQL->quickArray("select count(*) from forumPostRating where forumPostId="
.quote($self->get("forumPostId"))." and ((userId=".quote($userId)." and userId<>1) or (userId='1' and
ipAddress=".quote($ipAddress)."))");
return $flag;
}
#-------------------------------------------------------------------
=head2 incrementViews ( )
Increments the views counter for this post.
=cut
sub incrementViews {
my ($self) = @_;
WebGUI::SQL->write("update forumPost set views=views+1 where forumPostId=".quote($self->get("forumPostId")));
$self->getThread->incrementViews;
}
#-------------------------------------------------------------------
=head2 isMarkedRead ( [ userId ] )
Returns a boolean indicating whether this post is marked read for the user.
=head3 userId
A unique id for a user that you want to check. Defaults to the current user.
=cut
sub isMarkedRead {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
my ($isRead) = WebGUI::SQL->quickArray("select count(*) from forumRead where userId=".quote($userId)." and forumPostId=".quote($self->get("forumPostId")));
return $isRead;
}
#-------------------------------------------------------------------
=head2 isReply ( )
Returns a boolean indicating whether this post is a reply or the root post in a thread.
=cut
sub isReply {
my ($self) = @_;
if ($self->get("parentId") ne "0") {
return 1;
} else {
return 0;
}
}
#-------------------------------------------------------------------
=head2 markRead ( [ userId ] )
Marks this post read for this user.
=head3 userId
A unique identifier for a user. Defaults to the current user.
=cut
sub markRead {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
unless ($self->isMarkedRead($userId)) {
WebGUI::SQL->write("insert into forumRead (userId, forumPostId, forumThreadId, lastRead) values (".quote($userId).",
".quote($self->get("forumPostId")).", ".quote($self->get("forumThreadId")).", ".WebGUI::DateTime::time().")");
}
$self->incrementViews;
}
#-------------------------------------------------------------------
=head2 new ( postId )
Constructor.
=head3 postId
The unique identifier for the post object you wish to retrieve.
=cut
sub new {
my ($class, $forumPostId) = @_;
my $properties = WebGUI::SQL->getRow("forumPost","forumPostId",$forumPostId);
if (defined $properties) {
bless {_properties=>$properties}, $class;
} else {
return undef;
}
}
#-------------------------------------------------------------------
=head2 rate ( rating [ , userId, ipAddress ] )
Stores a rating against this post.
=head3 rating
An integer between 1 and 5 (5 being best) to rate this post with.
=head3 userId
The unique id for the user rating this post. Defaults to the current user.
=head3 ipAddress
The ip address of the user doing the rating. Defaults to the current user's IP.
=cut
sub rate {
my ($self, $rating, $userId, $ipAddress) = @_;
$userId = $session{user}{userId} unless ($userId);
$ipAddress = $session{env}{REMOTE_ADDR} unless ($ipAddress);
WebGUI::SQL->write("insert into forumPostRating (forumPostId,userId,ipAddress,dateOfRating,rating) values ("
.quote($self->get("forumPostId")).", ".quote($userId).", ".quote($ipAddress).", ".WebGUI::DateTime::time().", $rating)");
$self->recalculateRating;
}
#-------------------------------------------------------------------
=head2 recalculateRating ( )
Recalculates the average rating of the post from all the ratings and stores the result to the database.
=cut
sub recalculateRating {
my ($self) = @_;
my ($count) = WebGUI::SQL->quickArray("select count(*) from forumPostRating where forumPostId=".quote($self->get("forumPostId")));
$count = $count || 1;
my ($sum) = WebGUI::SQL->quickArray("select sum(rating) from forumPostRating where forumPostId=".quote($self->get("forumPostId")));
my $average = round($sum/$count);
$self->set({rating=>$average});
$self->getThread->recalculateRating;
}
#-------------------------------------------------------------------
=head2 set ( data )
Sets properties to the database and the object.
=head3 data
A hash reference containing the properties to set. See the forumPost table for details.
=cut
sub set {
my ($self, $data) = @_;
$data->{forumPostId} = $self->get("forumPostId") unless ($data->{forumPostId});
WebGUI::SQL->setRow("forumPost","forumPostId",$data);
foreach my $key (keys %{$data}) {
$self->{_properties}{$key} = $data->{$key};
}
}
#-------------------------------------------------------------------
=head2 setStatusApproved ( )
Sets the status of this post to approved.
=cut
sub setStatusApproved {
my ($self) = @_;
$self->set({status=>'approved'});
$self->getThread->setStatusApproved if ($self->getThread->get("rootPostId") eq $self->get("forumPostId"));
if ($self->isReply) {
$self->getThread->incrementReplies($self->get("dateOfPost"),$self->get("forumPostId"));
}
}
#-------------------------------------------------------------------
=head2 setStatusArchived ( )
Sets the status of this post to archived.
=cut
sub setStatusArchived {
my ($self) = @_;
$self->set({status=>'archived'});
$self->getThread->setStatusArchived if ($self->getThread->get("rootPostId") eq $self->get("forumPostId"));
if ($self->isReply) {
$self->getThread->incrementReplies($self->get("dateOfPost"),$self->get("forumPostId"));
}
}
#-------------------------------------------------------------------
=head2 setStatusDeleted ( )
Sets the status of this post to deleted.
=cut
sub setStatusDeleted {
my ($self) = @_;
$self->set({status=>'deleted'});
$self->getThread->decrementReplies;
$self->getThread->setStatusDeleted if ($self->getThread->get("rootPostId") eq $self->get("forumPostId"));
my ($id, $date) = WebGUI::SQL->quickArray("select forumPostId,dateOfPost from forumPost where forumThreadId="
.quote($self->get("forumThreadId"))." and status='approved'");
$self->getThread->setLastPost($date,$id);
}
#-------------------------------------------------------------------
=head2 setStatusDenied ( )
Sets the status of this post to denied.
=cut
sub setStatusDenied {
my ($self) = @_;
$self->set({status=>'denied'});
$self->getThread->setStatusDenied if ($self->getThread->get("rootPostId") eq $self->get("forumPostId"));
}
#-------------------------------------------------------------------
=head2 setStatusPending ( )
Sets the status of this post to pending.
=cut
sub setStatusPending {
my ($self) = @_;
$self->set({status=>'pending'});
$self->getThread->setStatusPending if ($self->getThread->get("rootPostId") eq $self->get("forumPostId"));
}
#-------------------------------------------------------------------
=head2 unmarkRead ( [ userId ] )
Negates the markRead method.
=head3 userId
The unique id of the user marking unread. Defaults to the current user.
=cut
sub unmarkRead {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
WebGUI::SQL->write("delete from forumRead where userId=".quote($userId)." and forumPostId=".quote($self->get("forumPostId")));
}
1;

View file

@ -1,540 +0,0 @@
package WebGUI::Forum::Thread;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2005 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use WebGUI::DateTime;
use WebGUI::Forum;
use WebGUI::Forum::Post;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Utility;
=head1 NAME
Package WebGUI::Forum::Thread
=head1 DESCRIPTION
Data management class for forum threads.
=head1 SYNOPSIS
use WebGUI::Forum;
$thread = WebGUI::Forum::Thread->create(\%params);
$thread = WebGUI::Forum::Thread->new($threadId);
$scalar = $thread->get($param);
$obj = $thread->getForum;
$obj = $thread->getNextThread;
$obj = $thread->getPost($postId);
$obj = $thread->getPreviousThread;
$boolean = $thread->isLocked;
$boolean = $thread->isSticky;
$boolean = $thread->isSubscribed;
$thread->decrementReplies;
$thread->incrementReplies($postDate, $postId);
$thread->incrementViews;
$thread->lock;
$thread->recalculateRating;
$thread->set(\%data);
$thread->setLastPost($postDate,$postId);
$thread->setStatusApproved;
$thread->setStatusArchived;
$thread->setStatusDeleted;
$thread->setStatusDenied;
$thread->setStatusPending;
$thread->stick;
$thread->subscribe;
$thread->unlock;
$thread->unstick;
$thread->unsubscribe;
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 create ( data, postData )
Creates a new thread, including the root post in that thread.
=head3 data
The properties of this thread. See the forumThread table for details.
=head3 postData
The properties of the root post in this thread. See the forumPost table and the WebGUI::Forum::Post->create method for details.
=cut
sub create {
my ($self, $data, $postData) = @_;
$data->{forumThreadId} = "new";
$postData->{forumThreadId} = WebGUI::SQL->setRow("forumThread","forumThreadId", $data);
$self = WebGUI::Forum::Thread->new($postData->{forumThreadId});
$postData->{parentId} = 0;
my $post = WebGUI::Forum::Post->create($postData);
$self->set({
rootPostId=>$post->get("forumPostId"),
lastPostId=>$post->get("forumPostId"),
lastPostDate=>$post->get("dateOfPost")
});
$self->{_post}{$post->get("forumPostId")} = $post;
$self->getForum->incrementThreads($post->get("dateOfPost"),$post->get("forumPostId"));
return $self;
}
#-------------------------------------------------------------------
=head2 decrementReplies ( )
Decrements the replies counter for this thread.
=cut
sub decrementReplies {
my ($self) = @_;
WebGUI::SQL->write("update forumThread set replies=replies-1 where forumThreadId=".quote($self->get("forumThreadId")));
$self->getForum->decrementReplies;
}
#-------------------------------------------------------------------
=head2 get ( [ param ] )
Returns a hash reference containing all the properties of this thread.
=head3 param
The name of a specific property. If specified only the value of that property will be return as a scalar.
=cut
sub get {
my ($self, $key) = @_;
if ($key eq "") {
return $self->{_properties};
}
return $self->{_properties}->{$key};
}
#-------------------------------------------------------------------
=head2 getForum ( )
Returns a forum object for the forum that is related to this thread.
=cut
sub getForum {
my ($self) = @_;
unless (exists $self->{_forum}) {
$self->{_forum} = WebGUI::Forum->new($self->get("forumId"));
}
return $self->{_forum};
}
#-------------------------------------------------------------------
=head2 getNextThread ( )
Returns a thread object for the next (newer) thread in the same forum.
=cut
sub getNextThread {
my ($self) = @_;
unless (exists $self->{_next}) {
my ($nextId) = WebGUI::SQL->quickArray("select lastPostId from forumThread where forumId=".quote($self->get("forumId"))."
and lastPostDate>".quote($self->get("lastPostDate")." order by lastPostDate asc"),WebGUI::SQL->getSlave);
$self->{_next} = WebGUI::Forum::Thread->new($nextId);
}
return $self->{_next};
}
#-------------------------------------------------------------------
=head2 getPost ( postId )
Returns a post object.
=head3 postId
The unique id of the post object you wish to retrieve.
=cut
sub getPost {
my ($self, $postId) = @_;
unless (exists $self->{_post}{$postId}) {
$self->{_post}{$postId} = WebGUI::Forum::Post->new($postId);
}
return $self->{_post}{$postId};
}
#-------------------------------------------------------------------
=head2 getPreviousThread ( )
Returns a thread object for the previous (older) thread in the same forum.
=cut
sub getPreviousThread {
my ($self) = @_;
unless (exists $self->{_previous}) {
my ($nextId) = WebGUI::SQL->quickArray("select lastPostId from forumThread where forumId=".quote($self->get("forumId"))."
and lastPostDate<".quote($self->get("lastPostDate")." order by lastPostDate desc"),WebGUI::SQL->getSlave);
$self->{_previous} = WebGUI::Forum::Thread->new($nextId);
}
return $self->{_previous};
}
#-------------------------------------------------------------------
=head2 isLocked ( )
Returns a boolean indicating whether this thread is locked from new posts and other edits.
=cut
sub isLocked {
my ($self) = @_;
return $self->get("isLocked");
}
#-------------------------------------------------------------------
=head2 incrementReplies ( lastPostDate, lastPostId )
Increments the replies counter for this thread.
=head3 lastPostDate
The date of the reply that caused the replies counter to be incremented.
=head3 lastPostId
The id of the reply that caused the replies counter to be incremented.
=cut
sub incrementReplies {
my ($self, $dateOfReply, $replyId) = @_;
WebGUI::SQL->write("update forumThread set replies=replies+1, lastPostId=".quote($replyId).", lastPostDate=$dateOfReply
where forumThreadId=".quote($self->get("forumThreadId")));
$self->getForum->incrementReplies($dateOfReply,$replyId);
}
#-------------------------------------------------------------------
=head2 incrementViews ( )
Increments the views counter for this thread.
=cut
sub incrementViews {
my ($self) = @_;
WebGUI::SQL->write("update forumThread set views=views+1 where forumThreadId=".quote($self->get("forumThreadId")));
$self->getForum->incrementViews;
}
#-------------------------------------------------------------------
=head2 isSticky ( )
Returns a boolean indicating whether this thread should be "stuck" a the top of the forum and not be sorted with the rest of the threads.
=cut
sub isSticky {
my ($self) = @_;
return $self->get("isSticky");
}
#-------------------------------------------------------------------
=head2 isSubscribed ( [ userId ] )
Returns a boolean indicating whether the user is subscribed to this thread.
=head3 userId
The unique id of the user to check. Defaults to the current user.
=cut
sub isSubscribed {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
my ($isSubscribed) = WebGUI::SQL->quickArray("select count(*) from forumThreadSubscription where forumThreadId=".quote($self->get("forumThreadId"))
." and userId=".quote($userId));
return $isSubscribed;
}
#-------------------------------------------------------------------
=head2 lock ( )
Sets this thread to be locked from edits.
=cut
sub lock {
my ($self) = @_;
$self->set({isLocked=>1});
}
#-------------------------------------------------------------------
=head2 new ( threadId )
Constructor.
=head3 threadId
The unique id of the thread object you wish to retrieve.
=cut
sub new {
my ($class, $forumThreadId) = @_;
my $properties = WebGUI::SQL->getRow("forumThread","forumThreadId",$forumThreadId);
if (defined $properties) {
bless {_properties=>$properties}, $class;
} else {
return undef;
}
}
#-------------------------------------------------------------------
=head2 recalculateRating ( )
Recalculates the average rating of this thread based upon all of the posts in the thread.
=cut
sub recalculateRating {
my ($self) = @_;
my ($count) = WebGUI::SQL->quickArray("select count(*) from forumPost where forumThreadId=".quote($self->get("forumThreadId"))." and rating>0");
$count = $count || 1;
my ($sum) = WebGUI::SQL->quickArray("select sum(rating) from forumPost where forumThreadId=".quote($self->get("forumThreadId"))." and rating>0");
my $average = round($sum/$count);
$self->set({rating=>$average});
$self->getForum->recalculateRating;
}
#-------------------------------------------------------------------
=head2 set ( data )
Sets properties for this thread both to the object and to the database.
=head3 data
A hash reference containing the properties to set. See the forumThread table for details.
=cut
sub set {
my ($self, $data) = @_;
$data->{forumThreadId} = $self->get("forumThreadId") unless ($data->{forumThreadId});
WebGUI::SQL->setRow("forumThread","forumThreadId",$data);
foreach my $key (keys %{$data}) {
$self->{_properties}{$key} = $data->{$key};
}
}
#-------------------------------------------------------------------
=head2 setLastPost ( lastPostDate, lastPostId )
Sets the pertinent details for the last post. Can also be done directly using the set method.
=head3 lastPostDate
The epoch date of the post.
=head3 lastPostId
The unique id of the post.
=cut
sub setLastPost {
my ($self, $postDate, $postId) = @_;
$self->set({
lastPostId=>$postId,
lastPostDate=>$postDate
});
$self->getForum->setLastPost($postDate, $postId);
}
#-------------------------------------------------------------------
=head2 setStatusApproved ( )
Sets the status of this thread to approved.
=cut
sub setStatusApproved {
my ($self) = @_;
$self->set({status=>'approved'});
}
#-------------------------------------------------------------------
=head2 setStatusArchived ( )
Sets the status of this thread to archived.
=cut
sub setStatusArchived {
my ($self) = @_;
$self->set({status=>'archived'});
}
#-------------------------------------------------------------------
=head2 setStatusDeleted ( )
Sets the status of this thread to deleted.
=cut
sub setStatusDeleted {
my ($self) = @_;
$self->set({status=>'deleted'});
$self->getForum->decrementThreads;
}
#-------------------------------------------------------------------
=head2 setStatusDenied ( )
Sets the status of this thread to denied.
=cut
sub setStatusDenied {
my ($self) = @_;
$self->set({status=>'denied'});
}
#-------------------------------------------------------------------
=head2 setStatusPending ( )
Sets the status of this thread to pending.
=cut
sub setStatusPending {
my ($self) = @_;
$self->set({status=>'pending'});
}
#-------------------------------------------------------------------
=head2 stick ( )
Makes this thread sticky.
=cut
sub stick {
my ($self) = @_;
$self->set({isSticky=>1});
}
#-------------------------------------------------------------------
=head2 subscribe ( [ userId ] )
Subscribes the user to this thread.
=head3 userId
The unique id of the user. Defaults to the current user.
=cut
sub subscribe {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
unless ($self->isSubscribed($userId)) {
WebGUI::SQL->write("insert into forumThreadSubscription (forumThreadId, userId) values (".quote($self->get("forumThreadId")).",".quote($userId).")");
}
}
#-------------------------------------------------------------------
=head2 unlock ( )
Negates the lock method.
=cut
sub unlock {
my ($self) = @_;
$self->set({isLocked=>0});
}
#-------------------------------------------------------------------
=head2 unstick ( )
Negates the stick method.
=cut
sub unstick {
my ($self) = @_;
$self->set({isSticky=>0});
}
#-------------------------------------------------------------------
=head2 unsubscribe ( [ userId ] )
Negates the subscribe method.
=head3 userId
The unique id of the user to unsubscribe. Defaults to the current user.
=cut
sub unsubscribe {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
if ($self->isSubscribed($userId)) {
WebGUI::SQL->write("delete from forumThreadSubscription where forumThreadId=".quote($self->get("forumThreadId"))." and userId=".quote($userId));
}
}
1;

File diff suppressed because it is too large Load diff