fixed a lot o bugs

This commit is contained in:
JT Smith 2003-11-18 06:19:36 +00:00
parent f2584fe07b
commit d150016395
6 changed files with 173 additions and 88 deletions

View file

@ -32,6 +32,7 @@ Data management class for forum posts.
$post = WebGUI::Forum::Post->new($postId);
$boolean = $post->canEdit;
$boolean = $post->canView;
$scalar = $post->get("forumPostId");
$arrayRef = $post->getReplies;
$obj = $post->getThread;
@ -82,6 +83,36 @@ sub canEdit {
#-------------------------------------------------------------------
=head2 canView ( [ userId ] )
Returns a boolean indicating whether the user can view the current post.
=over
=item userId
The unique identifier to check privileges against. Defaults to the current user.
=back
=cut
sub canView {
my ($self, $userId) = @_;
$userId = $session{user}{userId} unless ($userId);
if ($self->get("status") eq "deleted") {
return 0;
} elsif ($self->get("status") eq "denied" && $userId == $self->get("userId")) {
return 1;
} elsif ($self->getThread->getForum->isModerator) {
return 1;
} else {
return 0;
}
}
#-------------------------------------------------------------------
=head2 create ( [ data ] )
Creates a new post.
@ -432,6 +463,7 @@ Sets the status of this post to deleted.
sub setStatusDeleted {
my ($self) = @_;
$self->set({status=>'deleted'});
$self->getThread->decrementReplies;
$self->getThread->setStatusDeleted if ($self->getThread->get("rootPostId") == $self->get("forumPostId"));
if ($self->getThread->get("lastPostId") == $self->get("forumPostId")) {
my ($id, $date) = WebGUI::SQL->quickArray("select forumPostId,dateOfPost from forumPost where forumThreadId="

View file

@ -41,6 +41,7 @@ Data management class for forum threads.
$boolean = $thread->isSticky;
$boolean = $thread->isSubscribed;
$thread->decrementReplies;
$thread->incrementReplies($postDate, $postId);
$thread->incrementViews;
$thread->lock;
@ -103,6 +104,20 @@ sub create {
#-------------------------------------------------------------------
=head2 decrementReplies ( )
Decrements the replies counter for this thread.
=cut
sub deccrementReplies {
my ($self) = @_;
WebGUI::SQL->write("update forumThread set replies=replies-1 where forumThreadId=".$self->get("forumThreadId"));
$self->getForum->decrementReplies;
}
#-------------------------------------------------------------------
=head2 get ( [ param ] )
Returns a hash reference containing all the properties of this thread.
@ -439,6 +454,7 @@ Sets the status of this thread to deleted.
sub setStatusDeleted {
my ($self) = @_;
$self->set({status=>'deleted'});
$self->getForum->decrementThreads;
}
#-------------------------------------------------------------------

View file

@ -26,6 +26,7 @@ use WebGUI::MessageLog;
use WebGUI::Search;
use WebGUI::Session;
use WebGUI::Template;
use WebGUI::User;
=head1 DESCRIPTION
@ -1273,7 +1274,7 @@ sub getThreadTemplateVars {
my $callback = $caller->{callback};
$post->markRead($session{user}{userId});
my $thread = $post->getThread;
if (($post->get("status") eq "denied" && $session{user}{userId} != $post->get("userId")) || $post->get("status") eq "deleted") {
unless ($post->canView) {
$post = $thread->getPost($thread->get("rootPostId"));
}
my $forum = $thread->getForum;
@ -1370,16 +1371,16 @@ sub notifySubscribers {
my %lang;
foreach my $userId (keys %subscribers) {
my $u = WebGUI::User->new($userId);
unless (exists $lang{$u->get("language")}) {
$lang{$u->get("language")}{var} = {
'notify.subscription.message' => WebGUI::International::get(875,$u->get("language"))
unless (exists $lang{$u->profileField("language")}) {
$lang{$u->profileField("language")}{var} = {
'notify.subscription.message' => WebGUI::International::get(875,$u->profileField("language"))
};
$lang{$u->get("language")}{var} = getPostTemplateVars($post, $thread, $forum, $caller, $lang{$u->get("language")}{var});
$lang{$u->get("language")}{subject} = WebGUI::International::get(523,$u->get("language"));
$lang{$u->get("language")}{message} = WebGUI::Template::process(WebGUI::Template::get($forum->get("notificationTemplateId"),"Forum/Notification"),
$lang{$u->get("language")}{var});
$lang{$u->profileField("language")}{var} = getPostTemplateVars($post, $thread, $forum, $caller, $lang{$u->profileField("language")}{var});
$lang{$u->profileField("language")}{subject} = WebGUI::International::get(523,$u->profileField("language"));
$lang{$u->profileField("language")}{message} = WebGUI::Template::process(WebGUI::Template::get($forum->get("notificationTemplateId"),"Forum/Notification"),
$lang{$u->profileField("language")}{var});
}
WebGUI::MessageLog::addEntry($userId,"",$lang{$u->get("language")}{subject},$lang{$u->get("language")}{message});
WebGUI::MessageLog::addEntry($userId,"",$lang{$u->profileField("language")}{subject},$lang{$u->profileField("language")}{message});
}
}
@ -1426,15 +1427,17 @@ sub recurseThread {
push(@depth_loop,{depth=>$i});
}
my @post_loop;
push (@post_loop, getPostTemplateVars($post, $thread, $forum, $caller, {
'post.indent_loop'=>\@depth_loop,
'post.indent.depth'=>$depth,
'post.isCurrent'=>($currentPost == $post->get("forumPostId"))
}));
my $replies = $post->getReplies;
foreach my $reply (@{$replies}) {
@post_loop = (@post_loop,@{recurseThread($reply, $thread, $forum, $depth+1, $caller, $currentPost)});
}
if ($post->canView) {
push (@post_loop, getPostTemplateVars($post, $thread, $forum, $caller, {
'post.indent_loop'=>\@depth_loop,
'post.indent.depth'=>$depth,
'post.isCurrent'=>($currentPost == $post->get("forumPostId"))
}));
my $replies = $post->getReplies;
foreach my $reply (@{$replies}) {
@post_loop = (@post_loop,@{recurseThread($reply, $thread, $forum, $depth+1, $caller, $currentPost)});
}
}
return \@post_loop;
}
@ -2071,9 +2074,12 @@ sub www_search {
$var{'post.subject.label'} = WebGUI::International::get(229);
$var{'post.date.label'} = WebGUI::International::get(245);
$var{'post.user.label'} = WebGUI::International::get(244);
my $query = "select forumPostId,subject,userId,username,dateOfPost from forumPost where (status='approved' or status='archived') and ";
$query .= WebGUI::Search::buildConstraints([qw(subject username message)]);
my $p = WebGUI::Paginator->new(WebGUI::URL::append($caller->{callback},"forumOp=search&doit=1&forumId=".$forum->get("forumId")),"", $numResults);
my $query = "select a.forumPostId, a.subject, a.userId, a.username, a.dateOfPost from forumPost a left join forumThread b
on a.forumThreadId=b.forumThreadId where b.forumId=".$forum->get("forumId")." and
(a.status='approved' or a.status='archived') and ".WebGUI::Search::buildConstraints([qw(a.subject a.username a.message)])
." order by a.dateOfPost desc";
my $p = WebGUI::Paginator->new(WebGUI::URL::append($caller->{callback},"forumOp=search&doit=1&forumId=".$forum->get("forumId")),
"", $numResults);
$p->setDataByQuery($query);
my @post_loop;
foreach my $row (@{$p->getPageData}) {
@ -2299,7 +2305,7 @@ sub www_viewThread {
$postId = $session{form}{forumPostId} unless ($postId);
my $post = WebGUI::Forum::Post->new($postId);
my $var = getThreadTemplateVars($caller, $post);
if (($post->get("forumPostId") == $post->getThread->get("rootPostId") && $post->get("status") eq "denied" && $session{user}{userId} != $post->get("userId")) || $post->get("status") eq "deleted") {
if ($post->get("forumPostId") == $post->getThread->get("rootPostId") && !$post->canView) {
return www_viewForum($caller, $post->getThread->getForum->get("forumId"));
} else {
return WebGUI::Template::process(WebGUI::Template::get($post->getThread->getForum->get("threadTemplateId"),"Forum/Thread"), $var);