@@ -, +, @@ --- C4/Branch.pm | 10 ++++ C4/Koha.pm | 50 +++++++++++++------- C4/Search.pm | 9 +++- .../intranet-tmpl/prog/en/includes/facets.inc | 1 + .../opac-tmpl/prog/en/includes/opac-facets.inc | 1 + opac/opac-search.pl | 2 +- 6 files changed, 53 insertions(+), 20 deletions(-) --- a/C4/Branch.pm +++ a/C4/Branch.pm @@ -46,6 +46,7 @@ BEGIN { &DelBranchCategory &CheckCategoryUnique &mybranch + &GetBranchesCount ); @EXPORT_OK = qw( &onlymine &mybranch get_branch_code_from_name ); } @@ -580,6 +581,15 @@ sub get_branch_code_from_name { return $sth->fetchrow_array; } +sub GetBranchesCount { + my $dbh = C4::Context->dbh(); + my $query = "SELECT COUNT(*) AS branches_count FROM branches"; + my $sth = $dbh->prepare( $query ); + $sth->execute(); + my $row = $sth->fetchrow_hashref(); + return $row->{'branches_count'}; +} + 1; __END__ --- a/C4/Koha.pm +++ a/C4/Koha.pm @@ -24,7 +24,7 @@ use strict; #use warnings; FIXME - Bug 2505 use C4::Context; - +use C4::Branch qw(GetBranchesCount); use Memoize; use DateTime; use DateTime::Format::MySQL; @@ -713,14 +713,23 @@ sub getFacets { tags => [ qw/ 225a / ], sep => ', ', }, - ]; - my $library_facet = { - idx => 'branch', - label => 'Libraries', - tags => [ qw/ 995b / ], - expanded => '1', - }; - push @$facets, $library_facet unless C4::Context->preference("singleBranchMode"); + ]; + + my $library_facet; + unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) { + $library_facet = { + idx => 'branch', + label => 'Libraries', + tags => [ qw/ 995b / ], + }; + } else { + $library_facet = { + idx => 'location', + label => 'Location', + tags => [ qw/ 995c / ], + }; + } + push( @$facets, $library_facet ); } else { $facets = [ @@ -767,15 +776,22 @@ sub getFacets { sep => ', ', }, ]; + my $library_facet; - $library_facet = { - idx => 'branch', - label => 'Libraries', - tags => [ qw/ 952b / ], - sep => ', ', - expanded => '1', - }; - push @$facets, $library_facet unless C4::Context->preference("singleBranchMode"); + unless ( C4::Context->preference("singleBranchMode") || GetBranchesCount() == 1 ) { + $library_facet = { + idx => 'branch', + label => 'Libraries', + tags => [ qw / 952b / ], + }; + } else { + $library_facet = { + idx => 'location', + label => 'Location', + tags => [ qw / 952c / ], + }; + } + push( @$facets, $library_facet ); } return $facets; } --- a/C4/Search.pm +++ a/C4/Search.pm @@ -301,8 +301,8 @@ See verbse embedded documentation. sub getRecords { my ( $koha_query, $simple_query, $sort_by_ref, $servers_ref, - $results_per_page, $offset, $expanded_facet, $branches,$itemtypes, - $query_type, $scan + $results_per_page, $offset, $expanded_facet, $branches, + $itemtypes, $query_type, $scan, $opac ) = @_; my @servers = @$servers_ref; @@ -567,6 +567,11 @@ sub getRecords { } } + # also, if it's a location code, use the name instead of the code + if ( $link_value =~ /location/ ) { + $facet_label_value = GetKohaAuthorisedValueLib('LOC', $one_facet, $opac) || '*'; + } + # but we're down with the whole label being in the link's title. push @this_facets_array, { facet_count => $facets_counter->{$link_value}->{$one_facet}, --- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc @@ -17,6 +17,7 @@ [% IF ( facets_loo.type_label_Series ) %]Series[% END %] [% IF ( facets_loo.type_label_ItemTypes ) %]Item types[% END %] [% IF ( facets_loo.type_label_Libraries ) %]Libraries[% END %] +[% IF ( facets_loo.type_label_Location ) %]Locations[% END %]