From e9dbc2223d6e24996713b454ed8cdb43a8fca1ae Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Mon, 28 Oct 2013 15:59:00 +0200 Subject: [PATCH] Bug 6385 - All items should optionally be displayed by default in the OPAC Added a system preference "OPACmaxItemsOnDetail" to set a threshold after which only results from the users branch are displayed, or Items from the past year if homebranch cannot be defined. This tightly couples with bug 11129 which provides the filtering mechanism to display smaller result sets. Also added lots of complexity to define the warning messages based on is the filter used to override the "OPACmaxItemsOnDetail". Added a new "limit"-filter to C4::Items::GetItemsInfo() which adds the LIMIT-clause to the big SQL. Added a unit test for the filter to the Items.t Fixed a use-case where a user has no items in his branch, and the limited items set is emtpy. Now using items from past year if none available in the users branch. --- C4/Items.pm | 6 + installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 4 + koha-tmpl/opac-tmpl/prog/en/css/opac-detail.css | 9 + koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 20 +- opac/opac-detail.pl | 1579 ++++++++++++-------- t/db_dependent/Items.t | 6 +- 7 files changed, 966 insertions(+), 659 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 52b8517..c13535c 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1235,6 +1235,7 @@ $filter->{fromDate} = '01/01/2013'; #Filters only serial issues by the serialite #The starting date in C4::Context->preference('dateformat') format $filter->{toDate} = '31/12/2014'; #Filters only serial issues by the serialitems.publisheddate #The ending date in C4::Context->preference('dateformat') format +$filter->{limit} = 15; #Limits the returning set to this many items Filters are expected to be validated! If a filter is not defined, that filter is not present in the $filter-HASH @@ -1359,6 +1360,11 @@ sub GetItemsInfo { } $query .= "ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ; + if (exists $filter->{limit}) { + push @$queryParams, $filter->{limit}; + $query .= " LIMIT ?"; + } + my $sth = $dbh->prepare($query); $sth->execute(@$queryParams); my $i = 0; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 864a892..3c427fd 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -241,6 +241,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OpacMaintenance','0','','If ON, enables maintenance warning in OPAC','YesNo'), ('OpacMainUserBlock','Welcome to Koha...\r\n
','70|10','A user-defined block of HTML in the main content area of the opac main page','Textarea'), ('OpacMainUserBlockMobile','',NULL,'Show the following HTML in its own column on the main page of the OPAC (mobile version):','free'), +('OPACmaxItemsOnDetail', '50', NULL, 'On the Bibliographic record details page, show only items from the users branch and prompt the user to filter the items if the record has more then this many items.', 'Integer'), ('OPACMobileUserCSS','',NULL,'Include the following CSS for the mobile view on all pages in the OPAC:','free'), ('OPACMySummaryHTML','','70|10','Enter the HTML that will appear in a column on the \'my summary\' and \'my reading history\' tabs when a user is logged in to the OPAC. Enter {BIBLIONUMBER}, {TITLE}, {AUTHOR}, or {ISBN} in place of their respective variables in the HTML. Leave blank to disable.','Textarea'), ('OpacNav','Important links here.','70|10','Use HTML tags to add navigational links to the left-hand navigational bar in OPAC','Textarea'), 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 a75c7ef..e622253 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 @@ -188,6 +188,10 @@ OPAC: type: textarea class: code - + - On the Bibliographic record details page, show only this many items from the users branch and prompt the user to filter the items if the record has more than this many items. If the user has no branch or the branch has no items, displaying items from the past year. + - pref: OPACmaxItemsOnDetail + class: integer + - - pref: OpacShowLibrariesPulldownMobile choices: yes: Show diff --git a/koha-tmpl/opac-tmpl/prog/en/css/opac-detail.css b/koha-tmpl/opac-tmpl/prog/en/css/opac-detail.css index d58453a..e7935f8 100644 --- a/koha-tmpl/opac-tmpl/prog/en/css/opac-detail.css +++ b/koha-tmpl/opac-tmpl/prog/en/css/opac-detail.css @@ -11,4 +11,13 @@ padding-right: 20px; margin-right: 6px; +} + +#clearFilter { + border: none; + background: none; + color: #006699; +} +#clearFilter:hover { + color : #990033; } \ No newline at end of file diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt index a95d50f..6346f9f 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt @@ -1054,17 +1054,25 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
- [% IF ( lotsofholdingsitems ) %] + [% IF ( showFilter ) %] [%# Display the items filtering form used to filter the shown items. See the end of this file! %] [% INCLUDE filter_form tab="holdings" %] [% END %] [% IF ( itemloop.size ) %] + [% IF ( lotsofholdingsitems ) %] -

This record has many physical items. Click here to view them all. Or use the filter above to limit your selection

- [% ELSE %] - [% INCLUDE items_table items=itemloop tab="holdings" %] +

+ [% IF noBranchItems %] + Limiting items to the most recent received last year.
+ [% ELSE %] + Showing only the most recent items from your branch.
+ [% END %] + This record has many physical items. Use the filter above to limit your selection. +

[% END %] + [% INCLUDE items_table items=itemloop tab="holdings" %] + [% IF holds_count.defined || priority %]
[% IF holds_count.defined %] @@ -1641,9 +1649,9 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
Limit issues [% IF filter %] -
+ - +
[% END %]
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 1d1f1c6..2042166 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -19,7 +19,6 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - use strict; use warnings; @@ -35,7 +34,8 @@ use C4::Circulation; use C4::Tags qw(get_tags); use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn); use C4::External::Amazon; -use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes ); +use C4::External::Syndetics + qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes ); use C4::Review; use C4::Ratings; use C4::Members; @@ -53,10 +53,10 @@ use C4::HTML5Media; use C4::CourseReserves qw(GetItemCourseReservesInfo); BEGIN { - if (C4::Context->preference('BakerTaylorEnabled')) { - require C4::External::BakerTaylor; - import C4::External::BakerTaylor qw(&image_url &link_url); - } + if ( C4::Context->preference('BakerTaylorEnabled') ) { + require C4::External::BakerTaylor; + import C4::External::BakerTaylor qw(&image_url &link_url); + } } my $query = new CGI; @@ -66,7 +66,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( query => $query, type => "opac", authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), - flagsrequired => { borrow => 1 }, + flagsrequired => { borrow => 1 }, } ); @@ -77,22 +77,31 @@ $biblionumber = int($biblionumber); ##>> Handling the Serial issue filter parameters from the user ## # We can filter issues based on these five values. -my $filterBranchLimiter = $query->param('filterBranchLimiter') ? $query->param('filterBranchLimiter') : '_ShowAll'; -my $filterVolume = $query->param('filterVolume') ? $query->param('filterVolume') : undef; -my $filterNumber = $query->param('filterNumber') ? $query->param('filterNumber') : undef; -my $filterIssue = $query->param('filterIssue') ? $query->param('filterIssue') : undef; -my $filterFromDate = $query->param('filterFrom') ? $query->param('filterFrom') : undef; -my $filterToDate = $query->param('filterTo') ? $query->param('filterTo') : undef; - -my $filter; #a HASH! Collect the filters here, so they can be more conveniently moved around. +my $filterBranchLimiter = + $query->param('filterBranchLimiter') + ? $query->param('filterBranchLimiter') + : undef; +my $filterVolume = + $query->param('filterVolume') ? $query->param('filterVolume') : undef; +my $filterNumber = + $query->param('filterNumber') ? $query->param('filterNumber') : undef; +my $filterIssue = + $query->param('filterIssue') ? $query->param('filterIssue') : undef; +my $filterFromDate = + $query->param('filterFrom') ? $query->param('filterFrom') : undef; +my $filterToDate = + $query->param('filterTo') ? $query->param('filterTo') : undef; + +my $filter = + {}; #a HASH! Collect the filters here, so they can be more conveniently moved around. #We filter by the branch only if a valid branch is given. -if (defined $filterBranchLimiter && $filterBranchLimiter ne '_ShowAll') { +if ( defined $filterBranchLimiter && $filterBranchLimiter ne '_ShowAll' ) { $filter->{branch} = $filterBranchLimiter; } -if (defined $filterVolume && length $filterVolume > 0) { - if (!($filterVolume =~ /\d{1,4}/)) { - print $query->header(); #bad data goddamnit! +if ( defined $filterVolume && length $filterVolume > 0 ) { + if ( !( $filterVolume =~ /\d{1,4}/ ) ) { + print $query->header(); #bad data goddamnit! print "Invalid volume. Please try again. \n"; exit; } @@ -100,9 +109,9 @@ if (defined $filterVolume && length $filterVolume > 0) { $filter->{volume} = $filterVolume; } } -if (defined $filterNumber && length $filterNumber > 0) { - if (!($filterNumber =~ /\d{1,2}/)) { - print $query->header(); #stop spamming bad data! +if ( defined $filterNumber && length $filterNumber > 0 ) { + if ( !( $filterNumber =~ /\d{1,2}/ ) ) { + print $query->header(); #stop spamming bad data! print "Invalid number. Please try again. \n"; exit; } @@ -110,9 +119,9 @@ if (defined $filterNumber && length $filterNumber > 0) { $filter->{number} = $filterNumber; } } -if (defined $filterIssue && length $filterIssue > 0) { - if (!($filterIssue =~ /\d{1,2}/) ) { - print $query->header(); #stop spamming bad data! +if ( defined $filterIssue && length $filterIssue > 0 ) { + if ( !( $filterIssue =~ /\d{1,2}/ ) ) { + print $query->header(); #stop spamming bad data! print "Invalid issue. Please try again. \n"; exit; } @@ -120,102 +129,178 @@ if (defined $filterIssue && length $filterIssue > 0) { $filter->{issue} = $filterIssue; } } -if (defined $filterFromDate && length $filterFromDate > 0) { - if (!($filterFromDate =~ C4::Dates->regexp( C4::Context->preference('dateformat') )) ) { - print $query->header(); #noo not anymore noo! +if ( defined $filterFromDate && length $filterFromDate > 0 ) { + if ( + !( + $filterFromDate =~ + C4::Dates->regexp( C4::Context->preference('dateformat') ) + ) + ) + { + print $query->header(); #noo not anymore noo! print "Invalid starting date. Please try again. \n"; exit; } else { - $filter->{fromDate} = C4::Dates::format_date_in_iso( $filterFromDate ); + $filter->{fromDate} = C4::Dates::format_date_in_iso($filterFromDate); } } -if (defined $filterToDate && length $filterToDate > 0) { - if (!($filterToDate =~ C4::Dates->regexp( C4::Context->preference('dateformat') )) ) { - print $query->header(); #take your bad data away! +if ( defined $filterToDate && length $filterToDate > 0 ) { + if ( + !( + $filterToDate =~ + C4::Dates->regexp( C4::Context->preference('dateformat') ) + ) + ) + { + print $query->header(); #take your bad data away! print "Invalid ending date. Please try again. \n"; exit; } else { - $filter->{toDate} = C4::Dates::format_date_in_iso( $filterToDate ); + $filter->{toDate} = C4::Dates::format_date_in_iso($filterToDate); } } +$template->param( filter => $filter ); + +## +##<< Serial issues filter parameters handled! ## +## + +# If there are a lot of items, and the user has not decided +# to view them all yet, we first warn him +my $itemsCount = GetItemsCount($biblionumber); +my $lotsofholdingsitems = 0; +if ( $itemsCount > C4::Context->preference('OPACmaxItemsOnDetail') + && !( $query->param('viewallitems') ) ) +{ + + $lotsofholdingsitems = 1; + $template->param( 'lotsofholdingsitems' => $lotsofholdingsitems ); +} + +my @all_items; +if ($lotsofholdingsitems) { + + #Spare the poor old DB from this possibly excruciatinly huge read operation. + if ( !scalar(%$filter) ) { #Is the $filter empty? + + #Limit the amount of results to the system preference + $filter->{limit} = C4::Context->preference('OPACmaxItemsOnDetail'); + + #Limit display of Items based on the users branch + if ( C4::Context->userenv ) { + $filter->{branch} = C4::Context->userenv->{branch}; + $filterBranchLimiter = + $filter->{branch}; #Making the branches loop react to this! + + @all_items = GetItemsInfo( $biblionumber, $filter ); + } + +#Or if branch cannot be defined or has no items, then display Items only from the past year + if ( !( scalar(@all_items) ) ) { + delete $filter->{branch} + ; #Remove the branch filter as it gave no results + undef $filterBranchLimiter; + + my $now = DateTime->now(); + $now->set_year( ( $now->year() - 1 ) ); + $filter->{fromDate} = Koha::DateUtils::output_pref( + { dt => $now, dateformat => 'iso' } ); + $template->param( 'noBranchItems' => 1 ); + @all_items = GetItemsInfo( $biblionumber, $filter ); + } + + } +} + +#If we haven't found our items yet, then pull them using whatever we've got. +if ( !( scalar(@all_items) ) ) { + @all_items = GetItemsInfo( $biblionumber, $filter ); +} ##Prepare the custom branches loop containing the _ShowAll entry to show issues from all libraries. my $branchloop; -if ( $filterBranchLimiter eq '_ShowAll' || !(defined $filterBranchLimiter) ) { - $branchloop = C4::Branch::GetBranchesLoop('0'); #Using '0' to disable reverting to the users home branch - unshift @$branchloop, { branchcode => '_ShowAll', branchname => 'Show from any library', selected => '1', value => '_ShowAll'}; +if ( $filterBranchLimiter eq '_ShowAll' || !( defined $filterBranchLimiter ) ) { + $branchloop = C4::Branch::GetBranchesLoop('0') + ; #Using '0' to disable reverting to the users home branch + unshift @$branchloop, + { + branchcode => '_ShowAll', + branchname => 'Show from any library', + selected => '1', + value => '_ShowAll' + }; } else { $branchloop = C4::Branch::GetBranchesLoop($filterBranchLimiter); - unshift @$branchloop, { branchcode => '_ShowAll', branchname => 'Show from any library', selected => '0', value => '_ShowAll'}; + unshift @$branchloop, + { + branchcode => '_ShowAll', + branchname => 'Show from any library', + selected => '0', + value => '_ShowAll' + }; } $template->param( branchloop => $branchloop ); -$template->param( filter => $filter ) if defined $filter; - -## -##<< Serial issues filter parameters handled! ## -## - - -my @all_items = GetItemsInfo($biblionumber, $filter); # Now that the filter is no longer needed, we can reuse it to keep the filter modifications in the UI, -# by reverting the dates to the same format as in the UI layer. -$filter->{fromDate} = $filterFromDate; -$filter->{toDate} = $filterToDate; +# by reverting the dates and the branch to the same format as in the UI layer. +$filter->{fromDate} = $filterFromDate if $filterFromDate; +$filter->{toDate} = $filterToDate if $filterToDate; +$filter->{branch} = $filterBranchLimiter if $filterBranchLimiter; +$template->param( 'showFilter' => 1 ) if ( scalar(%$filter) ); my @hiddenitems; -if (scalar @all_items >= 1) { +if ( scalar @all_items >= 1 ) { push @hiddenitems, GetHiddenItemnumbers(@all_items); - if (scalar @hiddenitems == scalar @all_items ) { - print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early + if ( scalar @hiddenitems == scalar @all_items ) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early exit; } } -my $record = GetMarcBiblio($biblionumber); -if ( ! $record ) { - print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early +my $record = GetMarcBiblio($biblionumber); +if ( !$record ) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early exit; } $template->param( biblionumber => $biblionumber ); #Figure out if we are dealing with a serial! This affects the filter fields in UI -if (scalar @all_items > 0) { +if ( scalar @all_items > 0 ) { $template->param( isSerial => $all_items[0]->{serial} ); } else { - #It could be that a serial has no items to be displayed. This could be because there are none or the filters filter all items - my $search = C4::SQLHelper::SearchInTable("biblio",{biblionumber => $biblionumber}, undef, undef, ['serial'], undef, "exact"); +#It could be that a serial has no items to be displayed. This could be because there are none or the filters filter all items + my $search = + C4::SQLHelper::SearchInTable( "biblio", { biblionumber => $biblionumber }, + undef, undef, ['serial'], undef, "exact" ); $template->param( isSerial => $search->[0]->{serial} ); } - - - # get biblionumbers stored in the cart my @cart_list; -if($query->cookie("bib_list")){ +if ( $query->cookie("bib_list") ) { my $cart_list = $query->cookie("bib_list"); - @cart_list = split(/\//, $cart_list); - if ( grep {$_ eq $biblionumber} @cart_list) { + @cart_list = split( /\//, $cart_list ); + if ( grep { $_ eq $biblionumber } @cart_list ) { $template->param( incart => 1 ); } } - SetUTF8Flag($record); -my $marcflavour = C4::Context->preference("marcflavour"); +my $marcflavour = C4::Context->preference("marcflavour"); my $ean = GetNormalizedEAN( $record, $marcflavour ); # XSLT processing of some stuff -if (C4::Context->preference("OPACXSLTDetailsDisplay") ) { - $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) ); +if ( C4::Context->preference("OPACXSLTDetailsDisplay") ) { + $template->param( 'XSLTBloc' => + XSLTParse4Display( $biblionumber, $record, "OPACXSLTDetailsDisplay" ) + ); } my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults"); @@ -223,314 +308,433 @@ $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults; # We look for the busc param to build the simple paging from the search if ($OpacBrowseResults) { -my $session = get_session($query->cookie("CGISESSID")); -my %paging = (previous => {}, next => {}); -if ($session->param('busc')) { - use C4::Search; - - # Rebuild the string to store on session - sub rebuildBuscParam - { - my $arrParamsBusc = shift; - - my $pasarParams = ''; - my $j = 0; - for (keys %$arrParamsBusc) { - if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) { - if (defined($arrParamsBusc->{$_})) { - $pasarParams .= '&' if ($j); - $pasarParams .= $_ . '=' . $arrParamsBusc->{$_}; - $j++; + my $session = get_session( $query->cookie("CGISESSID") ); + my %paging = ( previous => {}, next => {} ); + if ( $session->param('busc') ) { + use C4::Search; + + # Rebuild the string to store on session + sub rebuildBuscParam { + my $arrParamsBusc = shift; + + my $pasarParams = ''; + my $j = 0; + for ( keys %$arrParamsBusc ) { + if ( $_ =~ +/^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/ + ) + { + if ( defined( $arrParamsBusc->{$_} ) ) { + $pasarParams .= '&' if ($j); + $pasarParams .= $_ . '=' . $arrParamsBusc->{$_}; + $j++; + } } - } else { - for my $value (@{$arrParamsBusc->{$_}}) { - $pasarParams .= '&' if ($j); - $pasarParams .= $_ . '=' . $value; - $j++; + else { + for my $value ( @{ $arrParamsBusc->{$_} } ) { + $pasarParams .= '&' if ($j); + $pasarParams .= $_ . '=' . $value; + $j++; + } } } - } - return $pasarParams; - }#rebuildBuscParam - - # Search given the current values from the busc param - sub searchAgain - { - my ($arrParamsBusc, $offset, $results_per_page) = @_; - - my $expanded_facet = $arrParamsBusc->{'expand'}; - my $branches = GetBranches(); - my $itemtypes = GetItemTypes; - my @servers; - @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'}; - @servers = ("biblioserver") unless (@servers); - - my ($default_sort_by, @sort_by); - $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder')); - @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'}; - $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by); - my ($error, $results_hashref, $facets); - eval { - ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'}); - }; - my $hits; - my @newresults; - for (my $i=0;$i<@servers;$i++) { - my $server = $servers[$i]; - $hits = $results_hashref->{$server}->{"hits"}; - @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"}); - } - return \@newresults; - }#searchAgain - - # Build the current list of biblionumbers in this search - sub buildListBiblios - { - my ($newresultsRef, $results_per_page) = @_; - - my $listBiblios = ''; - my $j = 0; - foreach (@$newresultsRef) { - my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0; - $listBiblios .= $bibnum . ','; - $j++; - last if ($j == $results_per_page); - } - chop $listBiblios if ($listBiblios =~ /,$/); - return $listBiblios; - }#buildListBiblios - - my $busc = $session->param("busc"); - my @arrBusc = split(/\&(?:amp;)?/, $busc); - my ($key, $value); - my %arrParamsBusc = (); - for (@arrBusc) { - ($key, $value) = split(/=/, $_, 2); - if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) { - $arrParamsBusc{$key} = $value; - } else { - unless (exists($arrParamsBusc{$key})) { - $arrParamsBusc{$key} = []; + return $pasarParams; + } #rebuildBuscParam + + # Search given the current values from the busc param + sub searchAgain { + my ( $arrParamsBusc, $offset, $results_per_page ) = @_; + + my $expanded_facet = $arrParamsBusc->{'expand'}; + my $branches = GetBranches(); + my $itemtypes = GetItemTypes; + my @servers; + @servers = @{ $arrParamsBusc->{'server'} } + if $arrParamsBusc->{'server'}; + @servers = ("biblioserver") unless (@servers); + + my ( $default_sort_by, @sort_by ); + $default_sort_by = + C4::Context->preference('OPACdefaultSortField') . "_" + . C4::Context->preference('OPACdefaultSortOrder') + if ( C4::Context->preference('OPACdefaultSortField') + && C4::Context->preference('OPACdefaultSortOrder') ); + @sort_by = @{ $arrParamsBusc->{'sort_by'} } + if $arrParamsBusc->{'sort_by'}; + $sort_by[0] = $default_sort_by + if !$sort_by[0] && defined($default_sort_by); + my ( $error, $results_hashref, $facets ); + eval { + ( $error, $results_hashref, $facets ) = getRecords( + $arrParamsBusc->{'query'}, + $arrParamsBusc->{'simple_query'}, + \@sort_by, + \@servers, + $results_per_page, + $offset, + $expanded_facet, + $branches, + $itemtypes, + $arrParamsBusc->{'query_type'}, + $arrParamsBusc->{'scan'} + ); + }; + my $hits; + my @newresults; + + for ( my $i = 0 ; $i < @servers ; $i++ ) { + my $server = $servers[$i]; + $hits = $results_hashref->{$server}->{"hits"}; + @newresults = searchResults( + 'opac', '', $hits, $results_per_page, $offset, + $arrParamsBusc->{'scan'}, + $results_hashref->{$server}->{"RECORDS"} + ); } - push @{$arrParamsBusc{$key}}, $value; - } - } - my $searchAgain = 0; - my $count = C4::Context->preference('OPACnumSearchResults') || 20; - my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count; - $arrParamsBusc{'count'} = $results_per_page; - my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0; - # The value OPACnumSearchResults has changed and the search has to be rebuild - if ($count != $results_per_page) { - if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) { - my $indexBiblio = 0; - my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'}); - for (@arrBibliosAux) { - last if ($_ == $biblionumber); - $indexBiblio++; + return \@newresults; + } #searchAgain + + # Build the current list of biblionumbers in this search + sub buildListBiblios { + my ( $newresultsRef, $results_per_page ) = @_; + + my $listBiblios = ''; + my $j = 0; + foreach (@$newresultsRef) { + my $bibnum = ( $_->{biblionumber} ) ? $_->{biblionumber} : 0; + $listBiblios .= $bibnum . ','; + $j++; + last if ( $j == $results_per_page ); } - $indexBiblio += $offset; - $offset = int($indexBiblio / $count) * $count; - $arrParamsBusc{'offset'} = $offset; - } - $arrParamsBusc{'count'} = $count; - $results_per_page = $count; - my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page); - $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page); - delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'})); - delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'})); - delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'})); - delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'})); - my $newbusc = rebuildBuscParam(\%arrParamsBusc); - $session->param("busc" => $newbusc); - @arrBusc = split(/\&(?:amp;)?/, $newbusc); - } else { - my $modifyListBiblios = 0; - # We come from a previous click - if (exists($arrParamsBusc{'previous'})) { - $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'}); - delete $arrParamsBusc{'previous'}; - } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click - $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'}); - delete $arrParamsBusc{'next'}; - } - if ($modifyListBiblios) { - if (exists($arrParamsBusc{'newlistBiblios'})) { - my $listBibliosAux = $arrParamsBusc{'listBiblios'}; - $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'}; - my @arrAux = split(',', $listBibliosAux); - $arrParamsBusc{'newlistBiblios'} = $listBibliosAux; - if ($modifyListBiblios == 1) { - $arrParamsBusc{'next'} = $arrAux[0]; - $paging{'next'}->{biblionumber} = $arrAux[0]; - }else { - $arrParamsBusc{'previous'} = $arrAux[$#arrAux]; - $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux]; + chop $listBiblios if ( $listBiblios =~ /,$/ ); + return $listBiblios; + } #buildListBiblios + + my $busc = $session->param("busc"); + my @arrBusc = split( /\&(?:amp;)?/, $busc ); + my ( $key, $value ); + my %arrParamsBusc = (); + for (@arrBusc) { + ( $key, $value ) = split( /=/, $_, 2 ); + if ( $key =~ +/^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/ + ) + { + $arrParamsBusc{$key} = $value; + } + else { + unless ( exists( $arrParamsBusc{$key} ) ) { + $arrParamsBusc{$key} = []; } - } else { - delete $arrParamsBusc{'listBiblios'}; + push @{ $arrParamsBusc{$key} }, $value; } - my $offsetAux = $arrParamsBusc{'offset'}; - $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'}; - $arrParamsBusc{'offsetSearch'} = $offsetAux; - $offset = $arrParamsBusc{'offset'}; - my $newbusc = rebuildBuscParam(\%arrParamsBusc); - $session->param("busc" => $newbusc); - @arrBusc = split(/\&(?:amp;)?/, $newbusc); } - } - my $buscParam = ''; - my $j = 0; - # Rebuild the query for the button "back to results" - for (@arrBusc) { - unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) { - $buscParam .= '&' unless ($j == 0); - $buscParam .= $_; - $j++; + my $searchAgain = 0; + my $count = C4::Context->preference('OPACnumSearchResults') || 20; + my $results_per_page = + ( $arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/ ) + ? $arrParamsBusc{'count'} + : $count; + $arrParamsBusc{'count'} = $results_per_page; + my $offset = + ( $arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/ ) + ? $arrParamsBusc{'offset'} + : 0; + + # The value OPACnumSearchResults has changed and the search has to be rebuild + if ( $count != $results_per_page ) { + if ( exists( $arrParamsBusc{'listBiblios'} ) + && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/ ) + { + my $indexBiblio = 0; + my @arrBibliosAux = split( ',', $arrParamsBusc{'listBiblios'} ); + for (@arrBibliosAux) { + last if ( $_ == $biblionumber ); + $indexBiblio++; + } + $indexBiblio += $offset; + $offset = int( $indexBiblio / $count ) * $count; + $arrParamsBusc{'offset'} = $offset; + } + $arrParamsBusc{'count'} = $count; + $results_per_page = $count; + my $newresultsRef = + searchAgain( \%arrParamsBusc, $offset, $results_per_page ); + $arrParamsBusc{'listBiblios'} = + buildListBiblios( $newresultsRef, $results_per_page ); + delete $arrParamsBusc{'previous'} + if ( exists( $arrParamsBusc{'previous'} ) ); + delete $arrParamsBusc{'next'} + if ( exists( $arrParamsBusc{'next'} ) ); + delete $arrParamsBusc{'offsetSearch'} + if ( exists( $arrParamsBusc{'offsetSearch'} ) ); + delete $arrParamsBusc{'newlistBiblios'} + if ( exists( $arrParamsBusc{'newlistBiblios'} ) ); + my $newbusc = rebuildBuscParam( \%arrParamsBusc ); + $session->param( "busc" => $newbusc ); + @arrBusc = split( /\&(?:amp;)?/, $newbusc ); } - } - $template->param('busc' => $buscParam); - my $offsetSearch; - my @arrBiblios; - # We are inside the list of biblios and we don't have to search - if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) { - @arrBiblios = split(',', $arrParamsBusc{'listBiblios'}); - if (@arrBiblios) { - # We are at the first item of the list - if ($arrBiblios[0] == $biblionumber) { - if (@arrBiblios > 1) { - for (my $j = 1; $j < @arrBiblios; $j++) { - next unless ($arrBiblios[$j]); - $paging{'next'}->{biblionumber} = $arrBiblios[$j]; - last; + else { + my $modifyListBiblios = 0; + + # We come from a previous click + if ( exists( $arrParamsBusc{'previous'} ) ) { + $modifyListBiblios = 1 + if ( $biblionumber == $arrParamsBusc{'previous'} ); + delete $arrParamsBusc{'previous'}; + } + elsif ( exists( $arrParamsBusc{'next'} ) ) + { # We come from a next click + $modifyListBiblios = 2 + if ( $biblionumber == $arrParamsBusc{'next'} ); + delete $arrParamsBusc{'next'}; + } + if ($modifyListBiblios) { + if ( exists( $arrParamsBusc{'newlistBiblios'} ) ) { + my $listBibliosAux = $arrParamsBusc{'listBiblios'}; + $arrParamsBusc{'listBiblios'} = + $arrParamsBusc{'newlistBiblios'}; + my @arrAux = split( ',', $listBibliosAux ); + $arrParamsBusc{'newlistBiblios'} = $listBibliosAux; + if ( $modifyListBiblios == 1 ) { + $arrParamsBusc{'next'} = $arrAux[0]; + $paging{'next'}->{biblionumber} = $arrAux[0]; + } + else { + $arrParamsBusc{'previous'} = $arrAux[$#arrAux]; + $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux]; } } - # search again if we are not at the first searching list - if ($offset && !$arrParamsBusc{'previous'}) { - $searchAgain = 1; - $offsetSearch = $offset - $results_per_page; - } - # we are at the last item of the list - } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) { - for (my $j = $#arrBiblios - 1; $j >= 0; $j--) { - next unless ($arrBiblios[$j]); - $paging{'previous'}->{biblionumber} = $arrBiblios[$j]; - last; - } - if (!$offset) { - # search again if we are at the first list and there is more results - $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios); - } else { - # search again if we aren't at the first list and there is more results - $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios)); + else { + delete $arrParamsBusc{'listBiblios'}; } - $offsetSearch = $offset + $results_per_page if ($searchAgain); - } else { - for (my $j = 1; $j < $#arrBiblios; $j++) { - if ($arrBiblios[$j] == $biblionumber) { - for (my $z = $j - 1; $z >= 0; $z--) { - next unless ($arrBiblios[$z]); - $paging{'previous'}->{biblionumber} = $arrBiblios[$z]; + my $offsetAux = $arrParamsBusc{'offset'}; + $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'}; + $arrParamsBusc{'offsetSearch'} = $offsetAux; + $offset = $arrParamsBusc{'offset'}; + my $newbusc = rebuildBuscParam( \%arrParamsBusc ); + $session->param( "busc" => $newbusc ); + @arrBusc = split( /\&(?:amp;)?/, $newbusc ); + } + } + my $buscParam = ''; + my $j = 0; + + # Rebuild the query for the button "back to results" + for (@arrBusc) { + unless ( $_ =~ +/^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/ + ) + { + $buscParam .= '&' unless ( $j == 0 ); + $buscParam .= $_; + $j++; + } + } + $template->param( 'busc' => $buscParam ); + my $offsetSearch; + my @arrBiblios; + + # We are inside the list of biblios and we don't have to search + if ( exists( $arrParamsBusc{'listBiblios'} ) + && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/ ) + { + @arrBiblios = split( ',', $arrParamsBusc{'listBiblios'} ); + if (@arrBiblios) { + + # We are at the first item of the list + if ( $arrBiblios[0] == $biblionumber ) { + if ( @arrBiblios > 1 ) { + for ( my $j = 1 ; $j < @arrBiblios ; $j++ ) { + next unless ( $arrBiblios[$j] ); + $paging{'next'}->{biblionumber} = $arrBiblios[$j]; last; } - for (my $z = $j + 1; $z < @arrBiblios; $z++) { - next unless ($arrBiblios[$z]); - $paging{'next'}->{biblionumber} = $arrBiblios[$z]; + } + + # search again if we are not at the first searching list + if ( $offset && !$arrParamsBusc{'previous'} ) { + $searchAgain = 1; + $offsetSearch = $offset - $results_per_page; + } + + # we are at the last item of the list + } + elsif ( $arrBiblios[$#arrBiblios] == $biblionumber ) { + for ( my $j = $#arrBiblios - 1 ; $j >= 0 ; $j-- ) { + next unless ( $arrBiblios[$j] ); + $paging{'previous'}->{biblionumber} = $arrBiblios[$j]; + last; + } + if ( !$offset ) { + + # search again if we are at the first list and there is more results + $searchAgain = 1 + if (!$arrParamsBusc{'next'} + && $arrParamsBusc{'total'} != @arrBiblios ); + } + else { + # search again if we aren't at the first list and there is more results + $searchAgain = 1 + if (!$arrParamsBusc{'next'} + && $arrParamsBusc{'total'} > + ( $offset + @arrBiblios ) ); + } + $offsetSearch = $offset + $results_per_page + if ($searchAgain); + } + else { + for ( my $j = 1 ; $j < $#arrBiblios ; $j++ ) { + if ( $arrBiblios[$j] == $biblionumber ) { + for ( my $z = $j - 1 ; $z >= 0 ; $z-- ) { + next unless ( $arrBiblios[$z] ); + $paging{'previous'}->{biblionumber} = + $arrBiblios[$z]; + last; + } + for ( my $z = $j + 1 ; $z < @arrBiblios ; $z++ ) { + next unless ( $arrBiblios[$z] ); + $paging{'next'}->{biblionumber} = + $arrBiblios[$z]; + last; + } last; } - last; } } } + $offsetSearch = 0 + if ( defined($offsetSearch) && $offsetSearch < 0 ); } - $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0); - } - if ($searchAgain) { - my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page); - my @newresults = @$newresultsRef; - # build the new listBiblios - my $listBiblios = buildListBiblios(\@newresults, $results_per_page); - unless (exists($arrParamsBusc{'listBiblios'})) { - $arrParamsBusc{'listBiblios'} = $listBiblios; - @arrBiblios = split(',', $arrParamsBusc{'listBiblios'}); - } else { - $arrParamsBusc{'newlistBiblios'} = $listBiblios; - } - # From the new list we build again the next and previous result - if (@arrBiblios) { - if ($arrBiblios[0] == $biblionumber) { - for (my $j = $#newresults; $j >= 0; $j--) { - next unless ($newresults[$j]); - $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber}; - $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber}; - $arrParamsBusc{'offsetSearch'} = $offsetSearch; - last; + if ($searchAgain) { + my $newresultsRef = + searchAgain( \%arrParamsBusc, $offsetSearch, $results_per_page ); + my @newresults = @$newresultsRef; + + # build the new listBiblios + my $listBiblios = + buildListBiblios( \@newresults, $results_per_page ); + unless ( exists( $arrParamsBusc{'listBiblios'} ) ) { + $arrParamsBusc{'listBiblios'} = $listBiblios; + @arrBiblios = split( ',', $arrParamsBusc{'listBiblios'} ); + } + else { + $arrParamsBusc{'newlistBiblios'} = $listBiblios; + } + + # From the new list we build again the next and previous result + if (@arrBiblios) { + if ( $arrBiblios[0] == $biblionumber ) { + for ( my $j = $#newresults ; $j >= 0 ; $j-- ) { + next unless ( $newresults[$j] ); + $paging{'previous'}->{biblionumber} = + $newresults[$j]->{biblionumber}; + $arrParamsBusc{'previous'} = + $paging{'previous'}->{biblionumber}; + $arrParamsBusc{'offsetSearch'} = $offsetSearch; + last; + } } - } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) { - for (my $j = 0; $j < @newresults; $j++) { - next unless ($newresults[$j]); - $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber}; - $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber}; - $arrParamsBusc{'offsetSearch'} = $offsetSearch; - last; + elsif ( $arrBiblios[$#arrBiblios] == $biblionumber ) { + for ( my $j = 0 ; $j < @newresults ; $j++ ) { + next unless ( $newresults[$j] ); + $paging{'next'}->{biblionumber} = + $newresults[$j]->{biblionumber}; + $arrParamsBusc{'next'} = + $paging{'next'}->{biblionumber}; + $arrParamsBusc{'offsetSearch'} = $offsetSearch; + last; + } } } + + # build new busc param + my $newbusc = rebuildBuscParam( \%arrParamsBusc ); + $session->param( "busc" => $newbusc ); } - # build new busc param - my $newbusc = rebuildBuscParam(\%arrParamsBusc); - $session->param("busc" => $newbusc); - } - my ($previous, $next, $dataBiblioPaging); - # Previous biblio - if ($paging{'previous'}->{biblionumber}) { - $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber} . '&query_desc=' . $query->param('query_desc'); - $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber}); - $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging); - } - # Next biblio - if ($paging{'next'}->{biblionumber}) { - $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber} . '&query_desc=' . $query->param('query_desc'); - $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber}); - $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging); - } - $template->param('previous' => $previous, 'next' => $next); - # Partial list of biblio results - my @listResults; - for (my $j = 0; $j < @arrBiblios; $j++) { - next unless ($arrBiblios[$j]); - $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber); - push @listResults, {index => $j + 1 + $offset, biblionumber => $arrBiblios[$j], title => ($arrBiblios[$j] == $biblionumber)?'':$dataBiblioPaging->{title}, author => ($arrBiblios[$j] != $biblionumber && $dataBiblioPaging->{author})?$dataBiblioPaging->{author}:'', url => ($arrBiblios[$j] == $biblionumber)?'':'opac-detail.pl?biblionumber=' . $arrBiblios[$j]}; + my ( $previous, $next, $dataBiblioPaging ); + + # Previous biblio + if ( $paging{'previous'}->{biblionumber} ) { + $previous = + 'opac-detail.pl?biblionumber=' + . $paging{'previous'}->{biblionumber} + . '&query_desc=' + . $query->param('query_desc'); + $dataBiblioPaging = + GetBiblioData( $paging{'previous'}->{biblionumber} ); + $template->param( 'previousTitle' => $dataBiblioPaging->{'title'} ) + if ($dataBiblioPaging); + } + + # Next biblio + if ( $paging{'next'}->{biblionumber} ) { + $next = + 'opac-detail.pl?biblionumber=' + . $paging{'next'}->{biblionumber} + . '&query_desc=' + . $query->param('query_desc'); + $dataBiblioPaging = + GetBiblioData( $paging{'next'}->{biblionumber} ); + $template->param( 'nextTitle' => $dataBiblioPaging->{'title'} ) + if ($dataBiblioPaging); + } + $template->param( 'previous' => $previous, 'next' => $next ); + + # Partial list of biblio results + my @listResults; + for ( my $j = 0 ; $j < @arrBiblios ; $j++ ) { + next unless ( $arrBiblios[$j] ); + $dataBiblioPaging = GetBiblioData( $arrBiblios[$j] ) + if ( $arrBiblios[$j] != $biblionumber ); + push @listResults, + { + index => $j + 1 + $offset, + biblionumber => $arrBiblios[$j], + title => ( $arrBiblios[$j] == $biblionumber ) ? '' + : $dataBiblioPaging->{title}, + author => ( + $arrBiblios[$j] != $biblionumber + && $dataBiblioPaging->{author} + ) ? $dataBiblioPaging->{author} : '', + url => ( $arrBiblios[$j] == $biblionumber ) ? '' + : 'opac-detail.pl?biblionumber=' . $arrBiblios[$j] + }; + } + $template->param( 'listResults' => \@listResults ) if (@listResults); + $template->param( + 'indexPag' => 1 + $offset, + 'totalPag' => $arrParamsBusc{'total'}, + 'indexPagEnd' => scalar(@arrBiblios) + $offset + ); } - $template->param('listResults' => \@listResults) if (@listResults); - $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset); -} } +$template->param( + 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); +$template->param( 'ItemsIssued' => CountItemsIssued($biblionumber) ); - -$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); - - - -$template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") ); -$template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") ); +$template->param( + 'OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") ); +$template->param( + 'OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") ); # adding items linked via host biblios my $analyticfield = '773'; -if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){ +if ( $marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC' ) { $analyticfield = '773'; -} elsif ($marcflavour eq 'UNIMARC') { +} +elsif ( $marcflavour eq 'UNIMARC' ) { $analyticfield = '461'; } -foreach my $hostfield ( $record->field($analyticfield)) { +foreach my $hostfield ( $record->field($analyticfield) ) { my $hostbiblionumber = $hostfield->subfield("0"); my $linkeditemnumber = $hostfield->subfield("9"); - my @hostitemInfos = GetItemsInfo($hostbiblionumber); - foreach my $hostitemInfo (@hostitemInfos){ - if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){ - push(@all_items, $hostitemInfo); + my @hostitemInfos = GetItemsInfo($hostbiblionumber); + foreach my $hostitemInfo (@hostitemInfos) { + if ( $hostitemInfo->{itemnumber} eq $linkeditemnumber ) { + push( @all_items, $hostitemInfo ); } } } @@ -539,51 +743,70 @@ my @items; # Are there items to hide? my $hideitems; -$hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0; +$hideitems = 1 + if C4::Context->preference('hidelostitems') + or scalar(@hiddenitems) > 0; # Hide items if ($hideitems) { for my $itm (@all_items) { - if ( C4::Context->preference('hidelostitems') ) { - push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems; - } else { - push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems; + if ( C4::Context->preference('hidelostitems') ) { + push @items, $itm + unless $itm->{itemlost} + or any { $itm->{'itemnumber'} eq $_ } @hiddenitems; + } + else { + push @items, $itm + unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems; + } } } -} else { +else { # Or not @items = @all_items; } my $branches = GetBranches(); -my $branch = ''; -if (C4::Context->userenv){ +my $branch = ''; +if ( C4::Context->userenv ) { $branch = C4::Context->userenv->{branch}; } if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { if ( - ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch ) - || - C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' - ) { + ( + ( + C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq + 'PatronBranch' + ) + && $branch + ) + || C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq + 'OpacURLBranch' + ) + { my $branchname; - if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) { + if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq + 'PatronBranch' ) + { $branchname = $branches->{$branch}->{'branchname'}; } - elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) { + elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq + 'OpacURLBranch' ) + { $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'}; } my @our_items; my @other_items; - foreach my $item ( @items ) { - if ( $item->{'branchname'} eq $branchname ) { - $item->{'this_branch'} = 1; - push( @our_items, $item ); - } else { - push( @other_items, $item ); - } + foreach my $item (@items) { + if ( $item->{'branchname'} eq $branchname ) { + $item->{'this_branch'} = 1; + push( @our_items, $item ); + } + else { + push( @other_items, $item ); + } } @items = ( @our_items, @other_items ); @@ -593,22 +816,29 @@ if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { my $dat = &GetBiblioData($biblionumber); my $itemtypes = GetItemTypes(); + # imageurl: my $itemtype = $dat->{'itemtype'}; -if ( $itemtype ) { - $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} ); +if ($itemtype) { + $dat->{'imageurl'} = + getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} ); $dat->{'description'} = $itemtypes->{$itemtype}->{'description'}; } -my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac'); -my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac'); -my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac'); +my $shelflocations = + GetKohaAuthorisedValues( 'items.location', $dat->{'frameworkcode'}, 'opac' ); +my $collections = + GetKohaAuthorisedValues( 'items.ccode', $dat->{'frameworkcode'}, 'opac' ); +my $copynumbers = + GetKohaAuthorisedValues( 'items.copynumber', $dat->{'frameworkcode'}, + 'opac' ); #coping with subscriptions my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); -my @subscriptions = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber ); +my @subscriptions = + GetSubscriptions( $dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber ); my @subs; -$dat->{'serial'}=1 if $subscriptionsnumber; +$dat->{'serial'} = 1 if $subscriptionsnumber; foreach my $subscription (@subscriptions) { my $serials_to_display; my %cell; @@ -619,14 +849,16 @@ foreach my $subscription (@subscriptions) { $cell{histstartdate} = $subscription->{histstartdate}; $cell{histenddate} = $subscription->{histenddate}; $cell{branchcode} = $subscription->{branchcode}; - $cell{branchname} = GetBranchName($subscription->{branchcode}); + $cell{branchname} = GetBranchName( $subscription->{branchcode} ); $cell{hasalert} = $subscription->{hasalert}; $cell{callnumber} = $subscription->{callnumber}; $cell{closed} = $subscription->{closed}; + #get the three latest serials. $serials_to_display = $subscription->{opacdisplaycount}; - $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display; - $cell{opacdisplaycount} = $serials_to_display; + $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') + unless $serials_to_display; + $cell{opacdisplaycount} = $serials_to_display; $cell{latestserials} = GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display ); push @subs, \%cell; @@ -634,171 +866,180 @@ foreach my $subscription (@subscriptions) { $dat->{'count'} = scalar(@items); +my $biblio_authorised_value_images = + C4::Items::get_authorised_value_images( + C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) ); -my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) ); - -my (%item_reserves, %priority); -my ($show_holds_count, $show_priority); +my ( %item_reserves, %priority ); +my ( $show_holds_count, $show_priority ); for ( C4::Context->preference("OPACShowHoldQueueDetails") ) { - m/holds/o and $show_holds_count = 1; - m/priority/ and $show_priority = 1; + m/holds/o and $show_holds_count = 1; + m/priority/ and $show_priority = 1; } my $has_hold; -if ( $show_holds_count || $show_priority) { - my ($reserve_count,$reserves) = GetReservesFromBiblionumber($biblionumber); - $template->param( holds_count => $reserve_count ) if $show_holds_count; +if ( $show_holds_count || $show_priority ) { + my ( $reserve_count, $reserves ) = + GetReservesFromBiblionumber($biblionumber); + $template->param( holds_count => $reserve_count ) if $show_holds_count; foreach (@$reserves) { $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber}; - if ($show_priority && $_->{borrowernumber} == $borrowernumber) { + if ( $show_priority && $_->{borrowernumber} == $borrowernumber ) { $has_hold = 1; $_->{itemnumber} - ? ($priority{ $_->{itemnumber} } = $_->{priority}) - : ($template->param( priority => $_->{priority} )); + ? ( $priority{ $_->{itemnumber} } = $_->{priority} ) + : ( $template->param( priority => $_->{priority} ) ); } } } -$template->param( show_priority => $has_hold ) ; +$template->param( show_priority => $has_hold ); my $norequests = 1; my %itemfields; -my (@itemloop, @otheritemloop); -my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef; -if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) { - $template->param(SeparateHoldings => 1); +my ( @itemloop, @otheritemloop ); +my $currentbranch = + C4::Context->userenv ? C4::Context->userenv->{branch} : undef; +if ( $currentbranch and C4::Context->preference('OpacSeparateHoldings') ) { + $template->param( SeparateHoldings => 1 ); } my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch'); for my $itm (@items) { $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} }; - $itm->{priority} = $priority{ $itm->{itemnumber} }; - $norequests = 0 - if ( (not $itm->{'withdrawn'} ) - && (not $itm->{'itemlost'} ) - && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} ) - && (not $itemtypes->{$itm->{'itype'}}->{notforloan} ) - && ($itm->{'itemnumber'} ) ); + $itm->{priority} = $priority{ $itm->{itemnumber} }; + $norequests = 0 + if ( ( not $itm->{'withdrawn'} ) + && ( not $itm->{'itemlost'} ) + && ( $itm->{'itemnotforloan'} < 0 || not $itm->{'itemnotforloan'} ) + && ( not $itemtypes->{ $itm->{'itype'} }->{notforloan} ) + && ( $itm->{'itemnumber'} ) ); # get collection code description, too my $ccode = $itm->{'ccode'}; - $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) ); + $itm->{'ccode'} = $collections->{$ccode} + if ( defined($collections) && exists( $collections->{$ccode} ) ); my $copynumber = $itm->{'copynumber'}; - $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) ); + $itm->{'copynumber'} = $copynumbers->{$copynumber} + if ( defined($copynumbers) + && defined($copynumber) + && exists( $copynumbers->{$copynumber} ) ); if ( defined $itm->{'location'} ) { - $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} }; + $itm->{'location_description'} = + $shelflocations->{ $itm->{'location'} }; } - if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) { - $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} ); + if ( exists $itm->{itype} + && defined( $itm->{itype} ) + && exists $itemtypes->{ $itm->{itype} } ) + { + $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', + $itemtypes->{ $itm->{itype} }->{'imageurl'} ); $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'}; } foreach (qw(ccode enumchron copynumber itemnotes uri)) { - $itemfields{$_} = 1 if ($itm->{$_}); + $itemfields{$_} = 1 if ( $itm->{$_} ); + } + + # walk through the item-level authorised values and populate some images + my $item_authorised_value_images = + C4::Items::get_authorised_value_images( + C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) ); + +# warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) ); + + if ( $itm->{'itemlost'} ) { + my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } + @$item_authorised_value_images; + $itm->{'lostimageurl'} = $lostimageinfo->{'imageurl'}; + $itm->{'lostimagelabel'} = $lostimageinfo->{'label'}; } + my $reserve_status = C4::Reserves::GetReserveStatus( $itm->{itemnumber} ); + if ( $reserve_status eq "Waiting" ) { $itm->{'waiting'} = 1; } + if ( $reserve_status eq "Reserved" ) { $itm->{'onhold'} = 1; } - # walk through the item-level authorised values and populate some images - my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) ); - # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) ); - - if ( $itm->{'itemlost'} ) { - my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images; - $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' }; - $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' }; - } - my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber}); - if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; } - if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; } - - my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber}); - if ( defined( $transfertwhen ) && $transfertwhen ne '' ) { + my ( $transfertwhen, $transfertfrom, $transfertto ) = + GetTransfers( $itm->{itemnumber} ); + if ( defined($transfertwhen) && $transfertwhen ne '' ) { $itm->{transfertwhen} = $transfertwhen; $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname}; $itm->{transfertto} = $branches->{$transfertto}{branchname}; - } + } my $itembranch = $itm->{$separatebranch}; - if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) { - if ($itembranch and $itembranch eq $currentbranch) { + if ( $currentbranch and C4::Context->preference('OpacSeparateHoldings') ) { + if ( $itembranch and $itembranch eq $currentbranch ) { push @itemloop, $itm; - } else { + } + else { push @otheritemloop, $itm; } - } else { + } + else { push @itemloop, $itm; } } # Display only one tab if one items list is empty -if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) { - $template->param(SeparateHoldings => 0); - if (scalar(@itemloop) == 0) { +if ( scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0 ) { + $template->param( SeparateHoldings => 0 ); + if ( scalar(@itemloop) == 0 ) { @itemloop = @otheritemloop; } } -# If there is a lot of items, and the user has not decided -# to view them all yet, we first warn him -# TODO: The limit of 50 could be a syspref -my $viewallitems = $query->param('viewallitems'); -if (scalar(@itemloop) >= 50 && !$viewallitems) { - $template->param('lotsofholdingsitems' => 1); -} -if (scalar(@otheritemloop) >= 50 && !$viewallitems) { - $template->param('lotsofothersholdingsitems' => 1); -} - ## get notes and subjects from MARC record my $dbh = C4::Context->dbh; -my $marcnotesarray = GetMarcNotes ($record,$marcflavour); -my $marcisbnsarray = GetMarcISBN ($record,$marcflavour); -my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour); -my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); -my $marcseriesarray = GetMarcSeries ($record,$marcflavour); -my $marcurlsarray = GetMarcUrls ($record,$marcflavour); -my $marchostsarray = GetMarcHosts($record,$marcflavour); -my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber)); +my $marcnotesarray = GetMarcNotes( $record, $marcflavour ); +my $marcisbnsarray = GetMarcISBN( $record, $marcflavour ); +my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); +my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); +my $marcseriesarray = GetMarcSeries( $record, $marcflavour ); +my $marcurlsarray = GetMarcUrls( $record, $marcflavour ); +my $marchostsarray = GetMarcHosts( $record, $marcflavour ); +my $subtitle = + GetRecordValue( 'subtitle', $record, GetFrameworkCode($biblionumber) ); - $template->param( - MARCNOTES => $marcnotesarray, - MARCSUBJCTS => $marcsubjctsarray, - MARCAUTHORS => $marcauthorsarray, - MARCSERIES => $marcseriesarray, - MARCURLS => $marcurlsarray, - MARCISBNS => $marcisbnsarray, - MARCHOSTS => $marchostsarray, - norequests => $norequests, - RequestOnOpac => C4::Context->preference("RequestOnOpac"), - itemdata_ccode => $itemfields{ccode}, - itemdata_enumchron => $itemfields{enumchron}, - itemdata_uri => $itemfields{uri}, - itemdata_copynumber => $itemfields{copynumber}, - itemdata_itemnotes => $itemfields{itemnotes}, - authorised_value_images => $biblio_authorised_value_images, - subtitle => $subtitle, - OpacStarRatings => C4::Context->preference("OpacStarRatings"), - ); +$template->param( + MARCNOTES => $marcnotesarray, + MARCSUBJCTS => $marcsubjctsarray, + MARCAUTHORS => $marcauthorsarray, + MARCSERIES => $marcseriesarray, + MARCURLS => $marcurlsarray, + MARCISBNS => $marcisbnsarray, + MARCHOSTS => $marchostsarray, + norequests => $norequests, + RequestOnOpac => C4::Context->preference("RequestOnOpac"), + itemdata_ccode => $itemfields{ccode}, + itemdata_enumchron => $itemfields{enumchron}, + itemdata_uri => $itemfields{uri}, + itemdata_copynumber => $itemfields{copynumber}, + itemdata_itemnotes => $itemfields{itemnotes}, + authorised_value_images => $biblio_authorised_value_images, + subtitle => $subtitle, + OpacStarRatings => C4::Context->preference("OpacStarRatings"), +); -if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) { +if ( C4::Context->preference("AlternateHoldingsField") && scalar @items == 0 ) { my $fieldspec = C4::Context->preference("AlternateHoldingsField"); my $subfields = substr $fieldspec, 3; - my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' '; + my $holdingsep = + C4::Context->preference("AlternateHoldingsSeparator") || ' '; my @alternateholdingsinfo = (); - my @holdingsfields = $record->field(substr $fieldspec, 0, 3); + my @holdingsfields = $record->field( substr $fieldspec, 0, 3 ); for my $field (@holdingsfields) { my %holding = ( holding => '' ); my $havesubfield = 0; - for my $subfield ($field->subfields()) { - if ((index $subfields, $$subfield[0]) >= 0) { - $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0); + for my $subfield ( $field->subfields() ) { + if ( ( index $subfields, $$subfield[0] ) >= 0 ) { + $holding{'holding'} .= $holdingsep + if ( length $holding{'holding'} > 0 ); $holding{'holding'} .= $$subfield[1]; $havesubfield++; } } if ($havesubfield) { - push(@alternateholdingsinfo, \%holding); + push( @alternateholdingsinfo, \%holding ); } } - $template->param( - ALTERNATEHOLDINGS => \@alternateholdingsinfo, - ); + $template->param( ALTERNATEHOLDINGS => \@alternateholdingsinfo, ); } foreach ( keys %{$dat} ) { @@ -808,33 +1049,33 @@ foreach ( keys %{$dat} ) { # some useful variables for enhanced content; # in each case, we're grabbing the first value we find in # the record and normalizing it -my $upc = GetNormalizedUPC($record,$marcflavour); -my $oclc = GetNormalizedOCLCNumber($record,$marcflavour); -my $isbn = GetNormalizedISBN(undef,$record,$marcflavour); +my $upc = GetNormalizedUPC( $record, $marcflavour ); +my $oclc = GetNormalizedOCLCNumber( $record, $marcflavour ); +my $isbn = GetNormalizedISBN( undef, $record, $marcflavour ); my $content_identifier_exists; if ( $isbn or $ean or $oclc or $upc ) { $content_identifier_exists = 1; } $template->param( - normalized_upc => $upc, - normalized_ean => $ean, - normalized_oclc => $oclc, - normalized_isbn => $isbn, - content_identifier_exists => $content_identifier_exists, + normalized_upc => $upc, + normalized_ean => $ean, + normalized_oclc => $oclc, + normalized_isbn => $isbn, + content_identifier_exists => $content_identifier_exists, ); # COinS format FIXME: for books Only -$template->param( - ocoins => GetCOinSBiblio($record), -); +$template->param( ocoins => GetCOinSBiblio($record), ); my $libravatar_enabled = 0; -if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) { +if ( C4::Context->preference('ShowReviewer') + and C4::Context->preference('ShowReviewerPhoto') ) +{ eval { require Libravatar::URL; Libravatar::URL->import(); }; - if (!$@ ) { + if ( !$@ ) { $libravatar_enabled = 1; } } @@ -842,30 +1083,30 @@ if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowRe my $reviews = getreviews( $biblionumber, 1 ); my $loggedincommenter; +foreach (@$reviews) { + my $borrowerData = GetMember( 'borrowernumber' => $_->{borrowernumber} ); - - -foreach ( @$reviews ) { - my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber}); # setting some borrower info into this hash $_->{title} = $borrowerData->{'title'}; $_->{surname} = $borrowerData->{'surname'}; $_->{firstname} = $borrowerData->{'firstname'}; - if ($libravatar_enabled and $borrowerData->{'email'}) { - $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS}); + if ( $libravatar_enabled and $borrowerData->{'email'} ) { + $_->{avatarurl} = libravatar_url( + email => $borrowerData->{'email'}, + https => $ENV{HTTPS} + ); } - $_->{userid} = $borrowerData->{'userid'}; - $_->{cardnumber} = $borrowerData->{'cardnumber'}; + $_->{userid} = $borrowerData->{'userid'}; + $_->{cardnumber} = $borrowerData->{'cardnumber'}; - if ($borrowerData->{'borrowernumber'} eq $borrowernumber) { - $_->{your_comment} = 1; - $loggedincommenter = 1; - } + if ( $borrowerData->{'borrowernumber'} eq $borrowernumber ) { + $_->{your_comment} = 1; + $loggedincommenter = 1; + } } - -if(C4::Context->preference("ISBD")) { - $template->param(ISBD => 1); +if ( C4::Context->preference("ISBD") ) { + $template->param( ISBD => 1 ); } $template->param( @@ -881,228 +1122,258 @@ $template->param( # Lists -if (C4::Context->preference("virtualshelves") ) { - $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) ); +if ( C4::Context->preference("virtualshelves") ) { + $template->param( 'GetShelves' => GetBibliosShelves($biblionumber) ); } - # XISBN Stuff -if (C4::Context->preference("OPACFRBRizeEditions")==1) { - eval { - $template->param( - XISBNS => get_xisbns($isbn) - ); - }; +if ( C4::Context->preference("OPACFRBRizeEditions") == 1 ) { + eval { $template->param( XISBNS => get_xisbns($isbn) ); }; if ($@) { warn "XISBN Failed $@"; } } # Serial Collection my @sc_fields = $record->field(955); -my @lc_fields = $marcflavour eq 'UNIMARC' - ? $record->field(930) - : $record->field(852); +my @lc_fields = + $marcflavour eq 'UNIMARC' + ? $record->field(930) + : $record->field(852); my @serialcollections = (); foreach my $sc_field (@sc_fields) { my %row_data; - $row_data{text} = $sc_field->subfield('r'); - $row_data{branch} = $sc_field->subfield('9'); + $row_data{text} = $sc_field->subfield('r'); + $row_data{branch} = $sc_field->subfield('9'); foreach my $lc_field (@lc_fields) { $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC' - ? $lc_field->subfield('a') # 930$a - : $lc_field->subfield('h') # 852$h - if ($sc_field->subfield('5') eq $lc_field->subfield('5')); + ? $lc_field->subfield('a') # 930$a + : $lc_field->subfield('h') # 852$h + if ( $sc_field->subfield('5') eq $lc_field->subfield('5') ); } - if ($row_data{text} && $row_data{branch}) { - push (@serialcollections, \%row_data); + if ( $row_data{text} && $row_data{branch} ) { + push( @serialcollections, \%row_data ); } } -if (scalar(@serialcollections) > 0) { +if ( scalar(@serialcollections) > 0 ) { $template->param( - serialcollection => 1, - serialcollections => \@serialcollections); + serialcollection => 1, + serialcollections => \@serialcollections + ); } # Local cover Images stuff -if (C4::Context->preference("OPACLocalCoverImages")){ - $template->param(OPACLocalCoverImages => 1); +if ( C4::Context->preference("OPACLocalCoverImages") ) { + $template->param( OPACLocalCoverImages => 1 ); } # HTML5 Media -if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) { - $template->param( C4::HTML5Media->gethtml5media($record)); +if ( ( C4::Context->preference("HTML5MediaEnabled") eq 'both' ) + or ( C4::Context->preference("HTML5MediaEnabled") eq 'opac' ) ) +{ + $template->param( C4::HTML5Media->gethtml5media($record) ); } my $syndetics_elements; if ( C4::Context->preference("SyndeticsEnabled") ) { - $template->param("SyndeticsEnabled" => 1); - $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode")); - eval { - $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc); - for my $element (values %$syndetics_elements) { - $template->param("Syndetics$element"."Exists" => 1 ); - #warn "Exists: "."Syndetics$element"."Exists"; - } + $template->param( "SyndeticsEnabled" => 1 ); + $template->param( + "SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode") + ); + eval { + $syndetics_elements = &get_syndetics_index( $isbn, $upc, $oclc ); + for my $element ( values %$syndetics_elements ) { + $template->param( "Syndetics$element" . "Exists" => 1 ); + + #warn "Exists: "."Syndetics$element"."Exists"; + } }; warn $@ if $@; } -if ( C4::Context->preference("SyndeticsEnabled") - && C4::Context->preference("SyndeticsSummary") - && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) { - eval { - my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements); - $template->param( SYNDETICS_SUMMARY => $syndetics_summary ); - }; - warn $@ if $@; +if ( + C4::Context->preference("SyndeticsEnabled") + && C4::Context->preference("SyndeticsSummary") + && ( exists( $syndetics_elements->{'SUMMARY'} ) + || exists( $syndetics_elements->{'AVSUMMARY'} ) ) + ) +{ + eval { + my $syndetics_summary = + &get_syndetics_summary( $isbn, $upc, $oclc, $syndetics_elements ); + $template->param( SYNDETICS_SUMMARY => $syndetics_summary ); + }; + warn $@ if $@; } -if ( C4::Context->preference("SyndeticsEnabled") - && C4::Context->preference("SyndeticsTOC") - && exists($syndetics_elements->{'TOC'}) ) { - eval { - my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc); - $template->param( SYNDETICS_TOC => $syndetics_toc ); - }; - warn $@ if $@; +if ( C4::Context->preference("SyndeticsEnabled") + && C4::Context->preference("SyndeticsTOC") + && exists( $syndetics_elements->{'TOC'} ) ) +{ + eval { + my $syndetics_toc = &get_syndetics_toc( $isbn, $upc, $oclc ); + $template->param( SYNDETICS_TOC => $syndetics_toc ); + }; + warn $@ if $@; } -if ( C4::Context->preference("SyndeticsEnabled") +if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("SyndeticsExcerpt") - && exists($syndetics_elements->{'DBCHAPTER'}) ) { + && exists( $syndetics_elements->{'DBCHAPTER'} ) ) +{ eval { - my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc); - $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt ); + my $syndetics_excerpt = &get_syndetics_excerpt( $isbn, $upc, $oclc ); + $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt ); }; - warn $@ if $@; + warn $@ if $@; } -if ( C4::Context->preference("SyndeticsEnabled") - && C4::Context->preference("SyndeticsReviews")) { +if ( C4::Context->preference("SyndeticsEnabled") + && C4::Context->preference("SyndeticsReviews") ) +{ eval { - my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements); - $template->param( SYNDETICS_REVIEWS => $syndetics_reviews ); + my $syndetics_reviews = + &get_syndetics_reviews( $isbn, $upc, $oclc, $syndetics_elements ); + $template->param( SYNDETICS_REVIEWS => $syndetics_reviews ); }; - warn $@ if $@; + warn $@ if $@; } -if ( C4::Context->preference("SyndeticsEnabled") +if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("SyndeticsAuthorNotes") - && exists($syndetics_elements->{'ANOTES'}) ) { + && exists( $syndetics_elements->{'ANOTES'} ) ) +{ eval { - my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc); - $template->param( SYNDETICS_ANOTES => $syndetics_anotes ); + my $syndetics_anotes = &get_syndetics_anotes( $isbn, $upc, $oclc ); + $template->param( SYNDETICS_ANOTES => $syndetics_anotes ); }; warn $@ if $@; } # LibraryThingForLibraries ID Code and Tabbed View Option -if( C4::Context->preference('LibraryThingForLibrariesEnabled') ) -{ -$template->param(LibraryThingForLibrariesID => -C4::Context->preference('LibraryThingForLibrariesID') ); -$template->param(LibraryThingForLibrariesTabbedView => -C4::Context->preference('LibraryThingForLibrariesTabbedView') ); -} +if ( C4::Context->preference('LibraryThingForLibrariesEnabled') ) { + $template->param( LibraryThingForLibrariesID => + C4::Context->preference('LibraryThingForLibrariesID') ); + $template->param( LibraryThingForLibrariesTabbedView => + C4::Context->preference('LibraryThingForLibrariesTabbedView') ); +} # Novelist Select -if( C4::Context->preference('NovelistSelectEnabled') ) -{ -$template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') ); -$template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') ); -$template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') ); -} - +if ( C4::Context->preference('NovelistSelectEnabled') ) { + $template->param( NovelistSelectProfile => + C4::Context->preference('NovelistSelectProfile') ); + $template->param( NovelistSelectPassword => + C4::Context->preference('NovelistSelectPassword') ); + $template->param( + NovelistSelectView => C4::Context->preference('NovelistSelectView') ); +} # Babelthèque if ( C4::Context->preference("Babeltheque") ) { - $template->param( - Babeltheque => 1, + $template->param( + Babeltheque => 1, Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"), ); } # Social Networks -if ( C4::Context->preference( "SocialNetworks" ) ) { - $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" ); +if ( C4::Context->preference("SocialNetworks") ) { + $template->param( current_url => C4::Context->preference('OPACBaseURL') + . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" ); $template->param( SocialNetworks => 1 ); } # Shelf Browser Stuff -if (C4::Context->preference("OPACShelfBrowser")) { +if ( C4::Context->preference("OPACShelfBrowser") ) { my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); - if (defined($starting_itemnumber)) { - $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber; + if ( defined($starting_itemnumber) ) { + $template->param( OpenOPACShelfBrowser => 1 ) if $starting_itemnumber; my $nearby = GetNearbyItems($starting_itemnumber); $template->param( starting_itemnumber => $starting_itemnumber, - starting_homebranch => $nearby->{starting_homebranch}->{description}, + starting_homebranch => + $nearby->{starting_homebranch}->{description}, starting_location => $nearby->{starting_location}->{description}, - starting_ccode => $nearby->{starting_ccode}->{description}, + starting_ccode => $nearby->{starting_ccode}->{description}, shelfbrowser_prev_item => $nearby->{prev_item}, shelfbrowser_next_item => $nearby->{next_item}, - shelfbrowser_items => $nearby->{items}, + shelfbrowser_items => $nearby->{items}, ); # in which tab shelf browser should open ? - if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) { - $template->param(shelfbrowser_tab => 'holdings'); - } else { - $template->param(shelfbrowser_tab => 'otherholdings'); + if ( grep { $starting_itemnumber == $_->{itemnumber} } @itemloop ) { + $template->param( shelfbrowser_tab => 'holdings' ); + } + else { + $template->param( shelfbrowser_tab => 'otherholdings' ); } } } -$template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages")); - -if (C4::Context->preference("BakerTaylorEnabled")) { - $template->param( - BakerTaylorEnabled => 1, - BakerTaylorImageURL => &image_url(), - BakerTaylorLinkURL => &link_url(), - BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'), - ); - my ($bt_user, $bt_pass); - if ($isbn and - $bt_user = C4::Context->preference('BakerTaylorUsername') and - $bt_pass = C4::Context->preference('BakerTaylorPassword') ) - { - $template->param( - BakerTaylorContentURL => - sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y", - $bt_user,$bt_pass,$isbn) - ); - } +$template->param( AmazonTld => get_amazon_tld() ) + if ( C4::Context->preference("OPACAmazonCoverImages") ); + +if ( C4::Context->preference("BakerTaylorEnabled") ) { + $template->param( + BakerTaylorEnabled => 1, + BakerTaylorImageURL => &image_url(), + BakerTaylorLinkURL => &link_url(), + BakerTaylorBookstoreURL => + C4::Context->preference('BakerTaylorBookstoreURL'), + ); + my ( $bt_user, $bt_pass ); + if ( $isbn + and $bt_user = C4::Context->preference('BakerTaylorUsername') + and $bt_pass = C4::Context->preference('BakerTaylorPassword') ) + { + $template->param( + BakerTaylorContentURL => sprintf( +"http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y", + $bt_user, $bt_pass, $isbn + ) + ); + } } my $tag_quantity; -if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) { - $template->param( - TagsEnabled => 1, - TagsShowOnDetail => $tag_quantity, - TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail') - ); - $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1, - 'sort'=>'-weight', limit=>$tag_quantity})); +if ( C4::Context->preference('TagsEnabled') + and $tag_quantity = C4::Context->preference('TagsShowOnDetail') ) +{ + $template->param( + TagsEnabled => 1, + TagsShowOnDetail => $tag_quantity, + TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail') + ); + $template->param( + TagLoop => get_tags( + { + biblionumber => $biblionumber, + approved => 1, + 'sort' => '-weight', + limit => $tag_quantity + } + ) + ); } -if (C4::Context->preference("OPACURLOpenInNewWindow")) { +if ( C4::Context->preference("OPACURLOpenInNewWindow") ) { + # These values are going to be read by Javascript, at least in the case # of the google covers - $template->param(covernewwindow => 'true'); -} else { - $template->param(covernewwindow => 'false'); + $template->param( covernewwindow => 'true' ); +} +else { + $template->param( covernewwindow => 'false' ); } #Export options -my $OpacExportOptions=C4::Context->preference("OpacExportOptions"); -my @export_options = split(/\|/,$OpacExportOptions); +my $OpacExportOptions = C4::Context->preference("OpacExportOptions"); +my @export_options = split( /\|/, $OpacExportOptions ); $template->{VARS}->{'export_options'} = \@export_options; if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) { @@ -1117,13 +1388,13 @@ if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) { } #Search for title in links -my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); -my $marcissns = GetMarcISSN ( $record, $marcflavour ); +my $marccontrolnumber = GetMarcControlnumber( $record, $marcflavour ); +my $marcissns = GetMarcISSN( $record, $marcflavour ); my $issn = $marcissns->[0] || ''; -if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ - $dat->{title} =~ s/\/+$//; # remove trailing slash - $dat->{title} =~ s/\s+$//; # remove trailing space +if ( my $search_for_title = C4::Context->preference('OPACSearchForTitleIn') ) { + $dat->{title} =~ s/\/+$//; # remove trailing slash + $dat->{title} =~ s/\s+$//; # remove trailing space $search_for_title = parametrized_url( $search_for_title, { @@ -1135,43 +1406,46 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ BIBLIONUMBER => $biblionumber, } ); - $template->param('OPACSearchForTitleIn' => $search_for_title); + $template->param( 'OPACSearchForTitleIn' => $search_for_title ); } # We try to select the best default tab to show, according to what # the user wants, and what's available for display my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab'); -my $defaulttab = - $opac_serial_default eq 'subscriptions' && $subscriptionsnumber - ? 'subscriptions' : - $opac_serial_default eq 'serialcollection' && @serialcollections > 0 - ? 'serialcollection' : - $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0 - ? 'holdings' : - $subscriptionsnumber - ? 'subscriptions' : - @serialcollections > 0 - ? 'serialcollection' : 'subscriptions'; -$template->param('defaulttab' => $defaulttab); - -if (C4::Context->preference('OPACLocalCoverImages') == 1) { +my $defaulttab = + $opac_serial_default eq 'subscriptions' + && $subscriptionsnumber ? 'subscriptions' + : $opac_serial_default eq 'serialcollection' + && @serialcollections > 0 ? 'serialcollection' + : $opac_serial_default eq 'holdings' && scalar(@itemloop) > 0 ? 'holdings' + : $subscriptionsnumber ? 'subscriptions' + : @serialcollections > 0 ? 'serialcollection' + : 'subscriptions'; +$template->param( 'defaulttab' => $defaulttab ); + +if ( C4::Context->preference('OPACLocalCoverImages') == 1 ) { my @images = ListImagesForBiblio($biblionumber); $template->{VARS}->{localimages} = \@images; } -$template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews'); -$template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer'); -$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults'); -$template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch'); +$template->{VARS}->{IDreamBooksReviews} = + C4::Context->preference('IDreamBooksReviews'); +$template->{VARS}->{IDreamBooksReadometer} = + C4::Context->preference('IDreamBooksReadometer'); +$template->{VARS}->{IDreamBooksResults} = + C4::Context->preference('IDreamBooksResults'); +$template->{VARS}->{OPACPopupAuthorsSearch} = + C4::Context->preference('OPACPopupAuthorsSearch'); -if (C4::Context->preference('OpacHighlightedWords')) { +if ( C4::Context->preference('OpacHighlightedWords') ) { $template->{VARS}->{query_desc} = $query->param('query_desc'); } $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks'); if ( C4::Context->preference('UseCourseReserves') ) { - foreach my $i ( @items ) { - $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} ); + foreach my $i (@items) { + $i->{'course_reserves'} = + GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} ); } } ## Defining general Serial issue filter related system preferences @@ -1179,6 +1453,7 @@ if ( C4::Context->preference('UseCourseReserves') ) { if ( length C4::Context->preference('NumberingFormulaParsingRegexp') < 3 ) { $template->{VARS}->{notDefined_NumberingFormulaParsingRegexp} = 1; } -$template->{VARS}->{useFilterIssueInput} = 1 if (C4::Context->preference('FilterSerialsByIssue')); +$template->{VARS}->{useFilterIssueInput} = 1 + if ( C4::Context->preference('FilterSerialsByIssue') ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 59b8416..30e639b 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -145,7 +145,7 @@ subtest 'GetHiddenItemnumbers tests' => sub { subtest 'Filter items tests' => sub { - plan tests => 2; + plan tests => 3; # Start transaction $dbh->{AutoCommit} = 0; @@ -173,6 +173,10 @@ subtest 'Filter items tests' => sub { # Testing the dates filter my @shouldBeEmpty = C4::Items::GetItemsInfo($biblionumber, {toDate => '01/01/1933'}); is( scalar(@shouldBeEmpty), 0, "Filtering by date"); + + # Testing the limit filter + @shouldBeEmpty = C4::Items::GetItemsInfo($biblionumber, {limit => 0}); + is( scalar(@shouldBeEmpty), 0, "Filtering by limit"); }; # Helper method to set up a Biblio. -- 1.8.1.2