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

(-)a/C4/Record.pm (-41 / +44 lines)
Lines 847-852 sub marc2bibtex { Link Here
847
    return $tex;
847
    return $tex;
848
}
848
}
849
849
850
850
=head2 marc2cites - Convert from MARC21 and UNIMARC to citations
851
=head2 marc2cites - Convert from MARC21 and UNIMARC to citations
851
852
852
  my $cites = marc2cites($record);
853
  my $cites = marc2cites($record);
Lines 859-939 C<$record> - a MARC::Record object Link Here
859
=cut
860
=cut
860
861
861
sub marc2cites {
862
sub marc2cites {
862
    my $record = shift;
863
    my $record      = shift;
863
    my $marcflavour = C4::Context->preference("marcflavour");
864
    my $marcflavour = C4::Context->preference("marcflavour");
864
    my %cites = ();
865
    my %cites       = ();
865
    my @authors = ();
866
    my @authors     = ();
866
    my $re_clean = qr/(^[\.,:;\/\-\s]+|[\.,:;\/\-\s]+$)/;
867
    my $re_clean    = qr/(^[\.,:;\/\-\s]+|[\.,:;\/\-\s]+$)/;
867
868
868
    my @authorFields = ('100','110','111','700','710','711');
869
    my @authorFields = ( '100', '110', '111', '700', '710', '711' );
869
    @authorFields = ('700','701','702','710','711','721') if ( $marcflavour eq "UNIMARC" );
870
    @authorFields = ( '700', '701', '702', '710', '711', '721' ) if ( $marcflavour eq "UNIMARC" );
870
871
871
    foreach my $ftag ( @authorFields ) {
872
    foreach my $ftag (@authorFields) {
872
        foreach my $field ($record->field($ftag)) {
873
        foreach my $field ( $record->field($ftag) ) {
873
            my $author = '';
874
            my $author = '';
874
            if ( $marcflavour eq "UNIMARC" ) {
875
            if ( $marcflavour eq "UNIMARC" ) {
875
                $author = join ', ',
876
                $author = join ', ',
876
                ( $field->subfield("a"), $field->subfield("b") );
877
                    ( $field->subfield("a"), $field->subfield("b") );
877
            } else {
878
            } else {
878
                $author = $field->subfield("a");
879
                $author = $field->subfield("a");
879
            }
880
            }
880
            if($author =~ /([^,]+),?(.*)/) {
881
            if ( $author =~ /([^,]+),?(.*)/ ) {
881
                my %a;
882
                my %a;
882
                ($a{'surname'} = $1) =~ s/$re_clean//g;
883
                ( $a{'surname'} = $1 ) =~ s/$re_clean//g;
883
                $a{'forenames'} = [map {my $t=$_;$t=~s/$re_clean//g;$t} split ' ', $2];
884
                $a{'forenames'} = [ map { my $t = $_; $t =~ s/$re_clean//g; $t } split ' ', $2 ];
884
                push(@authors, \%a);
885
                push( @authors, \%a );
885
            }
886
            }
886
        }
887
        }
887
    }
888
    }
888
889
889
    my %publication;
890
    my %publication;
890
    if ( $marcflavour eq "UNIMARC" ) {
891
    if ( $marcflavour eq "UNIMARC" ) {
891
            %publication = (
892
        %publication = (
892
                title     => $record->subfield("200", "a") || "",
893
            title     => $record->subfield( "200", "a" ) || "",
893
                place     => $record->subfield("210", "a") || "",
894
            place     => $record->subfield( "210", "a" ) || "",
894
                publisher => $record->subfield("210", "c") || "",
895
            publisher => $record->subfield( "210", "c" ) || "",
895
                date      => $record->subfield("210", "d") || $record->subfield("210", "h") || ""
896
            date      => $record->subfield( "210", "d" ) || $record->subfield( "210", "h" ) || ""
896
            );
897
        );
897
    } else {
898
    } else {
898
            %publication = (
899
        %publication = (
899
                title     => $record->subfield("245", "a") || "",
900
            title     => $record->subfield( "245", "a" ) || "",
900
                place     => $record->subfield("264", "a") || $record->subfield("260", "a") || "",
901
            place     => $record->subfield( "264", "a" ) || $record->subfield( "260", "a" ) || "",
901
                publisher => $record->subfield("264", "b") || $record->subfield("260", "b") || "",
902
            publisher => $record->subfield( "264", "b" ) || $record->subfield( "260", "b" ) || "",
902
                date      => $record->subfield("264", "c") || $record->subfield("260", "c") || $record->subfield("260", "g") || ""
903
            date      => $record->subfield( "264", "c" )
903
            );
904
                || $record->subfield( "260", "c" )
905
                || $record->subfield( "260", "g" )
906
                || ""
907
        );
904
    }
908
    }
905
909
906
    $publication{$_} =~ s/$re_clean//g for keys %publication;
910
    $publication{$_} =~ s/$re_clean//g for keys %publication;
907
    $publication{'date'} =~ s/[\D-]//g;
911
    $publication{'date'} =~ s/[\D-]//g;
908
912
909
    my $i = $#authors;
913
    my $i       = $#authors;
910
    my $last = 0;
914
    my $last    = 0;
911
    my $seclast = 0;
915
    my $seclast = 0;
912
    for my $author (@authors) {
916
    for my $author (@authors) {
913
        $cites{'Harvard'} .= $author->{'surname'} . ' ';
917
        $cites{'Harvard'} .= $author->{'surname'} . ' ';
914
        $cites{'Harvard'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
918
        $cites{'Harvard'} .= substr( $_, 0, 1 ) . '. ' for @{ $author->{'forenames'} };
915
        $cites{'Harvard'} =~ s/\s+$//;
919
        $cites{'Harvard'} =~ s/\s+$//;
916
        $cites{'Harvard'} .= $last ? '' : ($seclast ? ' and ' : ', ');
920
        $cites{'Harvard'} .= $last ? '' : ( $seclast ? ' and ' : ', ' );
917
        $cites{'Chicago'} .= $author->{'surname'} . ' ';
921
        $cites{'Chicago'} .= $author->{'surname'} . ' ';
918
        $cites{'Chicago'} .= $_ . ' ' for @{$author->{'forenames'}};
922
        $cites{'Chicago'} .= $_ . ' ' for @{ $author->{'forenames'} };
919
        $cites{'Chicago'} =~ s/\s+$//;
923
        $cites{'Chicago'} =~ s/\s+$//;
920
        $cites{'Chicago'} .= $last ? '' : ($seclast ? ' and ' : ', ');
924
        $cites{'Chicago'} .= $last ? '' : ( $seclast ? ' and ' : ', ' );
921
        $cites{'MLA'} .= $author->{'surname'} . ' ';
925
        $cites{'MLA'}     .= $author->{'surname'} . ' ';
922
        $cites{'MLA'} .= $_ . ' ' for @{$author->{'forenames'}};
926
        $cites{'MLA'}     .= $_ . ' ' for @{ $author->{'forenames'} };
923
        $cites{'MLA'} =~ s/\s+$//;
927
        $cites{'MLA'} =~ s/\s+$//;
924
        $cites{'MLA'} .= $last ? '' : ($seclast ? ' and ' : ', ');
928
        $cites{'MLA'} .= $last ? '' : ( $seclast ? ' and ' : ', ' );
925
        $cites{'APA'} .= $author->{'surname'} . ' ';
929
        $cites{'APA'} .= $author->{'surname'} . ' ';
926
        $cites{'APA'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
930
        $cites{'APA'} .= substr( $_, 0, 1 ) . '. ' for @{ $author->{'forenames'} };
927
        $cites{'APA'} =~ s/\s+$//;
931
        $cites{'APA'} =~ s/\s+$//;
928
        $cites{'APA'} .= $last ? '' : ($seclast ? ' & ' : ', ');
932
        $cites{'APA'} .= $last ? '' : ( $seclast ? ' & ' : ', ' );
929
        $seclast = $#authors > 1 && $i-- == 2;
933
        $seclast = $#authors > 1 && $i-- == 2;
930
        $last = $i == 0;
934
        $last    = $i == 0;
931
    }
935
    }
932
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
936
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
933
937
934
    if ( $publication{date} ) {
938
    if ( $publication{date} ) {
935
        $cites{'Harvard'} .= ' (' . $publication{'date'} . '). ';
939
        $cites{'Harvard'} .= ' (' . $publication{'date'} . '). ';
936
        $cites{'Chicago'} .= ' ' . $publication{'date'}  . '. ';
940
        $cites{'Chicago'} .= ' ' . $publication{'date'} . '. ';
937
        $cites{'MLA'}     .= ' ' . $publication{'title'} . '. ';
941
        $cites{'MLA'}     .= ' ' . $publication{'title'} . '. ';
938
        $cites{'APA'}     .= ' (' . $publication{'date'} . '). ';
942
        $cites{'APA'}     .= ' (' . $publication{'date'} . '). ';
939
    }
943
    }
Lines 943-955 sub marc2cites { Link Here
943
    $cites{'APA'}     .= $publication{'title'} . '. ';
947
    $cites{'APA'}     .= $publication{'title'} . '. ';
944
    $cites{'Harvard'} .= $publication{'place'} . ': ';
948
    $cites{'Harvard'} .= $publication{'place'} . ': ';
945
    $cites{'Chicago'} .= $publication{'place'} . ': ';
949
    $cites{'Chicago'} .= $publication{'place'} . ': ';
946
    $cites{'MLA'}     .= $publication{'publisher'}  . '. ';
950
    $cites{'MLA'}     .= $publication{'publisher'} . '. ';
947
    $cites{'APA'}     .= $publication{'place'} . ': ';
951
    $cites{'APA'}     .= $publication{'place'} . ': ';
948
    $cites{'Harvard'} .= $publication{'publisher'};
952
    $cites{'Harvard'} .= $publication{'publisher'};
949
    $cites{'Chicago'} .= $publication{'publisher'};
953
    $cites{'Chicago'} .= $publication{'publisher'};
950
    $cites{'MLA'}     .= $publication{'date'};
954
    $cites{'MLA'}     .= $publication{'date'};
951
    $cites{'APA'}     .= $publication{'publisher'};
955
    $cites{'APA'}     .= $publication{'publisher'};
952
    $cites{$_} =~ s/  +/ / for keys %cites;
956
    $cites{$_} =~ s/  +/ /        for keys %cites;
953
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
957
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
954
958
955
    return \%cites;
959
    return \%cites;
956
- 

Return to bug 14670