adding POD
This commit is contained in:
parent
c105522d86
commit
83db4d0e95
3 changed files with 553 additions and 6 deletions
|
|
@ -28,8 +28,28 @@ Data management class for forum posts.
|
|||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Forum::Post;
|
||||
$forum = WebGUI::Forum::Post->create(\%params);
|
||||
$forum = WebGUI::Forum::Post->new($postId);
|
||||
$post = WebGUI::Forum::Post->create(\%params);
|
||||
$post = WebGUI::Forum::Post->new($postId);
|
||||
|
||||
$boolean = $post->canEdit;
|
||||
$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
|
||||
|
||||
|
|
@ -187,12 +207,36 @@ sub hasRated {
|
|||
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=".$self->get("forumPostId"));
|
||||
$self->getThread->incrementViews;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isMarkedRead ( [ userId ] )
|
||||
|
||||
Returns a boolean indicating whether this post is marked read for the user.
|
||||
|
||||
=over
|
||||
|
||||
=item userId
|
||||
|
||||
A unique id for a user that you want to check. Defaults to the current user.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub isMarkedRead {
|
||||
my ($self, $userId) = @_;
|
||||
$userId = $session{user}{userId} unless ($userId);
|
||||
|
|
@ -200,6 +244,14 @@ sub isMarkedRead {
|
|||
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") > 0) {
|
||||
|
|
@ -209,6 +261,22 @@ sub isReply {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 markRead ( [ userId ] )
|
||||
|
||||
Marks this post read for this user.
|
||||
|
||||
=over
|
||||
|
||||
=item userId
|
||||
|
||||
A unique identifier for a user. Defaults to the current user.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub markRead {
|
||||
my ($self, $userId) = @_;
|
||||
$userId = $session{user}{userId} unless ($userId);
|
||||
|
|
@ -219,6 +287,22 @@ sub markRead {
|
|||
$self->incrementViews;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( postId )
|
||||
|
||||
Constructor.
|
||||
|
||||
=over
|
||||
|
||||
=item postId
|
||||
|
||||
The unique identifier for the post object you wish to retrieve.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ($class, $forumPostId) = @_;
|
||||
my $properties = WebGUI::SQL->getRow("forumPost","forumPostId",$forumPostId);
|
||||
|
|
@ -229,6 +313,30 @@ sub new {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 rate ( rating [ , userId, ipAddress ] )
|
||||
|
||||
Stores a rating against this post.
|
||||
|
||||
=over
|
||||
|
||||
=item rating
|
||||
|
||||
An integer between 1 and 5 (5 being best) to rate this post with.
|
||||
|
||||
=item userId
|
||||
|
||||
The unique id for the user rating this post. Defaults to the current user.
|
||||
|
||||
=item ipAddress
|
||||
|
||||
The ip address of the user doing the rating. Defaults to the current user's IP.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub rate {
|
||||
my ($self, $rating, $userId, $ipAddress) = @_;
|
||||
$userId = $session{user}{userId} unless ($userId);
|
||||
|
|
@ -238,6 +346,14 @@ sub rate {
|
|||
$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=".$self->get("forumPostId"));
|
||||
|
|
@ -248,6 +364,23 @@ sub recalculateRating {
|
|||
$self->getThread->recalculateRating;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 set ( data )
|
||||
|
||||
Sets properties to the database and the object.
|
||||
|
||||
=over
|
||||
|
||||
=item data
|
||||
|
||||
A hash reference containing the properties to set. See the forumPost table for details.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
sub set {
|
||||
my ($self, $data) = @_;
|
||||
$data->{forumPostId} = $self->get("forumPostId") unless ($data->{forumPostId});
|
||||
|
|
@ -257,6 +390,15 @@ sub set {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 setStatusApproved ( )
|
||||
|
||||
Sets the status of this post to approved.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
sub setStatusApproved {
|
||||
my ($self) = @_;
|
||||
$self->set({status=>'approved'});
|
||||
|
|
@ -266,6 +408,32 @@ sub setStatusApproved {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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") == $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'});
|
||||
|
|
@ -273,22 +441,55 @@ sub setStatusDeleted {
|
|||
if ($self->getThread->get("lastPostId") == $self->get("forumPostId")) {
|
||||
my ($id, $date) = WebGUI::SQL->quickArray("select forumPostId,dateOfPost from forumPost where forumThreadId="
|
||||
.$self->get("forumThreadId")." and status='approved'");
|
||||
$self->getThread->setLastPost($id,$date);
|
||||
$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") == $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") == $self->get("forumPostId"));
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 unmarkRead ( [ userId ] )
|
||||
|
||||
Negates the markRead method.
|
||||
|
||||
=over
|
||||
|
||||
=item userId
|
||||
|
||||
The unique id of the user marking unread. Defaults to the current user.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub unmarkRead {
|
||||
my ($self, $userId) = @_;
|
||||
$userId = $session{user}{userId} unless ($userId);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue