Bug fix to OPAC shelf browsing query statement
authorDavid Birmingham <dbirmingham@ptfs.com>
Thu, 30 Apr 2009 16:54:48 +0000 (12:54 -0400)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Tue, 26 May 2009 19:15:23 +0000 (21:15 +0200)
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 <galen.charlton@liblime.com>
Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl
opac/opac-detail.pl

index bee0ec7..6c739e6 100644 (file)
 
 <!-- TMPL_IF NAME="OpenOPACShelfBrowser" -->
 <div id="shelfbrowser">
-<h5 style="text-align: center;"><!-- TMPL_IF NAME="starting_homebranch" -->Browsing <!-- TMPL_VAR NAME="starting_homebranch" --> Library<!-- /TMPL_IF --><!-- TMPL_IF NAME="starting_location" -->, Shelving Location:</span><!-- TMPL_VAR NAME="starting_location" --> <!-- /TMPL_IF --> <a style="font-size: 75%;" href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">Close Shelf Browser</a></h5>
+<h5 style="text-align: center;"><!-- TMPL_IF NAME="starting_homebranch" -->Browsing <!-- TMPL_VAR NAME="starting_homebranch" --> Shelves<!-- /TMPL_IF --><!-- TMPL_IF NAME="starting_location" -->, Shelving Location:</span><!-- TMPL_VAR NAME="starting_location" --> <!-- /TMPL_IF --> <a style="font-size: 75%;" href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">Close Shelf Browser</a></h5>
 
         
         <table><tr>
index 85eeaa7..8100886 100755 (executable)
@@ -321,7 +321,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
@@ -329,7 +331,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=?");
@@ -346,7 +359,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
@@ -354,7 +369,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=?");