Bugzilla – Attachment 43919 Details for
Bug 14670
Add 'cite' option to detail page in OPAC
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14670: Add Cite-option to detail page in OPAC
Bug-14670-Add-Cite-option-to-detail-page-in-OPAC.patch (text/plain), 8.99 KB, created by
Katrin Fischer
on 2015-10-24 12:42:32 UTC
(
hide
)
Description:
Bug 14670: Add Cite-option to detail page in OPAC
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2015-10-24 12:42:32 UTC
Size:
8.99 KB
patch
obsolete
>From eb8dbac017243d951df40172963b483cde5d292e Mon Sep 17 00:00:00 2001 >From: Martin Stenberg <martin@xinxidi.net> >Date: Wed, 30 Sep 2015 14:55:15 +0200 >Subject: [PATCH] Bug 14670: Add Cite-option to detail page in OPAC > >Adds a "cite" option in the tools menu in OPAC detail page for easy citations. > >Test plan: >1. Apply this patch >2. Got to OPAC detail page >3. In the tools menu to the right, click the new "Cite" link >4. A modal should appear with four different citation styles (APA, Chicago, > Harvard, MLA) > >Sponsored-by: Regionbibliotek Halland / County library of Halland > >Signed-off-by: Nicole Engard <nengard@bywatersolutions.com> >--- > C4/Record.pm | 108 +++++++++++++++++++++ > .../bootstrap/en/includes/opac-detail-sidebar.inc | 16 +++ > opac/opac-ISBDdetail.pl | 4 + > opac/opac-MARCdetail.pl | 4 + > opac/opac-detail.pl | 4 + > 5 files changed, 136 insertions(+) > >diff --git a/C4/Record.pm b/C4/Record.pm >index f46651b..2008db6 100644 >--- a/C4/Record.pm >+++ b/C4/Record.pm >@@ -55,6 +55,7 @@ $VERSION = 3.07.00.049; > &marc2modsxml > &marc2madsxml > &marc2bibtex >+ &marc2cites > &marc2csv > &changeEncoding > ); >@@ -811,6 +812,113 @@ sub marc2bibtex { > return $tex; > } > >+=head2 marc2cites - Convert from MARC21 and UNIMARC to citations >+ >+ my $cites = marc2cites($record); >+ >+Returns hashref of citation from MARC data, suitable to pass to templates. >+Hash keys store citation system names, hash values citation string. >+ >+C<$record> - a MARC::Record object >+ >+=cut >+ >+sub marc2cites { >+ my $record = shift; >+ my $marcflavour = C4::Context->preference("marcflavour"); >+ my %cites = (); >+ my @authors = (); >+ my $re_clean = qr/(^[\.,:;\/\-\s]+|[\.,:;\/\-\s]+$)/; >+ >+ my @authors; >+ my @authorFields = ('100','110','111','700','710','711'); >+ @authorFields = ('700','701','702','710','711','721') if ( $marcflavour eq "UNIMARC" ); >+ >+ foreach my $ftag ( @authorFields ) { >+ foreach my $field ($record->field($ftag)) { >+ my $author = ''; >+ if ( $marcflavour eq "UNIMARC" ) { >+ $author = join ', ', >+ ( $field->subfield("a"), $field->subfield("b") ); >+ } else { >+ $author = $field->subfield("a"); >+ } >+ if($author =~ /([^,]+),?(.*)/) { >+ my %a; >+ ($a{'surname'} = $1) =~ s/$re_clean//g; >+ $a{'forenames'} = [map {s/$re_clean//g;$_} split ' ', $2]; >+ push(@authors, \%a); >+ } >+ } >+ } >+ >+ my %publication; >+ if ( $marcflavour eq "UNIMARC" ) { >+ %publication = ( >+ title => $record->subfield("200", "a") || "", >+ place => $record->subfield("210", "a") || "", >+ publisher => $record->subfield("210", "c") || "", >+ date => $record->subfield("210", "d") || $record->subfield("210", "h") || "" >+ ); >+ } else { >+ %publication = ( >+ title => $record->subfield("245", "a") || "", >+ place => $record->subfield("260", "a") || "", >+ publisher => $record->subfield("264", "b") || $record->subfield("260", "b") || "", >+ date => $record->subfield("264", "c") || $record->subfield("260", "c") || $record->subfield("260", "g") || "" >+ ); >+ } >+ >+ $publication{$_} =~ s/$re_clean//g for keys %publication; >+ $publication{'date'} =~ s/[\D-]//g; >+ >+ my $i = $#authors; >+ my $last = 0; >+ my $seclast = 0; >+ for my $author (@authors) { >+ $cites{'Harvard'} .= $author->{'surname'} . ' '; >+ $cites{'Harvard'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}}; >+ $cites{'Harvard'} =~ s/\s+$//; >+ $cites{'Harvard'} .= $last ? '' : ($seclast ? ' and ' : ', '); >+ $cites{'Chicago'} .= $author->{'surname'} . ' '; >+ $cites{'Chicago'} .= $_ . ' ' for @{$author->{'forenames'}}; >+ $cites{'Chicago'} =~ s/\s+$//; >+ $cites{'Chicago'} .= $last ? '' : ($seclast ? ' and ' : ', '); >+ $cites{'MLA'} .= $author->{'surname'} . ' '; >+ $cites{'MLA'} .= $_ . ' ' for @{$author->{'forenames'}}; >+ $cites{'MLA'} =~ s/\s+$//; >+ $cites{'MLA'} .= $last ? '' : ($seclast ? ' and ' : ', '); >+ $cites{'APA'} .= $author->{'surname'} . ' '; >+ $cites{'APA'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}}; >+ $cites{'APA'} =~ s/\s+$//; >+ $cites{'APA'} .= $last ? '' : ($seclast ? ' & ' : ', '); >+ $seclast = $#authors > 1 && $i-- == 2; >+ $last = $i == 0; >+ } >+ $cites{$_} =~ s/([^\.])$/$1./ for keys %cites; >+ >+ $cites{'Harvard'} .= ' (' . $publication{'date'} . '). '; >+ $cites{'Chicago'} .= ' ' . $publication{'date'} . '. '; >+ $cites{'MLA'} .= ' ' . $publication{'title'} . '. '; >+ $cites{'APA'} .= ' (' . $publication{'date'} . '). '; >+ $cites{'Harvard'} .= $publication{'title'} . '. '; >+ $cites{'Chicago'} .= $publication{'title'} . '. '; >+ $cites{'MLA'} .= $publication{'place'} . ': '; >+ $cites{'APA'} .= $publication{'title'} . '. '; >+ $cites{'Harvard'} .= $publication{'place'} . ': '; >+ $cites{'Chicago'} .= $publication{'place'} . ': '; >+ $cites{'MLA'} .= $publication{'publisher'} . '. '; >+ $cites{'APA'} .= $publication{'place'} . ': '; >+ $cites{'Harvard'} .= $publication{'publisher'}; >+ $cites{'Chicago'} .= $publication{'publisher'}; >+ $cites{'MLA'} .= $publication{'date'}; >+ $cites{'APA'} .= $publication{'publisher'}; >+ $cites{$_} =~ s/ +/ / for keys %cites; >+ $cites{$_} =~ s/([^\.])$/$1./ for keys %cites; >+ >+ return \%cites; >+} >+ > > =head1 INTERNAL FUNCTIONS > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc >index a4ef40e..ce688e4 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc >@@ -1,3 +1,18 @@ >+<div id="citemodal" class="modal hide" role="dialog" aria-labelledby="citeLabel" aria-hidden="true"> >+ <div class="modal-header"> >+ <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">Ã</button> >+ <h2 id="citeLabel">[% title OR 'Citation' | html %]</h2> >+ </div> >+ <div class="modal-body"> >+ [% FOREACH system IN cites.keys.sort %] >+ <h3>[% system %]</h3> >+ <p>[% cites.$system | html %]</p> >+ [% END %] >+ </div> >+ <div class="modal-footer"> >+ </div> >+</div> >+ > <ul id="action"> > [% UNLESS ( norequests ) %] > [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] >@@ -9,6 +24,7 @@ > [% END %] > [% END %] > <li><a class="print-large" href="#" onclick="window.print();">Print</a></li> >+ <li><a href="#citemodal" id="cite" data-toggle="modal">Cite</a></li> > [% IF Koha.Preference( 'virtualshelves' ) == 1 %] > [% IF ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && loggedinusername ) %] > <li><a class="addtoshelf" href="/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber=[% biblionumber %]" onclick="Dopop('opac-addbybiblionumber.pl?biblionumber=[% biblionumber %]'); return false;"> >diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl >index 7fb1073..ae7d328 100755 >--- a/opac/opac-ISBDdetail.pl >+++ b/opac/opac-ISBDdetail.pl >@@ -48,6 +48,7 @@ use C4::Output; > use CGI qw ( -utf8 ); > use MARC::Record; > use C4::Biblio; >+use C4::Record; > use C4::Items; > use C4::Reserves; > use C4::Acquisition; >@@ -205,4 +206,7 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){ > $template->param('OPACSearchForTitleIn' => $search_for_title); > } > >+# Cites >+$template->{VARS}->{'cites'} = marc2cites($record); >+ > output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl >index afac5d7..0db711d 100755 >--- a/opac/opac-MARCdetail.pl >+++ b/opac/opac-MARCdetail.pl >@@ -51,6 +51,7 @@ use C4::Output; > use CGI qw ( -utf8 ); > use MARC::Record; > use C4::Biblio; >+use C4::Record; > use C4::Items; > use C4::Reserves; > use C4::Members; >@@ -335,4 +336,7 @@ $template->param( > biblionumber => $biblionumber, > ); > >+# Cites >+$template->{VARS}->{'cites'} = marc2cites($record); >+ > output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 0fa588f..1b3b3c9 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -31,6 +31,7 @@ use C4::Koha; > use C4::Serials; #uses getsubscriptionfrom biblionumber > use C4::Output; > use C4::Biblio; >+use C4::Record; > use C4::Items; > use C4::Circulation; > use C4::Tags qw(get_tags); >@@ -1152,4 +1153,7 @@ $template->param( > 'OpacLocationBranchToDisplayShelving' => C4::Context->preference('OpacLocationBranchToDisplayShelving'), > ); > >+# Cites >+$template->{VARS}->{'cites'} = marc2cites($record); >+ > output_html_with_http_headers $query, $cookie, $template->output; >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14670
:
41441
|
42971
|
43508
|
43770
|
43771
|
43828
|
43829
|
43919
|
43920
|
43921
|
43922
|
43923
|
43924
|
75679
|
75680
|
75681
|
75682
|
75683
|
161600
|
161601
|
161602
|
161603
|
161604
|
161605
|
161606
|
161607
|
166474
|
167528
|
167529
|
167530
|
167531
|
167532
|
167533
|
167534
|
167535
|
173515
|
173516
|
173517
|
173518
|
173519
|
173520
|
173521
|
173522
|
173523
|
173524
|
174453