View | Details | Raw Unified | Return to bug 12252
Collapse All | Expand All

(-)a/C4/Biblio.pm (-16 / +51 lines)
Lines 1249-1260 sub GetMarcSubfieldStructureFromKohaField { Link Here
1249
1249
1250
=head2 GetMarcBiblio
1250
=head2 GetMarcBiblio
1251
1251
1252
  my $record = GetMarcBiblio($biblionumber, [$embeditems]);
1252
  my $record = GetMarcBiblio($biblionumber, [$embeditems], [$opac]);
1253
1253
1254
Returns MARC::Record representing bib identified by
1254
Returns MARC::Record representing a biblio record, or C<undef> if the
1255
C<$biblionumber>.  If no bib exists, returns undef.
1255
biblionumber doesn't exist.
1256
C<$embeditems>.  If set to true, items data are included.
1256
1257
The MARC record contains biblio data, and items data if $embeditems is set to true.
1257
=over 4
1258
1259
=item C<$biblionumber>
1260
1261
the biblionumber
1262
1263
=item C<$embeditems>
1264
1265
set to true to include item information.
1266
1267
=item C<$opac>
1268
1269
set to true to make the result suited for OPAC view. This causes things like
1270
OpacHiddenItems to be applied.
1271
1272
=back
1258
1273
1259
=cut
1274
=cut
1260
1275
Lines 1278-1292 sub GetMarcBiblio { Link Here
1278
    my $record = MARC::Record->new();
1293
    my $record = MARC::Record->new();
1279
1294
1280
    if ($marcxml) {
1295
    if ($marcxml) {
1281
        $record = eval { MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour') ) };
1296
        $record = eval {
1297
            MARC::Record::new_from_xml( $marcxml, "utf8",
1298
                C4::Context->preference('marcflavour') );
1299
        };
1282
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1300
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1283
        return unless $record;
1301
        return unless $record;
1284
1302
1285
        C4::Biblio::_koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber);
1303
        C4::Biblio::_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber,
1286
        C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems);
1304
            $biblioitemnumber );
1305
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac )
1306
          if ($embeditems);
1287
1307
1288
        return $record;
1308
        return $record;
1289
    } else {
1309
    }
1310
    else {
1290
        return;
1311
        return;
1291
    }
1312
    }
1292
}
1313
}
Lines 2885-2901 sub ModZebra { Link Here
2885
2906
2886
=head2 EmbedItemsInMarcBiblio
2907
=head2 EmbedItemsInMarcBiblio
2887
2908
2888
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers);
2909
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac);
2889
2910
2890
Given a MARC::Record object containing a bib record,
2911
Given a MARC::Record object containing a bib record,
2891
modify it to include the items attached to it as 9XX
2912
modify it to include the items attached to it as 9XX
2892
per the bib's MARC framework.
2913
per the bib's MARC framework.
2893
if $itemnumbers is defined, only specified itemnumbers are embedded
2914
if $itemnumbers is defined, only specified itemnumbers are embedded.
2915
2916
If $opac is true, then opac-relevant suppressions are included.
2894
2917
2895
=cut
2918
=cut
2896
2919
2897
sub EmbedItemsInMarcBiblio {
2920
sub EmbedItemsInMarcBiblio {
2898
    my ($marc, $biblionumber, $itemnumbers) = @_;
2921
    my ($marc, $biblionumber, $itemnumbers, $opac) = @_;
2899
    if ( !$marc ) {
2922
    if ( !$marc ) {
2900
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2923
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2901
        return;
2924
        return;
Lines 2912-2921 sub EmbedItemsInMarcBiblio { Link Here
2912
    $sth->execute($biblionumber);
2935
    $sth->execute($biblionumber);
2913
    my @item_fields;
2936
    my @item_fields;
2914
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2937
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2915
    while (my ($itemnumber) = $sth->fetchrow_array) {
2938
    my @items;
2939
    my $opachiddenitems = $opac
2940
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2941
    require C4::Items;
2942
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2916
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2943
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2917
        require C4::Items;
2944
        my $i = C4::Items::GetItem($itemnumber) if $opachiddenitems;
2918
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2945
        push @items, { itemnumber => $itemnumber, item => $i };
2946
    }
2947
    my @hiddenitems =
2948
      C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items )
2949
      if $opachiddenitems;
2950
    # Convert to a hash for quick searching
2951
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
2952
    foreach my $itemnumber ( map { $_->{itemnumber} } @items ) {
2953
        next if $hiddenitems{$itemnumber};
2954
        my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
2919
        push @item_fields, $item_marc->field($itemtag);
2955
        push @item_fields, $item_marc->field($itemtag);
2920
    }
2956
    }
2921
    $marc->append_fields(@item_fields);
2957
    $marc->append_fields(@item_fields);
2922
- 

Return to bug 12252