From 25842337e240375c3967fb48a981d095d5865a73 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 2 Jan 2013 10:06:11 -0500 Subject: [PATCH] Bug 7441 - search results showing wrong branch? - Followup - Use syspref for XSLT and non-XSLT Signed-off-by: Bernardo Gonzalez Kriegel Comment: Applied all patches. Tested with and without XLST display. Works as described. No errors. Not tested with UNIMARC --- C4/Search.pm | 16 +++--- C4/XSLT.pm | 2 +- Koha/Template/Plugin/Koha.pm | 49 ++++++++++++++++++++ installer/data/mysql/sysprefs.sql | 2 +- installer/data/mysql/updatedatabase.pl | 4 +- .../prog/en/modules/admin/preferences/opac.pref | 3 +- .../opac-tmpl/prog/en/modules/opac-results.tt | 9 +++- .../prog/en/xslt/MARC21slim2OPACResults.xsl | 10 ++-- .../prog/en/xslt/UNIMARCslim2OPACResults.xsl | 10 ++-- 9 files changed, 79 insertions(+), 26 deletions(-) create mode 100644 Koha/Template/Plugin/Koha.pm diff --git a/C4/Search.pm b/C4/Search.pm index aec024b..39fd74e 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1865,8 +1865,8 @@ sub searchResults { $item->{'branchname'} = $branches{$item->{$otherbranch}}; } - my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber}; -# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item + my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber}; + # For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item my $userenv = C4::Context->userenv; if ( $item->{onloan} && !(C4::Members::GetHideLostItemsPreference($userenv->{'number'}) && $item->{itemlost}) ) { $onloan_count++; @@ -1975,12 +1975,12 @@ sub searchResults { else { $can_place_holds = 1; $available_count++; - $available_items->{$prefix}->{count}++ if $item->{$hbranch}; - foreach (qw(branchname itemcallnumber description)) { - $available_items->{$prefix}->{$_} = $item->{$_}; - } - $available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} }; - $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} ); + $available_items->{$prefix}->{count}++ if $item->{$hbranch}; + foreach (qw(branchname itemcallnumber description homebranch holdingbranch)) { + $available_items->{$prefix}->{$_} = $item->{$_}; + } + $available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} }; + $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} ); } } } # notforloan, item level and biblioitem level diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 96690b9..8101890 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -190,7 +190,7 @@ sub XSLTParse4Display { UseControlNumber IntranetBiblioDefaultView BiblioDefaultView singleBranchMode OPACItemLocation DisplayIconsXSLT AlternateHoldingsField AlternateHoldingsSeparator - TrackClicks OPACResultsBranchXSLT / ) + TrackClicks OPACResultsBranch / ) { my $sp = C4::Context->preference( $syspref ); next unless defined($sp); diff --git a/Koha/Template/Plugin/Koha.pm b/Koha/Template/Plugin/Koha.pm new file mode 100644 index 0000000..a992961 --- /dev/null +++ b/Koha/Template/Plugin/Koha.pm @@ -0,0 +1,49 @@ +package Koha::Template::Plugin::Koha; + +# Copyright ByWater Solutions 2013 + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Template::Plugin; +use base qw( Template::Plugin ); + +use C4::Koha; +use C4::Context; + +=pod + +This plugin contains various Koha replated Template Toolkit functions +to help streamline Koha and to move logic from the Perl code into the +Templates when it makes sense to do so. + +To use, first, include the line '[% USE Koha %]' at the top +of the template to enable the plugin. + +For example: [% IF Koha.Preference( 'MyPreference ) == 'SettingA' %] +removes the necessity of setting a template variable in Perl code for +each and every system preference, even if no evaluation of the setting +is necessary. + +=cut + +sub Preference { + my ( $self, $pref ) = @_; + return C4::Context->preference( $pref ); +} + +1; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 8de79a3..bdc1ec1 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -424,4 +424,4 @@ INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES(' INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('HighlightOwnItemsOnOPAC','0','','If on, and a patron is logged into the OPAC, items from his or her home library will be emphasized and shown first in search results and item details.','YesNo'); INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('HighlightOwnItemsOnOPACWhich','PatronBranch','PatronBranch|OpacURLBranch','Decides which branch''s items to emphasize. If PatronBranch, emphasize the logged in user''s library''s items. If OpacURLBranch, highlight the items of the Apache var BRANCHCODE defined in Koha''s Apache configuration file.','Choice'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UniqueItemFields', 'barcode', 'Space-separated list of fields that should be unique (used in acquisition module for item creation). Fields must be valid SQL column names of items table', '', 'Free'); -INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('OPACResultsBranchXSLT', 'homebranch', 'homebranch|holdingbranch', 'Defines whether the OPAC displays the holding or home branch in search results when using XSLT', 'Choice'); +INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('OPACResultsBranch', 'homebranch', 'homebranch|holdingbranch', 'Defines whether the OPAC displays the holding or home branch in search results.', 'Choice'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index d1a25bb..0cc2d8c 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6836,8 +6836,8 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { $DBversion = "3.11.00.XXX"; if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { - $dbh->do("INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('OPACResultsBranchXSLT', 'homebranch', 'homebranch|holdingbranch', 'Defines whether the OPAC displays the holding or home branch in search results when using XSLT', 'Choice')"); - print "Upgrade to $DBversion done (Add syspref OPACResultsBranchXSLT)\n"; + $dbh->do("INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('OPACResultsBranch', 'homebranch', 'homebranch|holdingbranch', 'Defines whether the OPAC displays the holding or home branch in search results when using XSLT', 'Choice')"); + print "Upgrade to $DBversion done (Add syspref OPACResultsBranch)\n"; SetVersion($DBversion); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 53d9217..a4be63d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -84,11 +84,10 @@ OPAC: - the format, audience, and material type icons in XSLT MARC21 results and detail pages in the OPAC. - - On search result pages displayed with XSLT stylesheets on the OPAC, show the item's - - pref: OPACResultsBranchXSLT + - pref: OPACResultsBranch choices: holdingbranch: "holding branch" homebranch: "home branch" - - icons for itemtype and authorized values. - - pref: COinSinOPACResults choices: diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt index 0704f06..0cd86f4 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt @@ -1,3 +1,5 @@ +[% USE Koha %] +[% USE KohaBranchName %] [% SET TagsShowEnabled = ( TagsEnabled && TagsShowOnList ) %] [% SET TagsInputEnabled = ( opacuserlogin && TagsEnabled && TagsInputOnList ) %] @@ -538,9 +540,12 @@ $(document).ready(function(){ [% IF ( singleBranchMode ) %] [% available_items_loo.location %] [% ELSE %] - [% available_items_loo.branchname %] + [% IF Koha.Preference('OPACResultsBranch') == 'homebranch' %] + [% available_items_loo.homebranch | $KohaBranchName %] + [% ELSE %] + [% available_items_loo.holdingbranch | $KohaBranchName %] + [% END %] [% END %] - [% IF ( OPACItemsResultsDisplay ) %] [% UNLESS ( singleBranchMode ) %][% available_items_loo.location %][% END %] [% IF ( available_items_loo.itemcallnumber ) %][[% available_items_loo.itemcallnumber %]][% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl index 47644f7..e2c7c4d 100644 --- a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl +++ b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl @@ -20,7 +20,7 @@ - + @@ -1064,7 +1064,7 @@ - + [] @@ -1074,7 +1074,7 @@ . , - + [] @@ -1099,7 +1099,7 @@ - + [] @@ -1109,7 +1109,7 @@ . , - + [] diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl index 77315e1..89240fe 100644 --- a/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl +++ b/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl @@ -28,7 +28,7 @@ - + @@ -147,7 +147,7 @@ - + [] @@ -157,7 +157,7 @@ . , - + [] @@ -180,7 +180,7 @@ - + [] @@ -190,7 +190,7 @@ . , - + [] -- 1.7.2.5