\n\n --- (".$i18n->get('Edited_on')." ".$self->session->datetime->epochToHuman(undef,"%z %Z [GMT%O]")." ".$i18n->get('By')." ".$self->session->user->get("alias").") --- \n
"; } $data{url} = $self->fixUrl($self->getThread->url."/1") if ($self->isReply && $self->isNew); $data{groupIdView} = $self->getThread->getParent->groupIdView; $data{groupIdEdit} = $self->getThread->getParent->groupIdEdit; $self->update(\%data); my $size = 0; my $storage = $self->getStorageLocation; foreach my $file (@{$storage->getFiles}) { if ($storage->isImage($file)) { $storage->adjustMaxImageSize($file, $self->getThread->getParent->maxImageSize); $storage->generateThumbnail($file, $self->getThread->getParent->thumbnailSize); } $size += $storage->getFileSize($file); } $self->setSize($size); } #------------------------------------------------------------------- =head2 publish Extend the base method to handle updating last post information in the parent Thread and CS. =cut sub publish { my $self = shift; $self->next::method(@_); $self->qualifyAsLastPost; return 1; } #------------------------------------------------------------------- =head2 purge Extend the base method to handle cleaning up storage locations. =cut override purge => sub { my $self = shift; my $purged = super(); if ($purged) { my $sth = $self->session->db->read("select storageId from Post where assetId=?",[$self->getId]); while (my ($storageId) = $sth->array) { my $storage = WebGUI::Storage->get($self->session, $storageId); $storage->delete if defined $storage; } $sth->finish; $self->disqualifyAsLastPost; } return super(); }; #------------------------------------------------------------------- =head2 purgeCache ( ) Extend the base class to handle caching. =cut override purgeCache => sub { my $self = shift; $self->session->cache->remove("view_".$self->getThread->getId) if ($self->getThread); super(); delete $self->{_thread}; }; #------------------------------------------------------------------- =head2 purgeRevision Extend the base method to handle deleting the storage location. =cut override purgeRevision => sub { my $self = shift; $self->getStorageLocation->delete; return super(); }; #------------------------------------------------------------------- =head2 qualifyAsLastPost ( ) This method should be called whenever something happens to the Post or Thread that would qualify it as being the last post in a Thread, or Collaboration System. Good examples are pasting from the clipboard, restoring from the trash, or changing the state from archiving. It checks the parent Thread and CS to see if it is now the last Post, and updates that asset with its information. =cut sub qualifyAsLastPost { my ($self) = @_; my $thread = $self->getThread(); if ($self->get('creationDate') > $thread->get('lastPostDate')) { $thread->update({ lastPostId => $self->getId, lastPostDate => $self->get('creationDate'), }); } my $cs = $thread->getParent; if ($self->get('creationDate') > $cs->get('lastPostDate')) { $cs->update({ lastPostId => $self->getId, lastPostDate => $self->get('creationDate'), }); } } #------------------------------------------------------------------- =head2 rate ( rating ) Stores a rating against this post. =head3 rating An integer indicating either thumbss up (+1) or thumbs down (-1) =cut sub rate { my $self = shift; my $rating = shift; return undef unless ($rating == -1 || $rating == 1); return undef if $self->hasRated; my $session = $self->session; $self->insertUserPostRating($rating); $self->recalculatePostRating(); my $thread = $self->getThread; $thread->updateThreadRating(); if ($session->setting->get("useKarma") && $session->user->karma > $thread->getParent->karmaSpentToRate) { $session->user->karma(-$thread->getParent->karmaSpentToRate, "Rated Post ".$self->getId, "Rated a CS Post."); my $u = WebGUI::User->new($session, $self->ownerUserId); $u->karma($thread->getParent->karmaRatingMultiplier, "Post ".$self->getId." Rated by ".$session->user->userId, "Had post rated."); } } #------------------------------------------------------------------- =head2 recalculatePostRating ( ) Sum all the entries for this post from the ratings table and update its composite rating. =cut sub recalculatePostRating { my $self = shift; my ($sum) = $self->session->db->quickArray("select sum(rating) from Post_rating where assetId=?", [$self->getId]); $self->update({rating=>$sum}); } #------------------------------------------------------------------- =head2 restore Extend the base class to also make the thread containing this post to recalculate its replies and the thread rating. =cut override restore => sub { my $self = shift; super(); $self->getThread->sumReplies; $self->getThread->updateThreadRating; }; #------------------------------------------------------------------- =head2 rethreadUnder ($thread) Update the Post's threadId property with a new thread. =head3 $thread The new thread. =cut sub rethreadUnder { my $self = shift; my $thread = shift; $self->update({threadId => $thread->getId}); delete $self->{_thread}; } #------------------------------------------------------------------- =head2 setParent ( newParent ) We're overloading the setParent in Asset because we don't want posts to be able to be posted to anything other than other posts or threads. =head3 newParent An asset object to make the parent of this asset. =cut override setParent => sub { my $self = shift; my $newParent = shift; return 0 unless ($newParent->isa('WebGUI::Asset::Post')); return super(); }; #------------------------------------------------------------------- =head2 setStatusArchived ( ) Sets the status of this post to archived. Updates the parent thread and CS to remove the lastPost, if this post is the last post. =cut sub setStatusArchived { my ($self) = @_; $self->update({status=>'archived'}); $self->disqualifyAsLastPost; } #------------------------------------------------------------------- =head2 setStatusUnarchived ( ) Sets the status of this post to approved, but does so without any of the normal notifications and other stuff. Updates the last post information in the parent Thread and CS if applicable. =cut sub setStatusUnarchived { my ($self) = @_; $self->update({status=>'approved'}) if ($self->status eq "archived"); $self->qualifyAsLastPost; } #------------------------------------------------------------------- =head2 trash ( ) Moves post to the trash, updates reply counter on thread, recalculates the thread rating, and updates any lastPost information in the parent Thread, and CS. =cut override trash => sub { my $self = shift; super(); $self->getThread->sumReplies if ($self->isReply); $self->getThread->updateThreadRating; $self->disqualifyAsLastPost; }; #------------------------------------------------------------------- =head2 prepareView Extend the base method to also prepare the Thread containing this Post. =cut override prepareView => sub { my $self = shift; super(); unless ($self->getThread->getId eq $self->getId) { # Need the unless to avoid infinite recursion. $self->getThread->prepareView; } }; #------------------------------------------------------------------- =head2 valid_parent_classes Make sure that the current session asset is a Thread or Post for pasting and adding checks. Technically, we really only need WebGUI::Asset::Post, but it drives some testing code crazy so we explicitly list Thread, too. =cut sub valid_parent_classes { my $class = shift; my $session = shift; return [qw/WebGUI::Asset::Post::Thread WebGUI::Asset::Post/]; } #------------------------------------------------------------------- =head2 view Increment the number of views for this Post, and then display the Thread containing this Post. =cut sub view { my $self = shift; $self->incrementViews; return $self->getThread->view($self); } #------------------------------------------------------------------- =head2 www_deleteFile Deletes the file given by the form variable C