From 53e1afe62009f5ef0e686f3f4f9a4586afe9ea0c Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 18 Sep 2006 12:22:07 +0000 Subject: [PATCH] Functional prev/next links when not at start/end. --- web/htdocs/details/found.mc | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/web/htdocs/details/found.mc b/web/htdocs/details/found.mc index 2d690a9..1a41f91 100644 --- a/web/htdocs/details/found.mc +++ b/web/htdocs/details/found.mc @@ -1,17 +1,19 @@ -%# $Id: found.mc,v 1.1 2006-09-15 16:51:51 mike Exp $ +%# $Id: found.mc,v 1.2 2006-09-18 12:22:07 mike Exp $ <%once> use XML::LibXML; use XML::LibXML::XPathContext; <%perl> +my %params = map { ( $_, $r->param($_)) } $r->param(); my $query = ""; -foreach my $key ($r->param()) { +foreach my $key (keys %params) { next if $key =~ /^_/; - my $val = $r->param($key); + my $val = $params{$key}; next if $val eq ""; $query .= " and " if $query ne ""; $query .= "$key = ($val)"; } +$query = 'cql.allRecords=x' if $query eq ""; ### We can think about keeping the Connection object open to re-use # for multiple requests, but that may not get us much. Same applies @@ -23,8 +25,8 @@ my $parser = new XML::LibXML(); my $rs = $conn->search(new ZOOM::Query::CQL($query)); my $n = $rs->size(); -my $skip = $r->param("_skip") || 0; -my $count = $r->param("_count") || 10; +my $skip = $params{"_skip"} || 0; +my $count = $params{"_count"} || 10; my $first = $skip+1; my $last = $first+$count-1; @@ -36,9 +38,26 @@ $last = $n if $last > $n; % if ($n == 0) { No matches % } elsif ($first > $n) { +%# "Can't happen" Past end of <% $n %> records % } else { - Records <% $first %> to <% $last %> of <% $n %> + Records <% $first %> to <% $last %> of <% $n %>
+<%perl> +if ($skip > 0) { + $params{_skip} = $count < $skip ? $skip-$count : 0; + my $prev = "?" . join("&", map { "$_=" . $params{$_} } sort keys %params); + print qq[ Prev\n]; +} else { + print qq[ Prev\n]; +} +if ($last < $n) { + $params{_skip} = $skip+$count; + my $next = "?" . join("&", map { "$_=" . $params{$_} } sort keys %params); + print qq[ Next\n]; +} else { + print qq[ Next\n]; +} + % }

% if ($n > 0 && $first <= $n) { -- 1.7.10.4