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 1276-1290 sub GetMarcBiblio { Link Here
1276
    my $record = MARC::Record->new();
1291
    my $record = MARC::Record->new();
1277
1292
1278
    if ($marcxml) {
1293
    if ($marcxml) {
1279
        $record = eval { MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour') ) };
1294
        $record = eval {
1295
            MARC::Record::new_from_xml( $marcxml, "utf8",
1296
                C4::Context->preference('marcflavour') );
1297
        };
1280
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1298
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1281
        return unless $record;
1299
        return unless $record;
1282
1300
1283
        C4::Biblio::_koha_marc_update_bib_ids($record, '', $biblionumber, $biblionumber);
1301
        C4::Biblio::_koha_marc_update_bib_ids( $record, '', $biblionumber,
1284
	C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems);
1302
            $biblionumber );
1303
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac )
1304
          if ($embeditems);
1285
1305
1286
        return $record;
1306
        return $record;
1287
    } else {
1307
    }
1308
    else {
1288
        return;
1309
        return;
1289
    }
1310
    }
1290
}
1311
}
Lines 2883-2899 sub ModZebra { Link Here
2883
2904
2884
=head2 EmbedItemsInMarcBiblio
2905
=head2 EmbedItemsInMarcBiblio
2885
2906
2886
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers);
2907
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac);
2887
2908
2888
Given a MARC::Record object containing a bib record,
2909
Given a MARC::Record object containing a bib record,
2889
modify it to include the items attached to it as 9XX
2910
modify it to include the items attached to it as 9XX
2890
per the bib's MARC framework.
2911
per the bib's MARC framework.
2891
if $itemnumbers is defined, only specified itemnumbers are embedded
2912
if $itemnumbers is defined, only specified itemnumbers are embedded.
2913
2914
If $opac is true, then opac-relevant suppressions are included.
2892
2915
2893
=cut
2916
=cut
2894
2917
2895
sub EmbedItemsInMarcBiblio {
2918
sub EmbedItemsInMarcBiblio {
2896
    my ($marc, $biblionumber, $itemnumbers) = @_;
2919
    my ($marc, $biblionumber, $itemnumbers, $opac) = @_;
2897
    if ( !$marc ) {
2920
    if ( !$marc ) {
2898
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2921
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2899
        return;
2922
        return;
Lines 2910-2919 sub EmbedItemsInMarcBiblio { Link Here
2910
    $sth->execute($biblionumber);
2933
    $sth->execute($biblionumber);
2911
    my @item_fields;
2934
    my @item_fields;
2912
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2935
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2913
    while (my ($itemnumber) = $sth->fetchrow_array) {
2936
    my @items;
2937
    my $opachiddenitems = $opac
2938
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2939
    require C4::Items;
2940
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2914
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2941
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2915
        require C4::Items;
2942
        my $i = C4::Items::GetItem($itemnumber) if $opachiddenitems;
2916
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2943
        push @items, { itemnumber => $itemnumber, item => $i };
2944
    }
2945
    my @hiddenitems =
2946
      C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items )
2947
      if $opachiddenitems;
2948
    # Convert to a hash for quick searching
2949
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
2950
    foreach my $itemnumber ( map { $_->{itemnumber} } @items ) {
2951
        next if $hiddenitems{$itemnumber};
2952
        my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
2917
        push @item_fields, $item_marc->field($itemtag);
2953
        push @item_fields, $item_marc->field($itemtag);
2918
    }
2954
    }
2919
    $marc->append_fields(@item_fields);
2955
    $marc->append_fields(@item_fields);
2920
- 

Return to bug 12252