@@ -, +, @@ sysprefs --- C4/Circulation.pm | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -4321,6 +4321,7 @@ sub GetTopIssues { FROM biblio b LEFT JOIN items i ON (i.biblionumber = b.biblionumber) LEFT JOIN biblioitems bi ON (bi.biblionumber = b.biblionumber) + LEFT JOIN biblio_metadata bm ON (bm.biblionumber = b.biblionumber) }; my (@where_strs, @where_args); @@ -4347,6 +4348,58 @@ sub GetTopIssues { push @where_args, $newness; } + my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems'); + if ( $opachiddenitems_rules ){ + #NOTE: OpacHiddenItemsHidesRecord isn't relevant here since the bib won't appear if there is no items to appear anyway + my $userenv = C4::Context->userenv; + my $logged_in_user = Koha::Patrons->find( $userenv->{number} ) if $userenv; + my $logged_in_categorycode = $logged_in_user->categorycode if $logged_in_user; + my $hide_items = 1; + if (my $exceptions = C4::Context->preference('OpacHiddenItemsExceptions') && $logged_in_categorycode){ + foreach my $except (split(/\|/, $exceptions)){ + if ( $except eq $logged_in_categorycode ){ + $hide_items = 0; + last; + } + } + } + if ($hide_items){ + my %where = (); + my @keys = keys %$opachiddenitems_rules; + foreach my $key (@keys){ + #NOTE: Add "i." table alias to field names + #NOTE: Generate SQL::Abstract data structure + $where{ "i." . $key } = { '!=' => [ -and => @{$opachiddenitems_rules->{$key}} ] }; + } + if (%where){ + require SQL::Abstract; + my $sql = SQL::Abstract->new; + my ($stmt, @bind) = $sql->where(\%where); + if ($stmt){ + $stmt =~ s/^ WHERE //; + push(@where_strs,$stmt); + push(@where_args,@bind); + } + } + } + } + + if ( C4::Context->preference('OpacSuppression') ){ + my $hide_items = 1; + if (C4::Context->preference('OpacSuppressionByIPRange')) { + my $IPAddress = $ENV{'REMOTE_ADDR'}; + my $IPRange = C4::Context->preference('OpacSuppressionByIPRange'); + if ($IPAddress =~ /^$IPRange/){ + $hide_items = 0; + } + } + if ($hide_items){ + my $stmt = q#( ExtractValue(bm.metadata,'//datafield[@tag="942"]/subfield[@code="n"]') <> ? )#; + push(@where_strs, $stmt); + push(@where_args, 1); + } + } + if (@where_strs) { $query .= 'WHERE ' . join(' AND ', @where_strs); } --