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

(-)a/C4/Record.pm (+108 lines)
Lines 57-62 use vars qw(@ISA @EXPORT); Link Here
57
  &marc2modsxml
57
  &marc2modsxml
58
  &marc2madsxml
58
  &marc2madsxml
59
  &marc2bibtex
59
  &marc2bibtex
60
  &marc2cites
60
  &marc2csv
61
  &marc2csv
61
  &changeEncoding
62
  &changeEncoding
62
);
63
);
Lines 859-864 sub marc2bibtex { Link Here
859
    return $tex;
860
    return $tex;
860
}
861
}
861
862
863
=head2 marc2cites - Convert from MARC21 and UNIMARC to citations
864
865
  my $cites = marc2cites($record);
866
867
Returns hashref of citation from MARC data, suitable to pass to templates.
868
Hash keys store citation system names, hash values citation string.
869
870
C<$record> - a MARC::Record object
871
872
=cut
873
874
sub marc2cites {
875
    my $record = shift;
876
    my $marcflavour = C4::Context->preference("marcflavour");
877
    my %cites = ();
878
    my @authors = ();
879
    my $re_clean = qr/(^[\.,:;\/\-\s]+|[\.,:;\/\-\s]+$)/;
880
881
    my @authors;
882
    my @authorFields = ('100','110','111','700','710','711');
883
    @authorFields = ('700','701','702','710','711','721') if ( $marcflavour eq "UNIMARC" );
884
885
    foreach my $ftag ( @authorFields ) {
886
        foreach my $field ($record->field($ftag)) {
887
            my $author = '';
888
            if ( $marcflavour eq "UNIMARC" ) {
889
                $author = join ', ',
890
                ( $field->subfield("a"), $field->subfield("b") );
891
            } else {
892
                $author = $field->subfield("a");
893
            }
894
            if($author =~ /([^,]+),?(.*)/) {
895
                my %a;
896
                ($a{'surname'} = $1) =~ s/$re_clean//g;
897
                $a{'forenames'} = [map {s/$re_clean//g;$_} split ' ', $2];
898
                push(@authors, \%a);
899
            }
900
        }
901
    }
902
903
    my %publication;
904
    if ( $marcflavour eq "UNIMARC" ) {
905
            %publication = (
906
                title     => $record->subfield("200", "a") || "",
907
                place     => $record->subfield("210", "a") || "",
908
                publisher => $record->subfield("210", "c") || "",
909
                date      => $record->subfield("210", "d") || $record->subfield("210", "h") || ""
910
            );
911
    } else {
912
            %publication = (
913
                title     => $record->subfield("245", "a") || "",
914
                place     => $record->subfield("260", "a") || "",
915
                publisher => $record->subfield("264", "b") || $record->subfield("260", "b") || "",
916
                date      => $record->subfield("264", "c") || $record->subfield("260", "c") || $record->subfield("260", "g") || ""
917
            );
918
    }
919
920
    $publication{$_} =~ s/$re_clean//g for keys %publication;
921
    $publication{'date'} =~ s/[\D-]//g;
922
923
    my $i = $#authors;
924
    my $last = 0;
925
    my $seclast = 0;
926
    for my $author (@authors) {
927
        $cites{'Harvard'} .= $author->{'surname'} . ' ';
928
        $cites{'Harvard'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
929
        $cites{'Harvard'} =~ s/\s+$//;
930
        $cites{'Harvard'} .= $last ? '' : ($seclast ? ' and ' : ', ');
931
        $cites{'Chicago'} .= $author->{'surname'} . ' ';
932
        $cites{'Chicago'} .= $_ . ' ' for @{$author->{'forenames'}};
933
        $cites{'Chicago'} =~ s/\s+$//;
934
        $cites{'Chicago'} .= $last ? '' : ($seclast ? ' and ' : ', ');
935
        $cites{'MLA'} .= $author->{'surname'} . ' ';
936
        $cites{'MLA'} .= $_ . ' ' for @{$author->{'forenames'}};
937
        $cites{'MLA'} =~ s/\s+$//;
938
        $cites{'MLA'} .= $last ? '' : ($seclast ? ' and ' : ', ');
939
        $cites{'APA'} .= $author->{'surname'} . ' ';
940
        $cites{'APA'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}};
941
        $cites{'APA'} =~ s/\s+$//;
942
        $cites{'APA'} .= $last ? '' : ($seclast ? ' & ' : ', ');
943
        $seclast = $#authors > 1 && $i-- == 2;
944
        $last = $i == 0;
945
    }
946
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
947
948
    $cites{'Harvard'} .= ' (' . $publication{'date'} . '). ';
949
    $cites{'Chicago'} .= ' ' . $publication{'date'}  . '. ';
950
    $cites{'MLA'}     .= ' ' . $publication{'title'} . '. ';
951
    $cites{'APA'}     .= ' (' . $publication{'date'} . '). ';
952
    $cites{'Harvard'} .= $publication{'title'} . '. ';
953
    $cites{'Chicago'} .= $publication{'title'} . '. ';
954
    $cites{'MLA'}     .= $publication{'place'} . ': ';
955
    $cites{'APA'}     .= $publication{'title'} . '. ';
956
    $cites{'Harvard'} .= $publication{'place'} . ': ';
957
    $cites{'Chicago'} .= $publication{'place'} . ': ';
958
    $cites{'MLA'}     .= $publication{'publisher'}  . '. ';
959
    $cites{'APA'}     .= $publication{'place'} . ': ';
960
    $cites{'Harvard'} .= $publication{'publisher'};
961
    $cites{'Chicago'} .= $publication{'publisher'};
962
    $cites{'MLA'}     .= $publication{'date'};
963
    $cites{'APA'}     .= $publication{'publisher'};
964
    $cites{$_} =~ s/  +/ / for keys %cites;
965
    $cites{$_} =~ s/([^\.])$/$1./ for keys %cites;
966
967
    return \%cites;
968
}
969
862
970
863
=head1 INTERNAL FUNCTIONS
971
=head1 INTERNAL FUNCTIONS
864
972
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc (+17 lines)
Lines 1-4 Link Here
1
[% USE Biblio %]
1
[% USE Biblio %]
2
3
<div id="citemodal" class="modal hide" role="dialog" aria-labelledby="citeLabel" aria-hidden="true">
4
    <div class="modal-header">
5
        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
6
        <h2 id="citeLabel">[% title OR 'Citation' | html %]</h2>
7
    </div>
8
    <div class="modal-body">
9
        [% FOREACH system IN cites.keys.sort %]
10
        <h3>[% system %]</h3>
11
        <p>[% cites.$system | html %]</p>
12
        [% END %]
13
    </div>
14
    <div class="modal-footer">
15
    </div>
16
</div>
17
2
<ul id="action">
18
<ul id="action">
3
    [% UNLESS ( norequests ) %]
19
    [% UNLESS ( norequests ) %]
4
        [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
20
        [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
Lines 11-16 Link Here
11
    [% END %]
27
    [% END %]
12
28
13
    <li><a class="print-large" href="#">Print</a></li>
29
    <li><a class="print-large" href="#">Print</a></li>
30
    <li><a href="#citemodal" id="cite" data-toggle="modal">Cite</a></li>
14
31
15
    [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
32
    [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]
16
        [% IF Koha.Preference('ArticleRequests') %]
33
        [% IF Koha.Preference('ArticleRequests') %]
(-)a/opac/opac-ISBDdetail.pl (+4 lines)
Lines 47-52 use C4::Output; Link Here
47
use CGI qw ( -utf8 );
47
use CGI qw ( -utf8 );
48
use MARC::Record;
48
use MARC::Record;
49
use C4::Biblio;
49
use C4::Biblio;
50
use C4::Record;
50
use C4::Items;
51
use C4::Items;
51
use C4::Reserves;
52
use C4::Reserves;
52
use C4::Acquisition;
53
use C4::Acquisition;
Lines 217-220 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ Link Here
217
    $template->param('OPACSearchForTitleIn' => $search_for_title);
218
    $template->param('OPACSearchForTitleIn' => $search_for_title);
218
}
219
}
219
220
221
# Cites
222
$template->{VARS}->{'cites'} = marc2cites($record);
223
220
output_html_with_http_headers $query, $cookie, $template->output;
224
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/opac/opac-MARCdetail.pl (+4 lines)
Lines 51-56 use C4::Output; Link Here
51
use CGI qw ( -utf8 );
51
use CGI qw ( -utf8 );
52
use MARC::Record;
52
use MARC::Record;
53
use C4::Biblio;
53
use C4::Biblio;
54
use C4::Record;
54
use C4::Items;
55
use C4::Items;
55
use C4::Reserves;
56
use C4::Reserves;
56
use C4::Members;
57
use C4::Members;
Lines 356-359 $template->param( Link Here
356
    biblio              => $biblio,
357
    biblio              => $biblio,
357
);
358
);
358
359
360
# Cites
361
$template->{VARS}->{'cites'} = marc2cites($record);
362
359
output_html_with_http_headers $query, $cookie, $template->output;
363
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/opac/opac-detail.pl (-1 / +4 lines)
Lines 29-34 use C4::Koha; Link Here
29
use C4::Serials;    #uses getsubscriptionfrom biblionumber
29
use C4::Serials;    #uses getsubscriptionfrom biblionumber
30
use C4::Output;
30
use C4::Output;
31
use C4::Biblio;
31
use C4::Biblio;
32
use C4::Record;
32
use C4::Items;
33
use C4::Items;
33
use C4::Circulation;
34
use C4::Circulation;
34
use C4::Tags qw(get_tags);
35
use C4::Tags qw(get_tags);
Lines 1197-1200 $template->param( Link Here
1197
    'OpacLocationBranchToDisplay' => C4::Context->preference('OpacLocationBranchToDisplay'),
1198
    'OpacLocationBranchToDisplay' => C4::Context->preference('OpacLocationBranchToDisplay'),
1198
);
1199
);
1199
1200
1201
# Cites
1202
$template->{VARS}->{'cites'} = marc2cites($record);
1203
1200
output_html_with_http_headers $query, $cookie, $template->output;
1204
output_html_with_http_headers $query, $cookie, $template->output;
1201
- 

Return to bug 14670