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

(-)a/C4/Biblio.pm (+6 lines)
Lines 2809-2814 sub EmbedItemsInMarcBiblio { Link Here
2809
2809
2810
    $itemnumbers = [] unless defined $itemnumbers;
2810
    $itemnumbers = [] unless defined $itemnumbers;
2811
2811
2812
    if ( C4::Context->preference('SummaryHoldings') && !@$itemnumbers ) {
2813
        require C4::Holdings;
2814
        my $holdings_fields = C4::Holdings::GetMarcHoldingsFields( $biblionumber );
2815
        $marc->append_fields(@$holdings_fields) if ( @$holdings_fields );
2816
    }
2817
2812
    my $frameworkcode = GetFrameworkCode($biblionumber);
2818
    my $frameworkcode = GetFrameworkCode($biblionumber);
2813
    _strip_item_fields($marc, $frameworkcode);
2819
    _strip_item_fields($marc, $frameworkcode);
2814
2820
(-)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/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