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

(-)a/C4/Biblio.pm (+25 lines)
Lines 366-371 sub _strip_item_fields { Link Here
366
    }
366
    }
367
}
367
}
368
368
369
=head2 _strip_holdings_fields
370
371
  _strip_holdings_fields($record)
372
373
Utility routine to remove holdings tags from a
374
MARC bib.
375
376
=cut
377
378
sub _strip_holdings_fields {
379
    my $record = shift;
380
    my $frameworkcode = shift;
381
    my ( $holdingstag ) = GetMarcFromKohaField( "holdings.holdingbranch" );
382
    foreach my $field ( $record->field($holdingstag) ) {
383
        $record->delete_field($field);
384
    }
385
}
386
369
=head2 DelBiblio
387
=head2 DelBiblio
370
388
371
  my $error = &DelBiblio($biblionumber);
389
  my $error = &DelBiblio($biblionumber);
Lines 2809-2814 sub EmbedItemsInMarcBiblio { Link Here
2809
2827
2810
    $itemnumbers = [] unless defined $itemnumbers;
2828
    $itemnumbers = [] unless defined $itemnumbers;
2811
2829
2830
    if ( C4::Context->preference('SummaryHoldings') && !@$itemnumbers ) {
2831
        _strip_holdings_fields($marc);
2832
        require C4::Holdings;
2833
        my $holdings_fields = C4::Holdings::GetMarcHoldingsFields( $biblionumber );
2834
        $marc->append_fields(@$holdings_fields) if ( @$holdings_fields );
2835
    }
2836
2812
    my $frameworkcode = GetFrameworkCode($biblionumber);
2837
    my $frameworkcode = GetFrameworkCode($biblionumber);
2813
    _strip_item_fields($marc, $frameworkcode);
2838
    _strip_item_fields($marc, $frameworkcode);
2814
2839
(-)a/C4/Holdings.pm (+75 lines)
Lines 415-420 sub GetMarcHoldingsByBiblionumber { Link Here
415
    return \@records;
415
    return \@records;
416
}
416
}
417
417
418
=head2 GetMarcHoldingsFields
419
420
  my @marc_fields = GetMarcHoldingsFields($biblionumber);
421
422
Returns an array of MARC::Record objects of the holdings for the biblio.
423
424
=cut
425
426
sub GetMarcHoldingsFields {
427
	my ( $biblionumber ) = @_;
428
    # This is so much faster than using Koha::Holdings->search that it makes sense even if it's ugly.
429
    my $sth = C4::Context->dbh->prepare( 'SELECT * FROM holdings WHERE biblionumber = ?' );
430
    $sth->execute( $biblionumber );
431
    my $holdings = $sth->fetchall_arrayref({});
432
    $sth->finish();
433
    my @holdings_fields;
434
    my ( $holdingstag, $holdingssubfield ) = GetMarcHoldingFromKohaField( 'holdings.holdingbranch' );
435
    ITEMLOOP: foreach my $holding (@$holdings) {
436
        my $mungedholding = {
437
            map {
438
                defined($holding->{$_}) && $holding->{$_} ne '' ? ("holdings.$_" => $holding->{$_}) : ()
439
            } keys %{ $holding }
440
        };
441
        my $marc = TransformKohaHoldingToMarc($mungedholding);
442
        push @holdings_fields, $marc->field( $holdingstag );
443
    }
444
    return \@holdings_fields;
445
}
446
418
=head2 GetHoldingFrameworkCode
447
=head2 GetHoldingFrameworkCode
419
448
420
  $frameworkcode = GetFrameworkCode( $holding_id )
449
  $frameworkcode = GetFrameworkCode( $holding_id )
Lines 773-778 sub TransformMarcHoldingToKohaOneField { Link Here
773
    return $retval;
802
    return $retval;
774
}
803
}
775
804
805
=head2 TransformKohaToMarc
806
807
    $record = TransformKohaToMarc( $hash [, $params ] )
808
809
This function builds partial MARC::Record from holdings hash entries.
810
This function is called when embedding holdings into a biblio record.
811
812
=cut
813
814
sub TransformKohaHoldingToMarc {
815
    my ( $hash, $params ) = @_;
816
    my $record = MARC::Record->new();
817
    SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") );
818
819
    # In the next call we use the Default holdings framework, since it is considered
820
    # authoritative for Koha to Marc mappings.
821
    my $mss = C4::Biblio::GetMarcSubfieldStructure( 'HLD', { unsafe => 1 } ); # do not change framewok
822
    my $tag_hr = {};
823
    while ( my ($kohafield, $value) = each %$hash ) {
824
        foreach my $fld ( @{ $mss->{$kohafield} } ) {
825
            my $tagfield    = $fld->{tagfield};
826
            my $tagsubfield = $fld->{tagsubfield};
827
            next if !$tagfield;
828
            my @values = $params->{no_split}
829
                ? ( $value )
830
                : split(/\s?\|\s?/, $value, -1);
831
            foreach my $value ( @values ) {
832
                next if $value eq '';
833
                $tag_hr->{$tagfield} //= [];
834
                push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)];
835
            }
836
        }
837
    }
838
    foreach my $tag (sort keys %$tag_hr) {
839
        my @sfl = @{$tag_hr->{$tag}};
840
        @sfl = sort { $a->[0] cmp $b->[0]; } @sfl;
841
        @sfl = map { @{$_}; } @sfl;
842
        # Special care for control fields: remove the subfield indication @
843
        # and do not insert indicators.
844
        my @ind = $tag < 10 ? () : ( " ", " " );
845
        @sfl = grep { $_ ne '@' } @sfl if $tag < 10;
846
        $record->insert_fields_ordered( MARC::Field->new($tag, @ind, @sfl) );
847
    }
848
    return $record;
849
}
850
776
1;
851
1;
777
852
778
853
(-)a/Koha/OAI/Server/Repository.pm (-1 / +1 lines)
Lines 93-98 mode. A configuration file koha-oai.conf can look like that: Link Here
93
      xsl_file: /usr/local/koha/koha-tmpl/intranet-tmpl/xslt/UNIMARCslim2OAIDC.xsl
93
      xsl_file: /usr/local/koha/koha-tmpl/intranet-tmpl/xslt/UNIMARCslim2OAIDC.xsl
94
94
95
Note the 'include_items' parameter which is the only mean to return item-level info.
95
Note the 'include_items' parameter which is the only mean to return item-level info.
96
If summary holdings are enabled, 'include_items' includes their location information too.
96
97
97
=cut
98
=cut
98
99
99
- 

Return to bug 20447