3 # Copyright 2000-2002 Katipo Communications
4 # Parts copyright 2010 Nelsonville Public Library
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
32 use POSIX
qw(ceil floor strftime);
36 my $format = $query->param("format") || '';
37 my $count = C4
::Context
->preference('OPACnumSearchResults') || 20;
38 my $results_per_page = $query->param('count') || $count;
39 my $offset = $query->param('offset') || 0;
40 my $page = floor
( $offset / $results_per_page ) + 1;
42 if ($format eq "rss") {
43 $template_name = "opac-showreviews-rss.tt";
45 $template_name = "opac-showreviews.tt",
48 my ( $template, $borrowernumber, $cookie ) = &get_template_and_user
(
50 template_name
=> $template_name,
53 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
58 my $lastbuilddate = dt_from_string
;
59 my $lastbuilddate_output = $lastbuilddate->strftime("%a, %d %b %Y %H:%M:%S %z");
62 timestamp
=> $lastbuilddate_output
66 my $libravatar_enabled = 0;
67 if ( C4
::Context
->preference('ShowReviewer') and C4
::Context
->preference('ShowReviewerPhoto')) {
69 require Libravatar
::URL
;
70 Libravatar
::URL
->import();
73 $libravatar_enabled = 1;
77 my $reviews = Koha
::Reviews
->search(
80 rows
=> $results_per_page,
82 order_by
=> { -desc
=> 'datereviewed' },
85 my $marcflavour = C4
::Context
->preference("marcflavour");
86 my $hits = Koha
::Reviews
->search({ approved
=> 1 })->count;
88 for my $result (@
$reviews){
89 my $biblionumber = $result->{biblionumber
};
90 my $biblio = Koha
::Biblios
->find( $biblionumber );
91 my $biblioitem = $biblio->biblioitem;
92 my $record = GetMarcBiblio
({ biblionumber
=> $biblionumber });
93 $result->{normalized_upc
} = GetNormalizedUPC
($record,$marcflavour);
94 $result->{normalized_ean
} = GetNormalizedEAN
($record,$marcflavour);
95 $result->{normalized_oclc
} = GetNormalizedOCLCNumber
($record,$marcflavour);
96 $result->{normalized_isbn
} = GetNormalizedISBN
(undef,$record,$marcflavour);
97 $result->{title
} = $biblio->title;
98 $result->{subtitle
} = $biblio->subtitle;
99 $result->{medium
} = $biblio->medium;
100 $result->{part_number
} = $biblio->part_number;
101 $result->{part_name
} = $biblio->part_name;
102 $result->{author
} = $biblio->author;
103 $result->{place
} = $biblioitem->place;
104 $result->{publishercode
} = $biblioitem->publishercode;
105 $result->{copyrightdate
} = $biblio->copyrightdate;
106 $result->{pages
} = $biblioitem->pages;
107 $result->{size
} = $biblioitem->size;
108 $result->{notes
} = $biblioitem->notes;
109 $result->{timestamp
} = $biblioitem->timestamp;
111 $result->{biblio_object
} = $biblio; # TODO Use this variable directly in the template
113 my $patron = Koha
::Patrons
->find( $result->{borrowernumber
} );
115 $result->{borrtitle
} = $patron->title;
116 $result->{firstname
} = $patron->firstname;
117 $result->{surname
} = $patron->surname;
118 $result->{userid
} = $patron->userid;
119 if ($libravatar_enabled and $patron->email) {
120 $result->{avatarurl
} = libravatar_url
(email
=> $patron->email, size
=> 40, https
=> $ENV{HTTPS
});
123 if ($result->{borrowernumber
} eq $borrowernumber) {
124 $result->{your_comment
} = 1;
128 if($format eq "rss"){
129 my $rsstimestamp = eval { dt_from_string
( $result->{datereviewed
} ); };
130 $rsstimestamp = dt_from_string
unless ( $rsstimestamp ); #default to today if something went wrong
131 my $rsstimestamp_output = $rsstimestamp->strftime("%a, %d %b %Y %H:%M:%S %z");
132 $result->{timestamp
} = $rsstimestamp_output;
135 ## Build the page numbers on the bottom of the page
137 my $previous_page_first;
138 my $previous_page_offset;
139 # total number of pages there will be
140 my $pages = ceil
($hits / $results_per_page);
141 # default page number
142 my $current_page_number = 1;
143 $current_page_number = ($offset / $results_per_page + 1) if $offset;
144 if($offset - $results_per_page == 0){
145 $previous_page_first = 1;
146 } elsif ($offset - $results_per_page > 0){
147 $previous_page_offset = $offset - $results_per_page;
149 my $next_page_offset = $offset + $results_per_page;
150 # If we're within the first 10 pages, keep it simple
151 if ($current_page_number < 10) {
152 # just show the first 10 pages
153 # Loop through the pages
154 my $pages_to_show = 10;
155 $pages_to_show = $pages if $pages<10;
156 for ($i=1; $i<=$pages_to_show;$i++) {
157 # the offset for this page
158 my $this_offset = (($i*$results_per_page)-$results_per_page);
159 # the page number for this page
160 my $this_page_number = $i;
161 # it should only be highlighted if it's the current page
163 $highlight = 1 if ($this_page_number == $current_page_number);
164 # put it in the array
165 push @page_numbers, { offset
=> $this_offset, pg
=> $this_page_number, highlight
=> $highlight };
170 # now, show twenty pages, with the current one smack in the middle
172 for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
173 my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
174 my $this_page_number = $i-9;
176 $highlight = 1 if ($this_page_number == $current_page_number);
177 if ($this_page_number <= $pages) {
178 push @page_numbers, { offset
=> $this_offset, pg
=> $this_page_number, highlight
=> $highlight };
182 $template->param( PAGE_NUMBERS
=> \
@page_numbers,
183 previous_page_first
=> $previous_page_first,
184 previous_page_offset
=> $previous_page_offset) unless $pages < 2;
185 $template->param(next_page_offset
=> $next_page_offset) unless $pages eq $current_page_number;
189 results_per_page
=> $results_per_page,
192 output_html_with_http_headers
$query, $cookie, $template->output;