From d0181c10ba1da74ec8609982c2f2b5ffe993d89e Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 19 Mar 2005 22:47:29 +0000 Subject: [PATCH] couple of last minute bug fixes --- docs/upgrades/upgrade_6.5.2-6.5.3.sql | 2 ++ lib/WebGUI/Asset.pm | 4 +-- lib/WebGUI/Asset/Post/Thread.pm | 10 ++++--- lib/WebGUI/Asset/Wobject/Collaboration.pm | 34 +++++++++++------------ 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/docs/upgrades/upgrade_6.5.2-6.5.3.sql b/docs/upgrades/upgrade_6.5.2-6.5.3.sql index f5cf37d42..3079035dd 100644 --- a/docs/upgrades/upgrade_6.5.2-6.5.3.sql +++ b/docs/upgrades/upgrade_6.5.2-6.5.3.sql @@ -30,4 +30,6 @@ update template set template='\"> \r\n{_next}) { + my $sortBy = $self->getParent->getValue("sortBy"); $self->{_next} = WebGUI::Asset::Post->newByPropertyHashRef( WebGUI::SQL->quickHashRef(" select * @@ -197,12 +198,12 @@ sub getNextThread { where asset.parentId=".quote($self->get("parentId"))." and asset.state='published' and asset.className='WebGUI::Asset::Post::Thread' - and ".$self->getParent->getValue("sortBy").">".quote($self->get($self->getParent->getValue("sortBy")))." + and ".$sortBy.">".quote($self->get($sortBy))." and ( Post.status in ('approved','archived') or (asset.ownerUserId=".quote($session{user}{userId})." and asset.ownerUserId<>'1') ) - order by ".$self->getParent->getValue("sortBy")." asc + order by ".$sortBy." asc ",WebGUI::SQL->getSlave) ); delete $self->{_next} unless ($self->{_next}->{_properties}{className} =~ /Thread/); @@ -223,6 +224,7 @@ Returns a thread object for the previous (older) thread in the same forum. sub getPreviousThread { my $self = shift; unless (exists $self->{_previous}) { + my $sortBy = $self->getParent->getValue("sortBy"); $self->{_previous} = WebGUI::Asset::Post->newByPropertyHashRef( WebGUI::SQL->quickHashRef(" select * from Thread @@ -231,12 +233,12 @@ sub getPreviousThread { where asset.parentId=".quote($self->get("parentId"))." and asset.state='published' and asset.className='WebGUI::Asset::Post::Thread' - and ".$self->getParent->getValue("sortBy")."<".quote($self->get($self->getParent->getValue("sortBy")))." + and ".$sortBy."<".quote($self->get($sortBy))." and ( Post.status in ('approved','archived') or (asset.ownerUserId=".quote($session{user}{userId})." and asset.ownerUserId<>'1') ) - order by ".$self->getParent->getValue("sortBy")." desc ",WebGUI::SQL->getSlave) + order by ".$sortBy." desc ",WebGUI::SQL->getSlave) ); delete $self->{_previous} unless ($self->{_previous}->{_properties}{className} =~ /Thread/); }; diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 7c4220769..562ddfc81 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -811,19 +811,21 @@ sub unsubscribe { sub view { my $self = shift; my $scratchSortBy = $self->getId."_sortBy"; - my $scratchSortDir = $self->getId."_sortDir"; - if($session{scratch}{$scratchSortBy} ne $session{form}{sortBy}){ - WebGUI::Session::setScratch($scratchSortBy,$session{form}{sortBy}); - WebGUI::Session::setScratch($scratchSortDir, "desc"); - }else{ - my $sortDir; - if($session{scratch}{$scratchSortDir} eq "asc"){ - $sortDir = "desc"; - }else{ - $sortDir = "asc"; + my $scratchSortOrder = $self->getId."_sortDir"; + my $sortBy = $session{form}{sortBy} || $session{scratch}{$scratchSortBy} || $self->get("sortBy"); + my $sortOrder = $session{scratch}{$scratchSortOrder} || $self->get("sortOrder"); + if ($sortBy ne $session{scratch}{$scratchSortBy}) { + WebGUI::Session::setScratch($scratchSortBy,$session{form}{sortBy}); + } elsif ($session{form}{sortBy}) { + if ($sortOrder eq "asc") { + $sortOrder = "desc"; + } else { + $sortOrder = "asc"; } - WebGUI::Session::setScratch($scratchSortDir, $sortDir); - } + WebGUI::Session::setScratch($scratchSortOrder, $sortOrder); + } + $sortBy ||= "dateUpdated"; + $sortOrder ||= "desc"; my %var; $var{'user.canPost'} = $self->canPost; $var{"add.url"} = $self->getNewThreadUrl; @@ -834,7 +836,7 @@ sub view { $var{'sortby.title.url'} = $self->getSortByUrl("title"); $var{'sortby.username.url'} = $self->getSortByUrl("username"); $var{'sortby.date.url'} = $self->getSortByUrl("dateSubmitted"); - $var{'sortby.lastreply.url'} = $self->getSortByUrl("lastreply"); + $var{'sortby.lastreply.url'} = $self->getSortByUrl("dateUpdated"); $var{'sortby.views.url'} = $self->getSortByUrl("views"); $var{'sortby.replies.url'} = $self->getSortByUrl("replies"); $var{'sortby.rating.url'} = $self->getSortByUrl("rating"); @@ -847,16 +849,12 @@ sub view { $constraints .= " or Post.status='pending'"; } $constraints .= ")"; - my $sortBy = $self->getValue("sortBy"); - if ($sortBy eq "lastreply") { - $sortBy = "Thread.lastPostDate"; - } my $sql = "select * from Thread left join asset on Thread.assetId=asset.assetId left join Post on Post.assetId=asset.assetId where asset.parentId=".quote($self->getId)." and asset.state='published' and asset.className='WebGUI::Asset::Post::Thread' and $constraints - order by ".$sortBy." ".$self->getValue("sortOrder"); + order by ".$sortBy." ".$sortOrder; my $p = WebGUI::Paginator->new($self->getUrl,$self->get("threadsPerPage")); $self->appendPostListTemplateVars(\%var, $sql, $p); $self->appendTemplateLabels(\%var);