@@ -, +, @@
C4::Circulation
---
C4/Circulation.pm | 61 +++++++++++++++++++
.../bootstrap/en/modules/opac-topissues.tt | 53 ++++++++--------
opac/opac-topissues.pl | 71 ++++------------------
3 files changed, 100 insertions(+), 85 deletions(-)
--- a/C4/Circulation.pm
+++ a/C4/Circulation.pm
@@ -95,6 +95,7 @@ BEGIN {
&AnonymiseIssueHistory
&CheckIfIssuedToPatron
&IsItemIssued
+ GetTopIssues
);
# subs to deal with returns
@@ -4037,6 +4038,66 @@ sub GetPendingOnSiteCheckouts {
|, { Slice => {} } );
}
+sub GetTopIssues {
+ my ($params) = @_;
+
+ my ($count, $branch, $itemtype, $ccode, $newness)
+ = @$params{qw(count branch itemtype ccode newness)};
+
+ my $dbh = C4::Context->dbh;
+ my $query = q{
+ SELECT b.biblionumber, b.title, b.author, bi.itemtype, bi.publishercode,
+ bi.place, bi.publicationyear, b.copyrightdate, bi.pages, bi.size,
+ i.ccode, SUM(i.issues) AS count
+ FROM biblio b
+ LEFT JOIN items i ON (i.biblionumber = b.biblionumber)
+ LEFT JOIN biblioitems bi ON (bi.biblionumber = b.biblionumber)
+ };
+
+ my (@where_strs, @where_args);
+
+ if ($branch) {
+ push @where_strs, 'i.homebranch = ?';
+ push @where_args, $branch;
+ }
+ if ($itemtype) {
+ if (C4::Context->preference('item-level_itypes')){
+ push @where_strs, 'i.itype = ?';
+ push @where_args, $itemtype;
+ } else {
+ push @where_strs, 'bi.itemtype = ?';
+ push @where_args, $itemtype;
+ }
+ }
+ if ($ccode) {
+ push @where_strs, 'i.ccode = ?';
+ push @where_args, $ccode;
+ }
+ if ($newness) {
+ push @where_strs, 'TO_DAYS(NOW()) - TO_DAYS(b.datecreated) <= ?';
+ push @where_args, $newness;
+ }
+
+ if (@where_strs) {
+ $query .= 'WHERE ' . join(' AND ', @where_strs);
+ }
+
+ $query .= q{
+ GROUP BY b.biblionumber
+ HAVING count > 0
+ ORDER BY count DESC
+ };
+
+ $count = int($count);
+ if ($count > 0) {
+ $query .= "LIMIT $count";
+ }
+
+ my $rows = $dbh->selectall_arrayref($query, { Slice => {} }, @where_args);
+
+ return @$rows;
+}
+
__END__
=head1 AUTHOR
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt
+++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt
@@ -1,4 +1,6 @@
[% USE Koha %]
+[% USE AuthorisedValues %]
+[% USE ItemTypes %]
[% INCLUDE 'doc-head-open.inc' %]
[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Most popular titles
[% INCLUDE 'doc-head-close.inc' %]
@@ -20,7 +22,7 @@
- [% IF ( results_loop ) %]
+ [% IF ( results ) %]
[% INCLUDE 'opac-topissues.inc' %]
[% IF ( OpacNav || OpacNavBottom ) %]
@@ -38,7 +40,7 @@
- [% IF ( results_loop ) %]
+ [% IF ( results ) %]
The [% limit %] most checked-out
@@ -49,8 +51,8 @@
at
[% branch %]
[% END %]
- [% IF ( timeLimitFinite ) %]
- in the past [% timeLimitFinite |html %] months
+ [% IF ( timeLimit != 999 ) %]
+ in the past [% timeLimit |html %] months
[% ELSE %] of all time[% END %]
@@ -62,33 +64,30 @@
- [% FOREACH results_loo IN results_loop %]
+ [% FOREACH result IN results %]