From d5d21fe1018adf6fcb1899a67e0f1f84fa3b1d25 Mon Sep 17 00:00:00 2001 From: David Birmingham Date: Thu, 30 Apr 2009 12:54:48 -0400 Subject: [PATCH] Bug fix to OPAC shelf browsing query statement If the items.location field was NULL, then the current SQL query would produce no results. I have turned this into a conditional block that removes the location condition in the query if the location is not specified. In addition, there was a small change to opac-detail.tmpl that changed Library to Shelves when the shelf browser was open. This removes a potential redundant Library Library display if Library is contained in the starting_homebranch. Signed-off-by: Galen Charlton --- .../prog/en/modules/opac-detail.tmpl | 2 +- opac/opac-detail.pl | 34 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl index 39d25d5cd3..2d896d7189 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl @@ -368,7 +368,7 @@
-
Browsing Library, Shelving Location: ">Close Shelf Browser
+
Browsing Shelves, Shelving Location: ">Close Shelf Browser
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 5b986ac30e..650574151a 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -420,7 +420,9 @@ if (C4::Context->preference("OPACShelfBrowser")) { ## List of Previous Items # order by cn_sort, which should include everything we need for ordering purposes (though not # for limits, those need to be handled separately - my $sth_shelfbrowse_previous = $dbh->prepare(" + my $sth_shelfbrowse_previous; + if (defined $starting_location->{code}) { + $sth_shelfbrowse_previous = $dbh->prepare(" SELECT * FROM items WHERE @@ -428,7 +430,18 @@ if (C4::Context->preference("OPACShelfBrowser")) { homebranch = ? AND location = ? ORDER BY cn_sort DESC, itemnumber LIMIT 3 "); - $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code}); + $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code}); + } else { + $sth_shelfbrowse_previous = $dbh->prepare(" + SELECT * + FROM items + WHERE + ((cn_sort = ? AND itemnumber < ?) OR cn_sort < ?) AND + homebranch = ? + ORDER BY cn_sort DESC, itemnumber LIMIT 3 + "); + $sth_shelfbrowse_previous->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}); + } my @previous_items; while (my $this_item = $sth_shelfbrowse_previous->fetchrow_hashref()) { my $sth_get_biblio = $dbh->prepare("SELECT biblio.*,biblioitems.isbn AS isbn FROM biblio LEFT JOIN biblioitems ON biblio.biblionumber=biblioitems.biblionumber WHERE biblio.biblionumber=?"); @@ -444,7 +457,9 @@ if (C4::Context->preference("OPACShelfBrowser")) { } ## List of Next Items; this also intentionally catches the current item - my $sth_shelfbrowse_next = $dbh->prepare(" + my $sth_shelfbrowse_next; + if (defined $starting_location->{code}) { + $sth_shelfbrowse_next = $dbh->prepare(" SELECT * FROM items WHERE @@ -452,7 +467,18 @@ if (C4::Context->preference("OPACShelfBrowser")) { homebranch = ? AND location = ? ORDER BY cn_sort, itemnumber LIMIT 3 "); - $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code}); + $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}, $starting_location->{code}); + } else { + $sth_shelfbrowse_next = $dbh->prepare(" + SELECT * + FROM items + WHERE + ((cn_sort = ? AND itemnumber >= ?) OR cn_sort > ?) AND + homebranch = ? + ORDER BY cn_sort, itemnumber LIMIT 3 + "); + $sth_shelfbrowse_next->execute($starting_cn_sort, $starting_itemnumber, $starting_cn_sort, $starting_homebranch->{code}); + } my @next_items; while (my $this_item = $sth_shelfbrowse_next->fetchrow_hashref()) { my $sth_get_biblio = $dbh->prepare("SELECT biblio.*,biblioitems.isbn AS isbn FROM biblio LEFT JOIN biblioitems ON biblio.biblionumber=biblioitems.biblionumber WHERE biblio.biblionumber=?"); -- 2.39.5