+ my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } );
+ my $rules = C4::Context->yaml_preference('OpacHiddenItems');
+ my $should_hide = ( $rules ) ? 1 : 0;
+ $my_tags = get_tag_rows({borrowernumber=>$loggedinuser});
+ my $my_approved_tags = get_approval_rows({ approved => 1 });
+
+ my $art_req_itypes;
+ if( C4::Context->preference('ArticleRequests') ) {
+ $art_req_itypes = Koha::CirculationRules->guess_article_requestable_itemtypes({ $patron ? ( categorycode => $patron->categorycode ) : () });
+ }
+
+ # get biblionumbers stored in the cart
+ my @cart_list;
+
+ if($query->cookie("bib_list")){
+ my $cart_list = $query->cookie("bib_list");
+ @cart_list = split(/\//, $cart_list);
+ }
+
+ foreach my $tag (@$my_tags) {
+ $tag->{visible} = 0;
+ my $biblio = Koha::Biblios->find( $tag->{biblionumber} );
+ my $record = $biblio->metadata->record(
+ {
+ embed_items => 1,
+ opac => 1,
+ patron => $patron,
+ }
+ );
+ next unless $record;
+ my @hidden_items;
+ if ($should_hide) {
+ my $items = $biblio->items->search_ordered;
+ 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 (
+ (
+ !$patron
+ or ( $patron and !$patron->category->override_hidden_items )
+ )
+ and $biblio->hidden_in_opac( { rules => $rules } )
+ );
+ $tag->{title} = $biblio->title;
+ $tag->{subtitle} = $biblio->subtitle;
+ $tag->{medium} = $biblio->medium;
+ $tag->{part_number} = $biblio->part_number;
+ $tag->{part_name} = $biblio->part_name;
+ $tag->{author} = $biblio->author;
+ # BZ17530: 'Intelligent' guess if result can be article requested
+ $tag->{artreqpossible} = ( $art_req_itypes->{ $tag->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{};
+
+ 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})/;
+ $tag->{time_created_display} = $1;
+ $tag->{approved} = ( grep { $_->{term} eq $tag->{term} and $_->{approved} } @$my_approved_tags );
+ $tag->{visible} = 1;
+ # while we're checking each line, see if item is in the cart
+ if ( grep {$_ eq $biblio->biblionumber} @cart_list) {
+ $tag->{incart} = 1;
+ }
+ }