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

(-)a/C4/Record.pm (+108 lines)
Lines 58-63 use vars qw(@ISA @EXPORT); Link Here
58
  marc2madsxml
58
  marc2madsxml
59
  marc2bibtex
59
  marc2bibtex
60
  marc2csv
60
  marc2csv
61
  marc2cites
61
  marcrecord2csv
62
  marcrecord2csv
62
  changeEncoding
63
  changeEncoding
63
);
64
);
Lines 846-851 sub marc2bibtex { Link Here
846
    return $tex;
847
    return $tex;
847
}
848
}
848
849
850
=head2 marc2cites - Convert from MARC21 and UNIMARC to citations
851
852
  my $cites = marc2cites($record);
853
854
Returns hashref of citation from MARC data, suitable to pass to templates.
855
Hash keys store citation system names, hash values citation string.
856
857
C<$record> - a MARC::Record object
858
859
=cut
860
861
sub marc2cites {
862
    my $record = shift;
863
    my $marcflavour = C4::Context->preference("marcflavour");
864
    my %cites = ();
865
    my @authors = ();
866
    my $re_clean = qr/(^[\.,:;\/\-\s]+|[\.,:;\/\-\s]+$)/;
867
868
    my @authors;
869
    my @authorFields = ('100','110','111','700','710','711');
870
    @authorFields = ('700','701','702','710','711','721') if ( $marcflavour eq "UNIMARC" );
871
872
    foreach my $ftag ( @authorFields ) {
873
        foreach my $field ($record->field($ftag)) {
874
            my $author = '';
875
            if ( $marcflavour eq "UNIMARC" ) {
876
                $author = join ', ',
877
                ( $field->subfield("a"), $field->subfield("b") );
878
            } else {
879
                $author = $field->subfield("a");
880
            }
881
            if($author =~ /([^,]+),?(.*)/) {
882
                my %a;
883
                ($a{'surname'} = $1) =~ s/$re_clean//g;
884
                $a{'forenames'} = [map {s/$re_clean//g;$_} split ' ', $2];
885
                push(@authors, \%a);
886
            }
887
        }
888
    }
889
890
    my %publication;
891
    if ( $marcflavour eq "UNIMARC" ) {
892
            %publication = (
893
                title     => $record->subfield("200", "a") || "",
894
                place     => $record->subfield("210", "a") || "",
895
                publisher => $record->subfield("210", "c") || "",
896
                date      => $record->subfield("210", "d") || $record->subfield("210", "h") || ""
897
            );
898
    } else {
899
            %publication = (
900
                title     => $record->subfield("245", "a") || "",
901
                place     => $record->subfield("260", "a") || "",
902
                publisher => $record->subfield("264", "b") || $record->subfield("260", "b") || "",
903
                date      => $record->subfield("264", "c") || $record->subfield("260", "c") || $record->subfield("260", "g") || ""
904
            );
905
    }
906
907
    $publication{$_} =~ s/$re_clean//g for keys %publication;
908
    $publication{'date'} =~ s/[\D-]//g;
909
910
    my $i = $#authors;
911
    my $last = 0;
912
    my $seclast = 0;
913
    for my $author (@authors) {
914
        $cites{'Harvard'} .= $author->{'surname'} . ' ';
915
        $cites{'Harvard'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
916
        $cites{'Harvard'} =~ s/\s+$//;
917
        $cites{'Harvard'} .= $last ? '' : ($seclast ? ' and ' : ', ');
918
        $cites{'Chicago'} .= $author->{'surname'} . ' ';
919
        $cites{'Chicago'} .= $_ . ' ' for @{$author->{'forenames'}};
920
        $cites{'Chicago'} =~ s/\s+$//;
921
        $cites{'Chicago'} .= $last ? '' : ($seclast ? ' and ' : ', ');
922
        $cites{'MLA'} .= $author->{'surname'} . ' ';
923
        $cites{'MLA'} .= $_ . ' ' for @{$author->{'forenames'}};
924
        $cites{'MLA'} =~ s/\s+$//;
925
        $cites{'MLA'} .= $last ? '' : ($seclast ? ' and ' : ', ');
926
        $cites{'APA'} .= $author->{'surname'} . ' ';
927
        $cites{'APA'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
928
        $cites{'APA'} =~ s/\s+$//;
929
        $cites{'APA'} .= $last ? '' : ($seclast ? ' & ' : ', ');
930
        $seclast = $#authors > 1 && $i-- == 2;
931
        $last = $i == 0;
932
    }
933
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
934
935
    $cites{'Harvard'} .= ' (' . $publication{'date'} . '). ';
936
    $cites{'Chicago'} .= ' ' . $publication{'date'}  . '. ';
937
    $cites{'MLA'}     .= ' ' . $publication{'title'} . '. ';
938
    $cites{'APA'}     .= ' (' . $publication{'date'} . '). ';
939
    $cites{'Harvard'} .= $publication{'title'} . '. ';
940
    $cites{'Chicago'} .= $publication{'title'} . '. ';
941
    $cites{'MLA'}     .= $publication{'place'} . ': ';
942
    $cites{'APA'}     .= $publication{'title'} . '. ';
943
    $cites{'Harvard'} .= $publication{'place'} . ': ';
944
    $cites{'Chicago'} .= $publication{'place'} . ': ';
945
    $cites{'MLA'}     .= $publication{'publisher'}  . '. ';
946
    $cites{'APA'}     .= $publication{'place'} . ': ';
947
    $cites{'Harvard'} .= $publication{'publisher'};
948
    $cites{'Chicago'} .= $publication{'publisher'};
949
    $cites{'MLA'}     .= $publication{'date'};
950
    $cites{'APA'}     .= $publication{'publisher'};
951
    $cites{$_} =~ s/  +/ / for keys %cites;
952
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
953
954
    return \%cites;
955
}
956
849
957
850
=head1 INTERNAL FUNCTIONS
958
=head1 INTERNAL FUNCTIONS
851
959
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc (+17 lines)
Lines 1-5 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Biblio %]
2
[% USE Biblio %]
3
4
<div id="citemodal" class="modal hide" role="dialog" aria-labelledby="citeLabel" aria-hidden="true">
5
    <div class="modal-header">
6
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
7
        <h2 id="citeLabel">[% title OR 'Citation' | html %]</h2>
8
    </div>
9
    <div class="modal-body">
10
        [% FOREACH system IN cites.keys.sort %]
11
        <h3>[% system %]</h3>
12
        <p>[% cites.$system | html %]</p>
13
        [% END %]
14
    </div>
15
    <div class="modal-footer">
16
    </div>
17
</div>
18
3
<ul id="action">
19
<ul id="action">
4
    [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
20
    [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
5
        [% IF Koha.Preference( 'OPACHoldRequests' ) == 1 %]
21
        [% IF Koha.Preference( 'OPACHoldRequests' ) == 1 %]
Lines 15-20 Link Here
15
    [% END %]
31
    [% END %]
16
32
17
    <li><a class="print-large btn btn-link btn-lg" href="#"><i class="fa fa-fw fa-print" aria-hidden="true"></i> Print</a></li>
33
    <li><a class="print-large btn btn-link btn-lg" href="#"><i class="fa fa-fw fa-print" aria-hidden="true"></i> Print</a></li>
34
    <li><a href="#citemodal" id="cite" data-toggle="modal">Cite</a></li>
18
35
19
    [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
36
    [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
20
        [% IF artreqpossible %]
37
        [% IF artreqpossible %]
(-)a/opac/opac-ISBDdetail.pl (+4 lines)
Lines 51-56 use C4::Biblio qw( Link Here
51
    GetMarcISSN
51
    GetMarcISSN
52
    TransformMarcToKoha
52
    TransformMarcToKoha
53
);
53
);
54
use C4::Record;
54
use C4::Reserves qw( IsAvailableForItemLevelRequest );
55
use C4::Reserves qw( IsAvailableForItemLevelRequest );
55
use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
56
use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
56
use C4::Koha qw(
57
use C4::Koha qw(
Lines 229-232 if( C4::Context->preference('ArticleRequests') ) { Link Here
229
    $template->param( artreqpossible => $artreqpossible );
230
    $template->param( artreqpossible => $artreqpossible );
230
}
231
}
231
232
233
# Cites
234
$template->{VARS}->{'cites'} = marc2cites($record);
235
232
output_html_with_http_headers $query, $cookie, $template->output;
236
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/opac/opac-MARCdetail.pl (+4 lines)
Lines 57-62 use C4::Biblio qw( Link Here
57
    GetMarcStructure
57
    GetMarcStructure
58
    TransformMarcToKoha
58
    TransformMarcToKoha
59
);
59
);
60
use C4::Record;
60
use C4::Reserves qw( IsAvailableForItemLevelRequest );
61
use C4::Reserves qw( IsAvailableForItemLevelRequest );
61
use C4::Members;
62
use C4::Members;
62
use C4::Koha qw( GetNormalizedISBN );
63
use C4::Koha qw( GetNormalizedISBN );
Lines 386-389 $template->param( Link Here
386
    borrowernumber      => $loggedinuser,
387
    borrowernumber      => $loggedinuser,
387
);
388
);
388
389
390
# Cites
391
$template->{VARS}->{'cites'} = marc2cites($record);
392
389
output_html_with_http_headers $query, $cookie, $template->output;
393
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/opac/opac-detail.pl (-1 / +4 lines)
Lines 44-49 use C4::Biblio qw( Link Here
44
    GetMarcSubjects
44
    GetMarcSubjects
45
    GetMarcUrls
45
    GetMarcUrls
46
);
46
);
47
use C4::Record;
47
use C4::Tags qw( get_tags );
48
use C4::Tags qw( get_tags );
48
use C4::XISBN qw( get_xisbns );
49
use C4::XISBN qw( get_xisbns );
49
use C4::External::Amazon qw( get_amazon_tld );
50
use C4::External::Amazon qw( get_amazon_tld );
Lines 1260-1263 if ( C4::Context->preference('OPACAuthorIdentifiersAndInformation') ) { Link Here
1260
    $template->param( author_information => \@author_information );
1261
    $template->param( author_information => \@author_information );
1261
}
1262
}
1262
1263
1264
# Cites
1265
$template->{VARS}->{'cites'} = marc2cites($record);
1266
1263
output_html_with_http_headers $query, $cookie, $template->output;
1267
output_html_with_http_headers $query, $cookie, $template->output;
1264
- 

Return to bug 14670