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

(-)a/C4/Biblio.pm (+6 lines)
Lines 2821-2826 sub EmbedItemsInMarcBiblio { Link Here
2821
2821
2822
    $itemnumbers = [] unless defined $itemnumbers;
2822
    $itemnumbers = [] unless defined $itemnumbers;
2823
2823
2824
    if ( C4::Context->preference('SummaryHoldings') && !@$itemnumbers ) {
2825
        require C4::Holdings;
2826
        my $holdings_fields = C4::Holdings::GetMarcHoldingsFields( $biblionumber );
2827
        $marc->append_fields(@$holdings_fields) if ( @$holdings_fields );
2828
    }
2829
2824
    my $frameworkcode = GetFrameworkCode($biblionumber);
2830
    my $frameworkcode = GetFrameworkCode($biblionumber);
2825
    _strip_item_fields($marc, $frameworkcode);
2831
    _strip_item_fields($marc, $frameworkcode);
2826
2832
(-)a/C4/Holdings.pm (+76 lines)
Lines 426-431 sub GetMarcHoldingsByBiblionumber { Link Here
426
    return \@records;
426
    return \@records;
427
}
427
}
428
428
429
=head2 GetMarcHoldingsFields
430
431
  my @marc_fields = GetMarcHoldingsFields($biblionumber);
432
433
Returns an array of MARC::Record objects of the holdings for the biblio.
434
435
=cut
436
437
sub GetMarcHoldingsFields {
438
	my ( $biblionumber ) = @_;
439
    # This is so much faster than using Koha::Holdings->search that it makes sense even if it's ugly.
440
    my $sth = C4::Context->dbh->prepare( 'SELECT * FROM holdings WHERE biblionumber = ?' );
441
    $sth->execute( $biblionumber );
442
    my $holdings = $sth->fetchall_arrayref({});
443
    $sth->finish();
444
    my @holdings_fields;
445
    my ( $holdingstag, $holdingssubfield ) = GetMarcHoldingFromKohaField( 'holdings.holdingbranch' );
446
    ITEMLOOP: foreach my $holding (@$holdings) {
447
        my $mungedholding = {
448
            map {
449
                defined($holding->{$_}) && $holding->{$_} ne '' ? ("holdings.$_" => $holding->{$_}) : ()
450
            } keys %{ $holding }
451
        };
452
        my $marc = TransformKohaHoldingToMarc($mungedholding);
453
        push @holdings_fields, $marc->field( $holdingstag );
454
    }
455
    return \@holdings_fields;
456
}
457
429
=head2 GetHoldingFrameworkCode
458
=head2 GetHoldingFrameworkCode
430
459
431
  $frameworkcode = GetFrameworkCode( $holding_id )
460
  $frameworkcode = GetFrameworkCode( $holding_id )
Lines 788-793 sub TransformMarcHoldingToKohaOneField { Link Here
788
    return $retval;
817
    return $retval;
789
}
818
}
790
819
820
=head2 TransformKohaHoldingToMarc
821
822
    $record = TransformKohaToMarc( $hash [, $params ] )
823
824
This function builds partial MARC::Record from holdings hash entries.
825
This function is called when embedding holdings into a biblio record.
826
827
=cut
828
829
sub TransformKohaHoldingToMarc {
830
    my ( $hash, $params ) = @_;
831
832
    my $record = MARC::Record->new();
833
    SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") );
834
835
    # In the next call we use the Default holdings framework, since it is considered
836
    # authoritative for Koha to Marc mappings.
837
    my $mss = C4::Biblio::GetMarcSubfieldStructure( 'HLD', { unsafe => 1 } ); # do not change framewok
838
    my $tag_hr = {};
839
    while ( my ($kohafield, $value) = each %$hash ) {
840
        foreach my $fld ( @{ $mss->{$kohafield} } ) {
841
            my $tagfield    = $fld->{tagfield};
842
            my $tagsubfield = $fld->{tagsubfield};
843
            next if !$tagfield;
844
            my @values = $params->{no_split}
845
                ? ( $value )
846
                : split(/\s?\|\s?/, $value, -1);
847
            foreach my $value ( @values ) {
848
                next if $value eq '';
849
                $tag_hr->{$tagfield} //= [];
850
                push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)];
851
            }
852
        }
853
    }
854
    foreach my $tag (sort keys %$tag_hr) {
855
        my @sfl = @{$tag_hr->{$tag}};
856
        @sfl = sort { $a->[0] cmp $b->[0]; } @sfl;
857
        @sfl = map { @{$_}; } @sfl;
858
        # Special care for control fields: remove the subfield indication @
859
        # and do not insert indicators.
860
        my @ind = $tag < 10 ? () : ( " ", " " );
861
        @sfl = grep { $_ ne '@' } @sfl if $tag < 10;
862
        $record->insert_fields_ordered( MARC::Field->new($tag, @ind, @sfl) );
863
    }
864
    return $record;
865
}
866
791
1;
867
1;
792
868
793
869
(-)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