| 
      
            Line 0
          
      
      
        Link Here
      
     | 
  
          
            
              | 0 | 
              -   | 
              1 | 
              package Koha::Filter::MARC::EmbedItems;  | 
            
            
               | 
               | 
              2 | 
               | 
            
            
              | 3 | 
              # Copyright 2019  Theke Solutions  | 
            
            
              | 4 | 
               | 
            
            
              | 5 | 
              # This file is part of Koha.  | 
            
            
              | 6 | 
              #  | 
            
            
              | 7 | 
              # Koha is free software; you can redistribute it and/or modify it  | 
            
            
              | 8 | 
              # under the terms of the GNU General Public License as published by  | 
            
            
              | 9 | 
              # the Free Software Foundation; either version 3 of the License, or  | 
            
            
              | 10 | 
              # (at your option) any later version.  | 
            
            
              | 11 | 
              #  | 
            
            
              | 12 | 
              # Koha is distributed in the hope that it will be useful, but  | 
            
            
              | 13 | 
              # WITHOUT ANY WARRANTY; without even the implied warranty of  | 
            
            
              | 14 | 
              # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  | 
            
            
              | 15 | 
              # GNU General Public License for more details.  | 
            
            
              | 16 | 
              #  | 
            
            
              | 17 | 
              # You should have received a copy of the GNU General Public License  | 
            
            
              | 18 | 
              # along with Koha; if not, see <http://www.gnu.org/licenses>.  | 
            
            
              | 19 | 
               | 
            
            
              | 20 | 
              =head1 NAME  | 
            
            
              | 21 | 
               | 
            
            
              | 22 | 
              Koha::Filter::MARC::EmbedItems - Appends item information on MARC::Record objects.  | 
            
            
              | 23 | 
               | 
            
            
              | 24 | 
              =head1 SYNOPSIS  | 
            
            
              | 25 | 
               | 
            
            
              | 26 | 
              my $biblio = Koha::Biblios->find(  | 
            
            
              | 27 | 
                  $biblio_id,  | 
            
            
              | 28 | 
                  { prefetch => [ items, metadata ] } | 
            
            
              | 29 | 
              );  | 
            
            
              | 30 | 
               | 
            
            
              | 31 | 
              my $opachiddenitems_rules;  | 
            
            
              | 32 | 
              eval { | 
            
            
              | 33 | 
                  my $yaml = C4::Context->preference('OpacHiddenItems') . "\n\n"; | 
            
            
              | 34 | 
                  $opachiddenitems_rules = YAML::Load($yaml);  | 
            
            
              | 35 | 
              };  | 
            
            
              | 36 | 
               | 
            
            
              | 37 | 
              my @items  = grep { !$_->hidden_in_opac({ rules => $opachiddenitems_rules }) @{$biblio->items}; | 
            
            
              | 38 | 
              my $record = $biblio->metadata->record;  | 
            
            
              | 39 | 
               | 
            
            
              | 40 | 
              my $processor = Koha::RecordProcessor->new(  | 
            
            
              | 41 | 
                  { | 
            
            
              | 42 | 
                      filters => ('EmbedItems'), | 
            
            
              | 43 | 
                      options => { | 
            
            
              | 44 | 
                          items        => \@items,  | 
            
            
              | 45 | 
                          item_tag     => $item_tag,  | 
            
            
              | 46 | 
                          biblionumber => $biblionumber  | 
            
            
              | 47 | 
                      }  | 
            
            
              | 48 | 
                  }  | 
            
            
              | 49 | 
              );  | 
            
            
              | 50 | 
               | 
            
            
              | 51 | 
              $processor->process( $record );  | 
            
            
              | 52 | 
               | 
            
            
              | 53 | 
              =head1 DESCRIPTION  | 
            
            
              | 54 | 
               | 
            
            
              | 55 | 
              Filter to embed items information into MARC::Record objects.  | 
            
            
              | 56 | 
               | 
            
            
              | 57 | 
              =cut  | 
            
            
              | 58 | 
               | 
            
            
              | 59 | 
              use Modern::Perl;  | 
            
            
              | 60 | 
               | 
            
            
              | 61 | 
              use C4::Items qw(Item2Marc);  | 
            
            
              | 62 | 
               | 
            
            
              | 63 | 
              use base qw(Koha::RecordProcessor::Base);  | 
            
            
              | 64 | 
              our $NAME = 'EmbedItems';  | 
            
            
              | 65 | 
               | 
            
            
              | 66 | 
              =head2 filter  | 
            
            
              | 67 | 
               | 
            
            
              | 68 | 
              Embed items into the MARC::Record object.  | 
            
            
              | 69 | 
               | 
            
            
              | 70 | 
              =cut  | 
            
            
              | 71 | 
               | 
            
            
              | 72 | 
              sub filter { | 
            
            
              | 73 | 
                  my $self   = shift;  | 
            
            
              | 74 | 
                  my $record = shift;  | 
            
            
              | 75 | 
               | 
            
            
              | 76 | 
                  return unless defined $record and ref($record) eq 'MARC::Record';  | 
            
            
              | 77 | 
               | 
            
            
              | 78 | 
                  my $items        = $self->{options}->{items}; | 
            
            
              | 79 | 
                  my $item_tag     = $self->{options}->{item_tag}; | 
            
            
              | 80 | 
                  my $biblionumber = $self->{options}->{biblionumber}; | 
            
            
              | 81 | 
               | 
            
            
              | 82 | 
                  my @item_fields;  | 
            
            
              | 83 | 
               | 
            
            
              | 84 | 
                  foreach my $item ( @{$items} ) { | 
            
            
              | 85 | 
                      my $item_marc = Item2Marc( $item->unblessed, $biblionumber );  | 
            
            
              | 86 | 
                      push @item_fields, $item_marc->field($item_tag);  | 
            
            
              | 87 | 
                  }  | 
            
            
              | 88 | 
               | 
            
            
              | 89 | 
                  $record->append_fields(@item_fields);  | 
            
            
              | 90 | 
               | 
            
            
              | 91 | 
                  return $record;  | 
            
            
              | 92 | 
              }  | 
            
            
              | 93 | 
               | 
            
            
              | 94 | 
              1;  |