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

(-)a/C4/Biblio.pm (-15 / +52 lines)
Lines 1249-1266 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
1261
sub GetMarcBiblio {
1276
sub GetMarcBiblio {
1262
    my $biblionumber = shift;
1277
    my $biblionumber = shift;
1263
    my $embeditems   = shift || 0;
1278
    my $embeditems   = shift || 0;
1279
    my $opac         = shift || 0;
1264
    my $dbh          = C4::Context->dbh;
1280
    my $dbh          = C4::Context->dbh;
1265
    my $sth          = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
1281
    my $sth          = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
1266
    $sth->execute($biblionumber);
1282
    $sth->execute($biblionumber);
Lines 1270-1284 sub GetMarcBiblio { Link Here
1270
    my $record = MARC::Record->new();
1286
    my $record = MARC::Record->new();
1271
1287
1272
    if ($marcxml) {
1288
    if ($marcxml) {
1273
        $record = eval { MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour') ) };
1289
        $record = eval {
1290
            MARC::Record::new_from_xml( $marcxml, "utf8",
1291
                C4::Context->preference('marcflavour') );
1292
        };
1274
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1293
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1275
        return unless $record;
1294
        return unless $record;
1276
1295
1277
        C4::Biblio::_koha_marc_update_bib_ids($record, '', $biblionumber, $biblionumber);
1296
        C4::Biblio::_koha_marc_update_bib_ids( $record, '', $biblionumber,
1278
	C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems);
1297
            $biblionumber );
1298
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber, undef, $opac )
1299
          if ($embeditems);
1279
1300
1280
        return $record;
1301
        return $record;
1281
    } else {
1302
    }
1303
    else {
1282
        return;
1304
        return;
1283
    }
1305
    }
1284
}
1306
}
Lines 2876-2892 sub ModZebra { Link Here
2876
2898
2877
=head2 EmbedItemsInMarcBiblio
2899
=head2 EmbedItemsInMarcBiblio
2878
2900
2879
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers);
2901
    EmbedItemsInMarcBiblio($marc, $biblionumber, $itemnumbers, $opac);
2880
2902
2881
Given a MARC::Record object containing a bib record,
2903
Given a MARC::Record object containing a bib record,
2882
modify it to include the items attached to it as 9XX
2904
modify it to include the items attached to it as 9XX
2883
per the bib's MARC framework.
2905
per the bib's MARC framework.
2884
if $itemnumbers is defined, only specified itemnumbers are embedded
2906
if $itemnumbers is defined, only specified itemnumbers are embedded.
2907
2908
If $opac is true, then opac-relevant suppressions are included.
2885
2909
2886
=cut
2910
=cut
2887
2911
2888
sub EmbedItemsInMarcBiblio {
2912
sub EmbedItemsInMarcBiblio {
2889
    my ($marc, $biblionumber, $itemnumbers) = @_;
2913
    my ($marc, $biblionumber, $itemnumbers, $opac) = @_;
2890
    if ( !$marc ) {
2914
    if ( !$marc ) {
2891
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2915
        carp 'EmbedItemsInMarcBiblio: No MARC record passed';
2892
        return;
2916
        return;
Lines 2903-2912 sub EmbedItemsInMarcBiblio { Link Here
2903
    $sth->execute($biblionumber);
2927
    $sth->execute($biblionumber);
2904
    my @item_fields;
2928
    my @item_fields;
2905
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2929
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
2906
    while (my ($itemnumber) = $sth->fetchrow_array) {
2930
    my @items;
2931
    my $opachiddenitems = $opac
2932
      && ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ );
2933
    require C4::Items;
2934
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2907
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2935
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2908
        require C4::Items;
2936
        my $i = C4::Items::GetItem($itemnumber) if $opachiddenitems;
2909
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2937
        push @items, { itemnumber => $itemnumber, item => $i };
2938
    }
2939
    my @hiddenitems =
2940
      C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items )
2941
      if $opachiddenitems;
2942
    # Convert to a hash for quick searching
2943
    my %hiddenitems = map { $_ => 1 } @hiddenitems;
2944
    foreach my $itemnumber ( map { $_->{itemnumber} } @items ) {
2945
        next if $hiddenitems{$itemnumber};
2946
        my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
2910
        push @item_fields, $item_marc->field($itemtag);
2947
        push @item_fields, $item_marc->field($itemtag);
2911
    }
2948
    }
2912
    $marc->append_fields(@item_fields);
2949
    $marc->append_fields(@item_fields);
(-)a/opac/oai.pl (-2 / +1 lines)
Lines 280-286 sub new { Link Here
280
280
281
    # We fetch it using this method, rather than the database directly,
281
    # We fetch it using this method, rather than the database directly,
282
    # so it'll include the item data
282
    # so it'll include the item data
283
    my $record = GetMarcBiblio($biblionumber, 1);
283
    my $record = GetMarcBiblio($biblionumber, 1, 1);
284
    my $marcxml = $record->as_xml();
284
    my $marcxml = $record->as_xml();
285
    my $oai_sets = GetOAISetsBiblio($biblionumber);
285
    my $oai_sets = GetOAISetsBiblio($biblionumber);
286
    my @setSpecs;
286
    my @setSpecs;
287
- 

Return to bug 12252