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

(-)a/C4/Biblio.pm (-15 / +51 lines)
Lines 1261-1278 sub GetMarcSubfieldStructureFromKohaField { Link Here
1261
1261
1262
=head2 GetMarcBiblio
1262
=head2 GetMarcBiblio
1263
1263
1264
  my $record = GetMarcBiblio($biblionumber, [$embeditems]);
1264
  my $record = GetMarcBiblio($biblionumber, [$embeditems], [$opac]);
1265
1265
1266
Returns MARC::Record representing bib identified by
1266
Returns MARC::Record representing a biblio record, or C<undef> if the
1267
C<$biblionumber>.  If no bib exists, returns undef.
1267
biblionumber doesn't exist.
1268
C<$embeditems>.  If set to true, items data are included.
1268
1269
The MARC record contains biblio data, and items data if $embeditems is set to true.
1269
=over 4
1270
1271
=item C<$biblionumber>
1272
1273
the biblionumber
1274
1275
=item C<$embeditems>
1276
1277
set to true to include item information.
1278
1279
=item C<$opac>
1280
1281
set to true to make the result suited for OPAC view. This causes things like
1282
OpacHiddenItems to be applied.
1283
1284
=back
1270
1285
1271
=cut
1286
=cut
1272
1287
1273
sub GetMarcBiblio {
1288
sub GetMarcBiblio {
1274
    my $biblionumber = shift;
1289
    my $biblionumber = shift;
1275
    my $embeditems   = shift || 0;
1290
    my $embeditems   = shift || 0;
1291
    my $opac         = shift || 0;
1276
    my $dbh          = C4::Context->dbh;
1292
    my $dbh          = C4::Context->dbh;
1277
    my $sth          = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
1293
    my $sth          = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
1278
    $sth->execute($biblionumber);
1294
    $sth->execute($biblionumber);
Lines 1282-1296 sub GetMarcBiblio { Link Here
1282
    my $record = MARC::Record->new();
1298
    my $record = MARC::Record->new();
1283
1299
1284
    if ($marcxml) {
1300
    if ($marcxml) {
1285
        $record = eval { MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour') ) };
1301
        $record = eval {
1302
            MARC::Record::new_from_xml( $marcxml, "utf8",
1303
                C4::Context->preference('marcflavour') );
1304
        };
1286
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1305
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1287
        return unless $record;
1306
        return unless $record;
1288
1307
1289
        C4::Biblio::_koha_marc_update_bib_ids($record, '', $biblionumber, $biblionumber);
1308
        C4::Biblio::_koha_marc_update_bib_ids( $record, '', $biblionumber,
1290
	C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems);
1309
            $biblionumber );
1310
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac )
1311
          if ($embeditems);
1291
1312
1292
        return $record;
1313
        return $record;
1293
    } else {
1314
    }
1315
    else {
1294
        return;
1316
        return;
1295
    }
1317
    }
1296
}
1318
}
Lines 2882-2893 sub ModZebra { Link Here
2882
2904
2883
=head2 EmbedItemsInMarcBiblio
2905
=head2 EmbedItemsInMarcBiblio
2884
2906
2885
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers);
2907
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac);
2886
2908
2887
Given a MARC::Record object containing a bib record,
2909
Given a MARC::Record object containing a bib record,
2888
modify it to include the items attached to it as 9XX
2910
modify it to include the items attached to it as 9XX
2889
per the bib's MARC framework.
2911
per the bib's MARC framework.
2890
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.
2891
2915
2892
=cut
2916
=cut
2893
2917
Lines 2909-2918 sub EmbedItemsInMarcBiblio { Link Here
2909
    $sth->execute($biblionumber);
2933
    $sth->execute($biblionumber);
2910
    my @item_fields;
2934
    my @item_fields;
2911
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2935
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2912
    while (my ($itemnumber) = $sth->fetchrow_array) {
2936
    my @items;
2937
    my $opachiddenitems =
2938
      ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2939
    require C4::Items;
2940
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2913
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2941
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2914
        require C4::Items;
2942
        my $i = C4::Items::GetItem($itemnumber) if $opachiddenitems;
2915
        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 );
2916
        push @item_fields, $item_marc->field($itemtag);
2953
        push @item_fields, $item_marc->field($itemtag);
2917
    }
2954
    }
2918
    $marc->append_fields(@item_fields);
2955
    $marc->append_fields(@item_fields);
2919
- 

Return to bug 12252