Fix thread search URLs when threads are archived, or trashed. Location in the pagination is now found by interrupted linear search.
This commit is contained in:
parent
90cd1ac257
commit
a7b4fbc0ed
3 changed files with 99 additions and 59 deletions
|
|
@ -349,20 +349,46 @@ for the site.
|
|||
=cut
|
||||
|
||||
sub getCSLinkUrl {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
if ($self->get('status') eq 'archived') {
|
||||
return $self->get('url');
|
||||
}
|
||||
my $session = $self->session;
|
||||
my $url;
|
||||
my $cs = $self->getParent;
|
||||
my $paginator = WebGUI::Paginator->new($self->session, '', $self->getParent->get('threadsPerPage'));
|
||||
my $page_size = $paginator->{_rpp}; ##To make sure defaults are handled correctly.
|
||||
my $place = $self->getRank+1;
|
||||
my $last_place = $cs->getLastChild->getRank+1;
|
||||
my $page = int(($last_place - $place)/$page_size) + 1;
|
||||
my $page_size = $cs->get('threadsPerPage');
|
||||
my $sql =<<EOSQL;
|
||||
select lineage from asset
|
||||
left join Thread using (assetId)
|
||||
left join assetData using (assetId)
|
||||
where parentId=?
|
||||
and className='WebGUI::Asset::Post::Thread'
|
||||
and state='published'
|
||||
and status='approved'
|
||||
group by assetData.assetId
|
||||
order by Thread.isSticky DESC,
|
||||
lineage DESC
|
||||
EOSQL
|
||||
|
||||
my $sth = $session->db->read($sql, [$cs->getId]);
|
||||
my $place = 1; ##1 based indexing
|
||||
my $found = 0;
|
||||
my $lineage = $self->get('lineage');
|
||||
THREAD: while (my $arrayRef = $sth->arrayRef) {
|
||||
if ($arrayRef->[0] eq $lineage) {
|
||||
$found = 1;
|
||||
last THREAD;
|
||||
}
|
||||
++$place;
|
||||
}
|
||||
$sth->finish;
|
||||
return $self->get('url') if !$found;
|
||||
my $page = int($place/$page_size) + 1;
|
||||
my $page_frag = 'pn='.$page.';sortBy=lineage;sortOrder=desc';
|
||||
$url = $self->session->url->append($cs->get('url'), $page_frag);
|
||||
$url = $session->url->append($cs->get('url'), $page_frag);
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getThreadLinkUrl ( )
|
||||
|
|
|
|||
|
|
@ -1159,66 +1159,68 @@ Collaboration System
|
|||
=cut
|
||||
|
||||
sub getThreadsPaginator {
|
||||
my $self = shift;
|
||||
|
||||
my $self = shift;
|
||||
|
||||
my $scratchSortBy = $self->getId."_sortBy";
|
||||
my $scratchSortOrder = $self->getId."_sortDir";
|
||||
my $sortBy = $self->session->form->process("sortBy")
|
||||
my $scratchSortOrder = $self->getId."_sortDir";
|
||||
my $sortBy = $self->session->form->process("sortBy")
|
||||
|| $self->session->scratch->get($scratchSortBy)
|
||||
|| $self->get("sortBy");
|
||||
my $sortOrder = $self->session->form->process("sortOrder")
|
||||
|| $self->session->scratch->get($scratchSortOrder)
|
||||
|| $self->get("sortOrder");
|
||||
if ($sortBy ne $self->session->scratch->get($scratchSortBy) && $self->session->form->process("func") ne "editSave") {
|
||||
$self->session->scratch->set($scratchSortBy,$self->session->form->process("sortBy"));
|
||||
if ($sortBy ne $self->session->scratch->get($scratchSortBy) && $self->session->form->process("func") ne "editSave") {
|
||||
$self->session->scratch->set($scratchSortBy,$self->session->form->process("sortBy"));
|
||||
$self->session->scratch->set($scratchSortOrder, $sortOrder);
|
||||
} elsif ($self->session->form->process("sortBy") && $self->session->form->process("func") ne "editSave") {
|
||||
if ($sortOrder eq "asc") {
|
||||
$sortOrder = "desc";
|
||||
} else {
|
||||
$sortOrder = "asc";
|
||||
}
|
||||
$self->session->scratch->set($scratchSortOrder, $sortOrder);
|
||||
}
|
||||
$sortBy ||= "assetData.revisionDate";
|
||||
$sortOrder ||= "desc";
|
||||
}
|
||||
elsif ($self->session->form->process("sortBy") && $self->session->form->process("func") ne "editSave") {
|
||||
if ($sortOrder eq "asc") {
|
||||
$sortOrder = "desc";
|
||||
}
|
||||
else {
|
||||
$sortOrder = "asc";
|
||||
}
|
||||
$self->session->scratch->set($scratchSortOrder, $sortOrder);
|
||||
}
|
||||
$sortBy ||= "assetData.revisionDate";
|
||||
$sortOrder ||= "desc";
|
||||
# Sort by the thread rating instead of the post rating. other places don't care about threads.
|
||||
if ($sortBy eq 'rating') {
|
||||
$sortBy = 'threadRating';
|
||||
}
|
||||
$sortBy = join('.', map { $self->session->db->dbh->quote_identifier($_) } split(/\./, $sortBy));
|
||||
|
||||
my $sql = "
|
||||
select
|
||||
asset.assetId,
|
||||
asset.className,
|
||||
assetData.revisionDate as revisionDate
|
||||
from Thread
|
||||
left join asset on Thread.assetId=asset.assetId
|
||||
left join Post on Post.assetId=Thread.assetId and Thread.revisionDate = Post.revisionDate
|
||||
left join assetData on assetData.assetId=Thread.assetId and Thread.revisionDate = assetData.revisionDate
|
||||
where
|
||||
asset.parentId=".$self->session->db->quote($self->getId)."
|
||||
and asset.state='published'
|
||||
and asset.className='WebGUI::Asset::Post::Thread'
|
||||
and assetData.revisionDate=(
|
||||
select
|
||||
max(revisionDate)
|
||||
from
|
||||
assetData
|
||||
where
|
||||
assetData.assetId=asset.assetId
|
||||
and (status='approved' or status='archived')
|
||||
)
|
||||
and status='approved'
|
||||
group by
|
||||
assetData.assetId
|
||||
order by
|
||||
Thread.isSticky desc,
|
||||
".$sortBy."
|
||||
".$sortOrder;
|
||||
my $p = WebGUI::Paginator->new($self->session,$self->getUrl,$self->get("threadsPerPage"));
|
||||
$p->setDataByQuery($sql);
|
||||
my $sql = "
|
||||
select
|
||||
asset.assetId,
|
||||
asset.className,
|
||||
assetData.revisionDate as revisionDate
|
||||
from Thread
|
||||
left join asset on Thread.assetId=asset.assetId
|
||||
left join Post on Post.assetId=Thread.assetId and Thread.revisionDate = Post.revisionDate
|
||||
left join assetData on assetData.assetId=Thread.assetId and Thread.revisionDate = assetData.revisionDate
|
||||
where
|
||||
asset.parentId=".$self->session->db->quote($self->getId)."
|
||||
and asset.state='published'
|
||||
and asset.className='WebGUI::Asset::Post::Thread'
|
||||
and assetData.revisionDate=(
|
||||
select
|
||||
max(revisionDate)
|
||||
from
|
||||
assetData
|
||||
where
|
||||
assetData.assetId=asset.assetId
|
||||
and (status='approved' or status='archived')
|
||||
)
|
||||
and status='approved'
|
||||
group by
|
||||
assetData.assetId
|
||||
order by
|
||||
Thread.isSticky desc,
|
||||
".$sortBy."
|
||||
".$sortOrder;
|
||||
my $p = WebGUI::Paginator->new($self->session,$self->getUrl,$self->get("threadsPerPage"));
|
||||
$p->setDataByQuery($sql);
|
||||
|
||||
return $p;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue