Bug 5990: Lists and Cart show LOC code not Location Authorized value
authorIan Walls <ian.walls@bywatersolutions.com>
Wed, 30 Mar 2011 17:39:53 +0000 (13:39 -0400)
committerChris Nighswonger <chris.nighswonger@gmail.com>
Sat, 16 Apr 2011 15:17:30 +0000 (11:17 -0400)
Lists in the OPAC, and Cart on both sides, show the LOC code for items, rather
than the appropriate Description from Authorised Values.  This is because the
code uses GetItemInfo, which is a very heavy-weight call to only retrieve some
of the desired information.

This patch introduces a new subroutine in C4::Items, GetItemsLocationInfo, which
returns the branch names for both home- and holdingbranches, the location code,
both opac and intranet location descriptions, itemcallnumber and cn_sort. This
should be used instead of GetItemsInfo in any case where the locational
information is all that's required, as it's much more streamlined and efficient.

In the OPAC Lists, this only applies if OPACXSLTResultsDisplay is 'off' (set to
'normal').

Signed-off-by: Jared Camins-Esakov <jcamins@bywatersolutions.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
(cherry picked from commit 90392c19cc343ada611c1f06e4b5c20f3dd6dc93)

Signed-off-by: Chris Nighswonger <chris.nighswonger@gmail.com>
C4/Items.pm
C4/VirtualShelves/Page.pm
koha-tmpl/opac-tmpl/prog/en/modules/opac-basket.tmpl
koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl
opac/opac-basket.pl

index 05df0c5..bbd0ece 100644 (file)
@@ -65,6 +65,7 @@ BEGIN {
         GetItemInfosOf
         GetItemsByBiblioitemnumber
         GetItemsInfo
+       GetItemsLocationInfo
         get_itemnumbers_of
         GetItemnumberFromBarcode
         GetBarcodeFromItemnumber
@@ -1347,6 +1348,72 @@ sub GetItemsInfo {
        }
 }
 
+=head2 GetItemsLocationInfo
+
+  my @itemlocinfo = GetItemsLocationInfo($biblionumber);
+
+Returns the branch names, shelving location and itemcallnumber for each item attached to the biblio in question
+
+C<GetItemsInfo> returns a list of references-to-hash. Data returned:
+
+=over 2
+
+=item C<$data-E<gt>{homebranch}>
+
+Branch Name of the item's homebranch
+
+=item C<$data-E<gt>{holdingbranch}>
+
+Branch Name of the item's holdingbranch
+
+=item C<$data-E<gt>{location}>
+
+Item's shelving location code
+
+=item C<$data-E<gt>{location_intranet}>
+
+The intranet description for the Shelving Location as set in authorised_values 'LOC'
+
+=item C<$data-E<gt>{location_opac}>
+
+The OPAC description for the Shelving Location as set in authorised_values 'LOC'.  Falls back to intranet description if no OPAC 
+description is set.
+
+=item C<$data-E<gt>{itemcallnumber}>
+
+Item's itemcallnumber
+
+=item C<$data-E<gt>{cn_sort}>
+
+Item's call number normalized for sorting
+
+=back
+  
+=cut
+
+sub GetItemsLocationInfo {
+        my $biblionumber = shift;
+        my @results;
+
+       my $dbh = C4::Context->dbh;
+       my $query = "SELECT a.branchname as homebranch, b.branchname as holdingbranch, 
+                           location, itemcallnumber, cn_sort
+                    FROM items, branches as a, branches as b
+                    WHERE homebranch = a.branchcode AND holdingbranch = b.branchcode 
+                    AND biblionumber = ?
+                    ORDER BY cn_sort ASC";
+       my $sth = $dbh->prepare($query);
+        $sth->execute($biblionumber);
+
+        while ( my $data = $sth->fetchrow_hashref ) {
+             $data->{location_intranet} = GetKohaAuthorisedValueLib('LOC', $data->{location});
+             $data->{location_opac}= GetKohaAuthorisedValueLib('LOC', $data->{location}, 1);
+            push @results, $data;
+       }
+       return @results;
+}
+
+
 =head2 GetLastAcquisitions
 
   my $lastacq = GetLastAcquisitions({'branches' => ('branch1','branch2'), 
index d6d0f7f..49d1aa8 100644 (file)
@@ -216,7 +216,7 @@ sub shelfpage ($$$$$) {
                     $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber($record,$marcflavour);
                     $this_item->{'normalized_isbn'} = GetNormalizedISBN(undef,$record,$marcflavour);
                     # Getting items infos for location display
-                    my @items_infos = &GetItemsInfo( $this_item->{'biblionumber'}, $type );
+                    my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'});
                     $this_item->{'itemsissued'} = CountItemsIssued( $this_item->{'biblionumber'} );
                     $this_item->{'ITEM_RESULTS'} = \@items_infos;
 
index b64205b..4928daa 100644 (file)
@@ -293,7 +293,7 @@ function tagAdded() {
             <th scope="row">Location(s)</th>
             <td><!-- TMPL_IF NAME="ITEM_RESULTS" --><ul><!-- TMPL_LOOP NAME="ITEM_RESULTS" -->
                             <li>
-                                <strong><!-- TMPL_VAR NAME="branchname" --></strong><!-- TMPL_IF NAME="location" -->, <!-- TMPL_VAR NAME="location" --><!-- /TMPL_IF -->
+                                <strong><!-- TMPL_VAR NAME="homebranch" --></strong><!-- TMPL_IF NAME="location_opac" -->, <!-- TMPL_VAR NAME="location_opac" --><!-- /TMPL_IF -->
                                 <!-- TMPL_IF name="itemcallnumber" -->
                                     (<!-- TMPL_VAR NAME="itemcallnumber" -->)
                                 <!-- /TMPL_IF -->
@@ -367,7 +367,7 @@ function tagAdded() {
            </td>
                 <td><!-- TMPL_IF NAME="ITEM_RESULTS" --><ul><!-- TMPL_LOOP NAME="ITEM_RESULTS" -->
                     <li>
-                        <!-- TMPL_VAR NAME="branchname" --><!-- TMPL_IF NAME="location" -->, <!-- TMPL_VAR NAME="location" --><!-- /TMPL_IF -->
+                        <!-- TMPL_VAR NAME="homebranch" --><!-- TMPL_IF NAME="location_opac" -->, <!-- TMPL_VAR NAME="location_opac" --><!-- /TMPL_IF -->
                         <!-- TMPL_IF name="itemcallnumber" -->
                             (<!-- TMPL_VAR NAME="itemcallnumber" -->)
                         <!-- /TMPL_IF -->
index 3c04429..7441887 100644 (file)
@@ -267,7 +267,7 @@ $(function() {
                         <!-- TMPL_IF name="size" --> <!-- TMPL_VAR name="size" --><!-- /TMPL_IF -->
                 </span>
                 <span class="results_summary"><span class="label">Holdings:</span><!-- TMPL_IF NAME="ITEM_RESULTS" --><!-- TMPL_LOOP NAME="ITEM_RESULTS" -->
-          <!-- TMPL_VAR NAME="branchname" --><!-- TMPL_IF NAME="location" -->, <!-- TMPL_VAR NAME="location" --><!-- /TMPL_IF -->
+          <!-- TMPL_VAR NAME="homebranch" --><!-- TMPL_IF NAME="location_opac" -->, <!-- TMPL_VAR NAME="location_opac" --><!-- /TMPL_IF -->
           <!-- TMPL_IF name="itemcallnumber" -->
         (<!-- TMPL_VAR NAME="itemcallnumber" -->)<!-- TMPL_IF NAME="__LAST__" -->.<!-- TMPL_ELSE -->,<!-- /TMPL_IF -->
           <!-- /TMPL_IF -->
index c453c87..bfee06c 100755 (executable)
@@ -68,7 +68,7 @@ foreach my $biblionumber ( @bibs ) {
     my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
     my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
     my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
-    my @items            = &GetItemsInfo( $biblionumber, 'opac' );
+    my @items            = &GetItemsLocationInfo( $biblionumber );
     my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
 
     my $hasauthors = 0;