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

(-)a/C4/Biblio.pm (+6 lines)
Lines 2791-2796 sub EmbedItemsInMarcBiblio { Link Here
2791
2791
2792
    $itemnumbers = [] unless defined $itemnumbers;
2792
    $itemnumbers = [] unless defined $itemnumbers;
2793
2793
2794
    if ( C4::Context->preference('SummaryHoldings') && !@$itemnumbers ) {
2795
        require C4::Holdings;
2796
        my $holdings_fields = C4::Holdings::GetMarcHoldingsFields( $biblionumber );
2797
        $marc->append_fields(@$holdings_fields) if ( @$holdings_fields );
2798
    }
2799
2794
    my $frameworkcode = GetFrameworkCode($biblionumber);
2800
    my $frameworkcode = GetFrameworkCode($biblionumber);
2795
    _strip_item_fields($marc, $frameworkcode);
2801
    _strip_item_fields($marc, $frameworkcode);
2796
2802
(-)a/C4/Holdings.pm (+75 lines)
Lines 414-419 sub GetMarcHoldingsByBiblionumber { Link Here
414
    return \@records;
414
    return \@records;
415
}
415
}
416
416
417
=head2 GetMarcHoldingsFields
418
419
  my @marc_fields = GetMarcHoldingsFields($biblionumber);
420
421
Returns an array of MARC::Record objects of the holdings for the biblio.
422
423
=cut
424
425
sub GetMarcHoldingsFields {
426
	my ( $biblionumber ) = @_;
427
    # This is so much faster than using Koha::Holdings->search that it makes sense even if it's ugly.
428
    my $sth = C4::Context->dbh->prepare( 'SELECT * FROM holdings WHERE biblionumber = ?' );
429
    $sth->execute( $biblionumber );
430
    my $holdings = $sth->fetchall_arrayref({});
431
    $sth->finish();
432
    my @holdings_fields;
433
    my ( $holdingstag, $holdingssubfield ) = GetMarcHoldingFromKohaField( 'holdings.holdingbranch' );
434
    ITEMLOOP: foreach my $holding (@$holdings) {
435
        my $mungedholding = {
436
            map {
437
                defined($holding->{$_}) && $holding->{$_} ne '' ? ("holdings.$_" => $holding->{$_}) : ()
438
            } keys %{ $holding }
439
        };
440
        my $marc = TransformKohaHoldingToMarc($mungedholding);
441
        push @holdings_fields, $marc->field( $holdingstag );
442
    }
443
    return \@holdings_fields;
444
}
445
417
=head2 GetHoldingFrameworkCode
446
=head2 GetHoldingFrameworkCode
418
447
419
  $frameworkcode = GetFrameworkCode( $holding_id )
448
  $frameworkcode = GetFrameworkCode( $holding_id )
Lines 775-780 sub TransformMarcHoldingToKohaOneField { Link Here
775
    return $retval;
804
    return $retval;
776
}
805
}
777
806
807
=head2 TransformKohaToMarc
808
809
    $record = TransformKohaToMarc( $hash [, $params ] )
810
811
This function builds partial MARC::Record from holdings hash entries.
812
This function is called when embedding holdings into a biblio record.
813
814
=cut
815
816
sub TransformKohaHoldingToMarc {
817
    my ( $hash, $params ) = @_;
818
    my $record = MARC::Record->new();
819
    SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") );
820
821
    # In the next call we use the Default holdings framework, since it is considered
822
    # authoritative for Koha to Marc mappings.
823
    my $mss = C4::Biblio::GetMarcSubfieldStructure( 'HLD', { unsafe => 1 } ); # do not change framewok
824
    my $tag_hr = {};
825
    while ( my ($kohafield, $value) = each %$hash ) {
826
        foreach my $fld ( @{ $mss->{$kohafield} } ) {
827
            my $tagfield    = $fld->{tagfield};
828
            my $tagsubfield = $fld->{tagsubfield};
829
            next if !$tagfield;
830
            my @values = $params->{no_split}
831
                ? ( $value )
832
                : split(/\s?\|\s?/, $value, -1);
833
            foreach my $value ( @values ) {
834
                next if $value eq '';
835
                $tag_hr->{$tagfield} //= [];
836
                push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)];
837
            }
838
        }
839
    }
840
    foreach my $tag (sort keys %$tag_hr) {
841
        my @sfl = @{$tag_hr->{$tag}};
842
        @sfl = sort { $a->[0] cmp $b->[0]; } @sfl;
843
        @sfl = map { @{$_}; } @sfl;
844
        # Special care for control fields: remove the subfield indication @
845
        # and do not insert indicators.
846
        my @ind = $tag < 10 ? () : ( " ", " " );
847
        @sfl = grep { $_ ne '@' } @sfl if $tag < 10;
848
        $record->insert_fields_ordered( MARC::Field->new($tag, @ind, @sfl) );
849
    }
850
    return $record;
851
}
852
778
1;
853
1;
779
854
780
855
(-)a/Koha/OAI/Server/ListBase.pm (-2 / +8 lines)
Lines 69-76 sub GetRecords { Link Here
69
        if ($include_items) {
69
        if ($include_items) {
70
            $sql .= "
70
            $sql .= "
71
                OR biblionumber IN (SELECT biblionumber from deleteditems WHERE timestamp >= ? AND timestamp <= ?)
71
                OR biblionumber IN (SELECT biblionumber from deleteditems WHERE timestamp >= ? AND timestamp <= ?)
72
                OR biblionumber IN (SELECT biblionumber from holdings WHERE timestamp >= ? AND timestamp <= ?)
72
            ";
73
            ";
73
            push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'});
74
            push @bind_params, ($token->{'from_arg'}, $token->{'until_arg'}, $token->{'from_arg'}, $token->{'until_arg'});
74
            if (!$deleted) {
75
            if (!$deleted) {
75
                $sql .= "
76
                $sql .= "
76
                    OR biblionumber IN (SELECT biblionumber from items WHERE timestamp >= ? AND timestamp <= ?)
77
                    OR biblionumber IN (SELECT biblionumber from items WHERE timestamp >= ? AND timestamp <= ?)
Lines 106-111 sub GetRecords { Link Here
106
                    SELECT timestamp FROM deletedbiblio_metadata WHERE biblionumber = ?
107
                    SELECT timestamp FROM deletedbiblio_metadata WHERE biblionumber = ?
107
                    UNION
108
                    UNION
108
                    SELECT timestamp FROM deleteditems WHERE biblionumber = ?
109
                    SELECT timestamp FROM deleteditems WHERE biblionumber = ?
110
                    UNION
111
                    SELECT timestamp FROM holdings WHERE biblionumber = ?
109
                ) bis
112
                ) bis
110
            ";
113
            ";
111
        } else {
114
        } else {
Lines 117-122 sub GetRecords { Link Here
117
                    SELECT timestamp FROM deleteditems WHERE biblionumber = ?
120
                    SELECT timestamp FROM deleteditems WHERE biblionumber = ?
118
                    UNION
121
                    UNION
119
                    SELECT timestamp FROM items WHERE biblionumber = ?
122
                    SELECT timestamp FROM items WHERE biblionumber = ?
123
                    UNION
124
                    SELECT timestamp FROM holdings WHERE biblionumber = ?
120
                ) bi
125
                ) bi
121
            ";
126
            ";
122
        }
127
        }
Lines 139-145 sub GetRecords { Link Here
139
                );
144
                );
140
                last STAGELOOP;
145
                last STAGELOOP;
141
            }
146
            }
142
            my @params = $deleted ? ( $biblionumber, $biblionumber ) : ( $biblionumber, $biblionumber, $biblionumber );
147
            my @params = $deleted ? ( $biblionumber, $biblionumber, $biblionumber ) 
148
                : ( $biblionumber, $biblionumber, $biblionumber, $biblionumber );
143
            $record_sth->execute( @params ) || die( 'Could not execute statement: ' . $sth->errstr );
149
            $record_sth->execute( @params ) || die( 'Could not execute statement: ' . $sth->errstr );
144
150
145
            my ($timestamp) = $record_sth->fetchrow;
151
            my ($timestamp) = $record_sth->fetchrow;
(-)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