From b769763073b831c0eecd2750351c340d93a38bcc Mon Sep 17 00:00:00 2001 From: jeremy breuillard Date: Mon, 7 Feb 2022 12:00:00 +0100 Subject: [PATCH] Bug 21330: Add xslt for authority normal view in OPAC This patch provides a xslt stylesheet on authority normal view in OPAC. Have a look on opac-authoritiesdetail.pl Test plan: 1)You need the file 'UNIMARCauthResults.xsl' -> get it in the patch from Bug 11083 2)For testing make sure to have at least one or more authorities defined 3)OPAC: Home > Authority search(Submit) > Authority search results 4)Click details on a result and notice the view 5)Apply patch 6)INTRA: Home > Administration > System preferences ->find "AuthorityXSLTOpacDetailsDisplay" 7)Write the path where your file is, ex: '/home/koha/src/UNIMARCauthResults.xsl' 8)Save changes 9)Repeat 3) and 4) and notice the display This is a similar bug: Bug 30036 --- .gitignore | 2 +- ...spref-AuthorityXSLTOpacDetailsDisplay.perl | 9 ++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/staff_interface.pref | 4 + .../bootstrap/en/modules/opac-auth-detail.tt | 96 ++----------------- opac/opac-authoritiesdetail.pl | 29 +++++- 6 files changed, 45 insertions(+), 96 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/add-syspref-AuthorityXSLTOpacDetailsDisplay.perl diff --git a/.gitignore b/.gitignore index c70d94a1dd..5c9d3a90c0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ /pm_to_blib node_modules/ koha-tmpl/opac-tmpl/bootstrap/css/maps/ -koha-tmpl/intranet-tmpl/prog/css/maps/ +koha-tmpl/intranet-tmpl/prog/css/maps/ \ No newline at end of file diff --git a/installer/data/mysql/atomicupdate/add-syspref-AuthorityXSLTOpacDetailsDisplay.perl b/installer/data/mysql/atomicupdate/add-syspref-AuthorityXSLTOpacDetailsDisplay.perl new file mode 100644 index 0000000000..cf56c1877d --- /dev/null +++ b/installer/data/mysql/atomicupdate/add-syspref-AuthorityXSLTOpacDetailsDisplay.perl @@ -0,0 +1,9 @@ +$DBversion = 'XXX'; +if (CheckVersion($DBversion)) { + $dbh->do(q{ + INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) + VALUES ('AuthorityXSLTOpacDetailsDisplay','','','Enable XSL stylesheet control over authority results page display on intranet','Free') + }); + + NewVersion($DBversion, '11083', 'Add syspref AuthorityXSLTOpacDetailsDisplay'); +} \ No newline at end of file diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index dd83a00fd8..01cbd8f8e8 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -69,6 +69,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AuthorityMergeLimit','50',NULL,'Maximum number of biblio records updated immediately when an authority record has been modified.','integer'), ('AuthorityMergeMode','loose','loose|strict','Authority merge mode','Choice'), ('AuthoritySeparator','--','10','Used to separate a list of authorities in a display. Usually --','free'), +('AuthorityXSLTOpacDetailsDisplay','','','Enable XSL stylesheet control over authority details page display on opac','Free'), ('AuthSuccessLog','0',NULL,'If enabled, log successful authentications','YesNo'), ('autoBarcode','OFF','incremental|annual|hbyymmincr|EAN13|OFF','Used to autogenerate a barcode: incremental will be of the form 1, 2, 3; annual of the form 2007-0001, 2007-0002; hbyymmincr of the form HB08010001 where HB=Home Branch','Choice'), ('AutoCreateAuthorities','0',NULL,'Automatically create authorities that do not exist when cataloging records.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref index 10c41c581d..4e63e68439 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_interface.pref @@ -1,6 +1,10 @@ Staff interface: Appearance: - + - 'Display authority details in the opac interface using XSLT stylesheet at: ' + - pref: AuthorityXSLTOpacDetailsDisplay + class: file + - '
Options:{langcode} will be replaced with current interface language and {authtypecode} will be replaced by the authority type code' - "Display language selector on " - pref: StaffLangSelectorMode choices: diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt index f0d9fbcc2d..9629aaf05f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt @@ -50,17 +50,12 @@ - [% IF ( displayhierarchy ) %] -
- [% PROCESS showhierarchy trees = loophierarchies %] -
- [% END %] -

[% summary.mainentry | html %][% IF authtypetext %] ([% authtypetext | html %])[% END %]

[% IF count %]Number of records used in: [% count | html %][% ELSE %]This authority is not used in any records.[% END %]
+
[% FOREACH authorize IN summary.authorized %] @@ -72,91 +67,12 @@ [% PROCESS otherscript headings=summary.otherscript wantcategory='preferred' %]
- [% IF summary.seefrom.size %] -
-
Used for/see from:
- -
- [% END %] - - [% IF summary.seealso.size %] -
-
See also:
- -
- [% END %] - - [% IF marcflavour == 'UNIMARC' && summary.otherscript %] -
-
Other forms:
- -
+ [% IF authresult.html %] + [% authresult.html | $raw %] + [% ELSE %] + [% PROCESS authresult summary=authresult.summary authid=authresult.authid %] [% END %] - - [% IF ( MARCURLS ) %] -
- Online resources: - -
- [% END # / IF MARCURLS %] - -
- -
-
- [% FOREACH note IN summary.notes %] -

[% note.note | html %]

- [% END %] -
-
-
+ diff --git a/opac/opac-authoritiesdetail.pl b/opac/opac-authoritiesdetail.pl index ed0a1c7014..ad12e90f2a 100755 --- a/opac/opac-authoritiesdetail.pl +++ b/opac/opac-authoritiesdetail.pl @@ -69,8 +69,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $authid = $query->param('authid'); $authid = int($authid); -my $record = GetAuthority( $authid ); -if ( ! $record ) { +my $authresult = GetAuthority( $authid ); +if ( ! $authresult ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early exit; } @@ -86,7 +86,25 @@ if ($display_hierarchy){ my $count = $authority ? $authority->get_usage_count : 0; my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); -my $marcurlsarray = GetMarcUrls( $record, $marcflavour ); +my $marcurlsarray = GetMarcUrls( $authresult, $marcflavour ); + +my $AuthorityXSLTOpacDetailsDisplay = C4::Context->preference('AuthorityXSLTOpacDetailsDisplay'); + if ($authresult && $AuthorityXSLTOpacDetailsDisplay) { + my $lang = C4::Languages::getlanguage(); + + my $xsl = $AuthorityXSLTOpacDetailsDisplay; + + $xsl =~ s/\{langcode\}/$lang/g; + $xsl =~ s/\{authtypecode\}/$authtypecode/g; + my $xslt_engine = Koha::XSLT::Base->new; + my $output = $xslt_engine->transform({ xml => $authority->marcxml, file => $xsl }); + if ($xslt_engine->err) { + warn "XSL transformation failed ($xsl): " . $xslt_engine->err; + next; + } + $authresult->{html} = $output; + + } $template->param( authority_types => $authority_types, @@ -94,6 +112,7 @@ $template->param( authid => $authid, count => $count, MARCURLS => $marcurlsarray, + authresult => $authresult, ); # find the marc field/subfield used in biblio by this authority @@ -114,7 +133,7 @@ if ($show_marc) { my @loop_data = (); # loop through each tag - my @fields = $record->fields(); + my @fields = $authresult->fields(); foreach my $field (@fields) { my @subfields_data; @@ -166,7 +185,7 @@ if ($show_marc) { } $template->param( "Tab0XX" => \@loop_data ); } else { - my $summary = BuildSummary($record, $authid, $authtypecode); + my $summary = BuildSummary($authresult, $authid, $authtypecode); $template->{VARS}->{'summary'} = $summary; } -- 2.17.1