Bug 29697: Remove GetHiddenItemnumbers
[koha-ffzg.git] / opac / opac-tags.pl
index f9dd207..c8f5d15 100755 (executable)
@@ -34,13 +34,14 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use CGI::Cookie; # need to check cookies before having CGI parse the POST request
+use Array::Utils qw( array_minus );
 
 use C4::Auth qw( check_cookie_auth get_template_and_user );
 use C4::Context;
 use C4::Output qw( output_with_http_headers is_ajax output_html_with_http_headers );
 use C4::Scrubber;
 use C4::Biblio qw( GetMarcBiblio );
-use C4::Items qw( GetHiddenItemnumbers GetItemsInfo );
+use C4::Items qw( GetItemsInfo );
 use C4::Tags qw(
     add_tag
     get_approval_rows
@@ -69,7 +70,7 @@ sub ajax_auth_cgi {     # returns CGI object
     my %cookies = CGI::Cookie->fetch;
        my $input = CGI->new;
     my $sessid = $cookies{'CGISESSID'}->value;
-       my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags);
+    my ($auth_status) = check_cookie_auth($sessid, $needed_flags);
        if ($auth_status ne "ok") {
                output_with_http_headers $input, undef,
                "window.alert('Your CGI session cookie ($sessid) is not current.  " .
@@ -226,7 +227,6 @@ if ($is_ajax) {
 
 my $results = [];
 my $my_tags = [];
-my $borcat  = q{};
 
 if ($loggedinuser) {
     my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } );
@@ -258,15 +258,12 @@ if ($loggedinuser) {
             opac         => 1,
             borcat       => $borcat });
         next unless $record;
-        my $hidden_items = undef;
-        my @hidden_itemnumbers;
-        my @all_items;
+        my @hidden_items;
         if ($should_hide) {
-            @all_items = GetItemsInfo( $tag->{biblionumber} );
-            @hidden_itemnumbers = GetHiddenItemnumbers({
-                items => \@all_items,
-                borcat => $borcat });
-            $hidden_items = \@hidden_itemnumbers;
+            my $items = $biblio->items;
+            my @all_itemnumbers = $items->get_column('itemnumber');
+            my @items_to_show = $items->filter_by_visible_in_opac({ opac => 1, patron => $patron })->as_list;
+            @hidden_items = array_minus( @all_itemnumbers, @items_to_show );
         }
         next
           if (
@@ -285,22 +282,19 @@ if ($loggedinuser) {
         # BZ17530: 'Intelligent' guess if result can be article requested
         $tag->{artreqpossible} = ( $art_req_itypes->{ $tag->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{};
 
-        my $xslfile = C4::Context->preference('OPACXSLTResultsDisplay');
-        my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
-        my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
-
-        if ($xslfile) {
-            my $variables = {
-                anonymous_session => ($loggedinuser) ? 0 : 1
-            };
-            $tag->{XSLTBloc} = XSLTParse4Display(
-                $tag->{biblionumber},     $record,
-                "OPACXSLTResultsDisplay", 1,
-                $hidden_items,            $sysxml,
-                $xslfile,                 $lang,
-                $variables
-            );
-        }
+        my $variables = {
+            anonymous_session => ($loggedinuser) ? 0 : 1
+        };
+        $tag->{XSLTBloc} = XSLTParse4Display(
+            {
+                biblionumber   => $tag->{biblionumber},
+                record         => $record,
+                xsl_syspref    => 'OPACXSLTResultsDisplay',
+                fix_amps       => 1,
+                hidden_items   => \@hidden_items,
+                xslt_variables => $variables
+            }
+        );
 
         my $date = $tag->{date_created} || '';
         $date =~ /\s+(\d{2}\:\d{2}\:\d{2})/;