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 855-860 sub marc2bibtex { Link Here
855
    return $tex;
856
    return $tex;
856
}
857
}
857
858
859
=head2 marc2cites - Convert from MARC21 and UNIMARC to citations
860
861
  my $cites = marc2cites($record);
862
863
Returns hashref of citation from MARC data, suitable to pass to templates.
864
Hash keys store citation system names, hash values citation string.
865
866
C<$record> - a MARC::Record object
867
868
=cut
869
870
sub marc2cites {
871
    my $record = shift;
872
    my $marcflavour = C4::Context->preference("marcflavour");
873
    my %cites = ();
874
    my @authors = ();
875
    my $re_clean = qr/(^[\.,:;\/\-\s]+|[\.,:;\/\-\s]+$)/;
876
877
    my @authors;
878
    my @authorFields = ('100','110','111','700','710','711');
879
    @authorFields = ('700','701','702','710','711','721') if ( $marcflavour eq "UNIMARC" );
880
881
    foreach my $ftag ( @authorFields ) {
882
        foreach my $field ($record->field($ftag)) {
883
            my $author = '';
884
            if ( $marcflavour eq "UNIMARC" ) {
885
                $author = join ', ',
886
                ( $field->subfield("a"), $field->subfield("b") );
887
            } else {
888
                $author = $field->subfield("a");
889
            }
890
            if($author =~ /([^,]+),?(.*)/) {
891
                my %a;
892
                ($a{'surname'} = $1) =~ s/$re_clean//g;
893
                $a{'forenames'} = [map {s/$re_clean//g;$_} split ' ', $2];
894
                push(@authors, \%a);
895
            }
896
        }
897
    }
898
899
    my %publication;
900
    if ( $marcflavour eq "UNIMARC" ) {
901
            %publication = (
902
                title     => $record->subfield("200", "a") || "",
903
                place     => $record->subfield("210", "a") || "",
904
                publisher => $record->subfield("210", "c") || "",
905
                date      => $record->subfield("210", "d") || $record->subfield("210", "h") || ""
906
            );
907
    } else {
908
            %publication = (
909
                title     => $record->subfield("245", "a") || "",
910
                place     => $record->subfield("260", "a") || "",
911
                publisher => $record->subfield("264", "b") || $record->subfield("260", "b") || "",
912
                date      => $record->subfield("264", "c") || $record->subfield("260", "c") || $record->subfield("260", "g") || ""
913
            );
914
    }
915
916
    $publication{$_} =~ s/$re_clean//g for keys %publication;
917
    $publication{'date'} =~ s/[\D-]//g;
918
919
    my $i = $#authors;
920
    my $last = 0;
921
    my $seclast = 0;
922
    for my $author (@authors) {
923
        $cites{'Harvard'} .= $author->{'surname'} . ' ';
924
        $cites{'Harvard'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
925
        $cites{'Harvard'} =~ s/\s+$//;
926
        $cites{'Harvard'} .= $last ? '' : ($seclast ? ' and ' : ', ');
927
        $cites{'Chicago'} .= $author->{'surname'} . ' ';
928
        $cites{'Chicago'} .= $_ . ' ' for @{$author->{'forenames'}};
929
        $cites{'Chicago'} =~ s/\s+$//;
930
        $cites{'Chicago'} .= $last ? '' : ($seclast ? ' and ' : ', ');
931
        $cites{'MLA'} .= $author->{'surname'} . ' ';
932
        $cites{'MLA'} .= $_ . ' ' for @{$author->{'forenames'}};
933
        $cites{'MLA'} =~ s/\s+$//;
934
        $cites{'MLA'} .= $last ? '' : ($seclast ? ' and ' : ', ');
935
        $cites{'APA'} .= $author->{'surname'} . ' ';
936
        $cites{'APA'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
937
        $cites{'APA'} =~ s/\s+$//;
938
        $cites{'APA'} .= $last ? '' : ($seclast ? ' & ' : ', ');
939
        $seclast = $#authors > 1 && $i-- == 2;
940
        $last = $i == 0;
941
    }
942
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
943
944
    $cites{'Harvard'} .= ' (' . $publication{'date'} . '). ';
945
    $cites{'Chicago'} .= ' ' . $publication{'date'}  . '. ';
946
    $cites{'MLA'}     .= ' ' . $publication{'title'} . '. ';
947
    $cites{'APA'}     .= ' (' . $publication{'date'} . '). ';
948
    $cites{'Harvard'} .= $publication{'title'} . '. ';
949
    $cites{'Chicago'} .= $publication{'title'} . '. ';
950
    $cites{'MLA'}     .= $publication{'place'} . ': ';
951
    $cites{'APA'}     .= $publication{'title'} . '. ';
952
    $cites{'Harvard'} .= $publication{'place'} . ': ';
953
    $cites{'Chicago'} .= $publication{'place'} . ': ';
954
    $cites{'MLA'}     .= $publication{'publisher'}  . '. ';
955
    $cites{'APA'}     .= $publication{'place'} . ': ';
956
    $cites{'Harvard'} .= $publication{'publisher'};
957
    $cites{'Chicago'} .= $publication{'publisher'};
958
    $cites{'MLA'}     .= $publication{'date'};
959
    $cites{'APA'}     .= $publication{'publisher'};
960
    $cites{$_} =~ s/  +/ / for keys %cites;
961
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
962
963
    return \%cites;
964
}
965
858
966
859
=head1 INTERNAL FUNCTIONS
967
=head1 INTERNAL FUNCTIONS
860
968
(-)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
    [% UNLESS ( norequests ) %]
20
    [% UNLESS ( norequests ) %]
5
        [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
21
        [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
Lines 17-22 Link Here
17
    [% END %]
33
    [% END %]
18
34
19
    <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>
35
    <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>
36
    <li><a href="#citemodal" id="cite" data-toggle="modal">Cite</a></li>
20
37
21
    [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
38
    [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
22
        [% IF artreqpossible %]
39
        [% IF artreqpossible %]
(-)a/opac/opac-ISBDdetail.pl (+4 lines)
Lines 52-57 use C4::Biblio qw( Link Here
52
    GetMarcISSN
52
    GetMarcISSN
53
    TransformMarcToKoha
53
    TransformMarcToKoha
54
);
54
);
55
use C4::Record;
55
use C4::Reserves qw( IsAvailableForItemLevelRequest );
56
use C4::Reserves qw( IsAvailableForItemLevelRequest );
56
use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
57
use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
57
use C4::Koha qw(
58
use C4::Koha qw(
Lines 227-230 if( C4::Context->preference('ArticleRequests') ) { Link Here
227
    $template->param( artreqpossible => $artreqpossible );
228
    $template->param( artreqpossible => $artreqpossible );
228
}
229
}
229
230
231
# Cites
232
$template->{VARS}->{'cites'} = marc2cites($record);
233
230
output_html_with_http_headers $query, $cookie, $template->output;
234
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/opac/opac-MARCdetail.pl (+4 lines)
Lines 58-63 use C4::Biblio qw( Link Here
58
    GetMarcStructure
58
    GetMarcStructure
59
    TransformMarcToKoha
59
    TransformMarcToKoha
60
);
60
);
61
use C4::Record;
61
use C4::Reserves qw( IsAvailableForItemLevelRequest );
62
use C4::Reserves qw( IsAvailableForItemLevelRequest );
62
use C4::Members;
63
use C4::Members;
63
use C4::Koha qw( GetNormalizedISBN );
64
use C4::Koha qw( GetNormalizedISBN );
Lines 379-382 $template->param( Link Here
379
    norequests          => $norequests,
380
    norequests          => $norequests,
380
);
381
);
381
382
383
# Cites
384
$template->{VARS}->{'cites'} = marc2cites($record);
385
382
output_html_with_http_headers $query, $cookie, $template->output;
386
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/opac/opac-detail.pl (-1 / +4 lines)
Lines 45-50 use C4::Biblio qw( Link Here
45
    GetMarcSubjects
45
    GetMarcSubjects
46
    GetMarcUrls
46
    GetMarcUrls
47
);
47
);
48
use C4::Record;
48
use C4::Tags qw( get_tags );
49
use C4::Tags qw( get_tags );
49
use C4::XISBN qw( get_xisbns );
50
use C4::XISBN qw( get_xisbns );
50
use C4::External::Amazon qw( get_amazon_tld );
51
use C4::External::Amazon qw( get_amazon_tld );
Lines 1245-1248 if ( C4::Context->preference('OPACAuthorIdentifiers') ) { Link Here
1245
    $template->param( author_identifiers => \@author_identifiers );
1246
    $template->param( author_identifiers => \@author_identifiers );
1246
}
1247
}
1247
1248
1249
# Cites
1250
$template->{VARS}->{'cites'} = marc2cites($record);
1251
1248
output_html_with_http_headers $query, $cookie, $template->output;
1252
output_html_with_http_headers $query, $cookie, $template->output;
1249
- 

Return to bug 14670