Bug 12561: Change prototype of XSLTParse4Display

Use a hash for better readability and reusability.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2021-06-18 16:05:34 +02:00
parent 56c2856e26
commit 977774f095
7 changed files with 85 additions and 57 deletions

View file

@ -1655,10 +1655,6 @@ sub searchResults {
my ($bibliotag,$bibliosubf)=GetMarcFromKohaField( 'biblio.biblionumber' );
# set stuff for XSLT processing here once, not later again for every record we retrieved
my $xslsyspref = $is_opac ? 'OPACXSLTResultsDisplay' : 'XSLTResultsDisplay';
my $xslfile = C4::Context->preference( $xslsyspref ) || "default";
my $lang = C4::Languages::getlanguage();
my $sysxml = C4::XSLT::get_xslt_sysprefs();
my $userenv = C4::Context->userenv;
my $logged_in_user
@ -1955,14 +1951,28 @@ sub searchResults {
# XSLT processing of some stuff
# we fetched the sysprefs already before the loop through all retrieved record!
if (!$scan && $xslfile) {
if (!$scan) {
$record_processor->options({
frameworkcode => $fw,
interface => $search_context->{'interface'}
});
$record_processor->process($marcrecord);
$oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang, $xslt_variables);
$oldbiblio->{XSLTResultsRecord} = XSLTParse4Display(
{
biblionumber => $oldbiblio->{biblionumber},
record => $marcrecord,
xsl_syspref => (
$is_opac
? 'OPACXSLTResultsDisplay'
: 'XSLTResultsDisplay'
),
fix_amps => 1,
hidden_items => \@hiddenitems,
xslt_variables => $xslt_variables
}
);
}
# if biblio level itypes are used and itemtype is notforloan, it can't be reserved either

View file

@ -188,17 +188,17 @@ sub get_xslt_sysprefs {
return $sysxml;
}
sub XSLTParse4Display {
my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang, $variables, $items_rs ) = @_;
sub get_xsl_filename {
my ( $xslsyspref ) = @_;
$sysxml ||= C4::Context->preference($xslsyspref);
$xslfilename ||= C4::Context->preference($xslsyspref);
$lang ||= C4::Languages::getlanguage();
my $lang = C4::Languages::getlanguage();
my $xslfilename = C4::Context->preference($xslsyspref) || "default";
if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) {
my $htdocs;
my $theme;
my $xslfile;
my ( $htdocs, $theme, $xslfile );
if ($xslsyspref eq "XSLTDetailsDisplay") {
$htdocs = C4::Context->config('intrahtdocs');
$theme = C4::Context->preference("template");
@ -239,6 +239,22 @@ sub XSLTParse4Display {
$xslfilename =~ s/\{langcode\}/$lang/;
}
return $xslfilename;
}
sub XSLTParse4Display {
my ( $params ) = @_;
my $biblionumber = $params->{biblionumber};
my $orig_record = $params->{record};
my $xslsyspref = $params->{xsl_syspref};
my $fixamps = $params->{fix_amps};
my $hidden_items = $params->{hidden_items} || [];
my $variables = $params->{xslt_variables};
my $items_rs = $params->{items_rs};
my $xslfilename = get_xsl_filename( $xslsyspref);
# grab the XML, run it through our stylesheet, push it out to the browser
my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
my $itemsxml;
@ -271,6 +287,7 @@ sub XSLTParse4Display {
}
$varxml .= "</variables>\n";
my $sysxml = get_xslt_sysprefs();
$xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml\<\/record\>/;
if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
$xmlrecord =~ s/\&amp;amp;/\&amp;/g;

View file

@ -124,9 +124,6 @@ my $marcflavour = C4::Context->preference("marcflavour");
{
# XSLT processing of some stuff
my $xslfile = C4::Context->preference('XSLTDetailsDisplay') || "default";
my $lang = C4::Languages::getlanguage();
my $sysxml = C4::XSLT::get_xslt_sysprefs();
my $searcher = Koha::SearchEngine::Search->new(
{ index => $Koha::SearchEngine::BIBLIOS_INDEX }
@ -148,11 +145,15 @@ my $marcflavour = C4::Context->preference("marcflavour");
$template->param(
XSLTDetailsDisplay => '1',
XSLTBloc => XSLTParse4Display(
$biblionumber, $record, "XSLTDetailsDisplay", 1,
undef, $sysxml, $xslfile, $lang,
$variables
)
XSLTBloc => XSLTParse4Display(
{
biblionumber => $biblionumber,
record => $record,
xsl_syspref => "XSLTDetailsDisplay",
fix_amps => 1,
xslt_variables => $variables
}
),
);
}

View file

@ -194,12 +194,6 @@ my $marcflavour = C4::Context->preference("marcflavour");
my $ean = GetNormalizedEAN( $record, $marcflavour );
{
# XSLT processing of some stuff
my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay') || "default";
my $lang = C4::Languages::getlanguage();
my $sysxml = C4::XSLT::get_xslt_sysprefs();
my $searcher = Koha::SearchEngine::Search->new(
{ index => $Koha::SearchEngine::BIBLIOS_INDEX }
);
@ -212,13 +206,14 @@ my $ean = GetNormalizedEAN( $record, $marcflavour );
my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
warn "Warning from simple_search_compat: $err"
if $err;
if $err;
my $variables = {
anonymous_session => ($borrowernumber) ? 0 : 1,
show_analytics_link => $count > 0 ? 1 : 0
};
my $lang = C4::Languages::getlanguage();
my @plugin_responses = Koha::Plugins->call(
'opac_detail_xslt_variables',
{
@ -234,9 +229,14 @@ my $ean = GetNormalizedEAN( $record, $marcflavour );
$template->param(
XSLTBloc => XSLTParse4Display(
$biblionumber, $record, "OPACXSLTDetailsDisplay", 1, undef,
$sysxml, $xslfile, $lang, $variables
)
{
biblionumber => $biblionumber,
record => $record,
xsl_syspref => 'OPACXSLTDetailsDisplay',
fix_amps => 1,
xslt_variables => $variables
}
),
);
}

View file

@ -303,11 +303,6 @@ if ( $op eq 'view' ) {
$categorycode = $patron ? $patron->categorycode : undef;
}
# Lists display falls back to search results configuration
my $xslfile = C4::Context->preference('OPACXSLTListsDisplay') || "default";
my $lang = C4::Languages::getlanguage();
my $sysxml = C4::XSLT::get_xslt_sysprefs();
my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
my $art_req_itypes;
@ -374,13 +369,17 @@ if ( $op eq 'view' ) {
anonymous_session => ($loggedinuser) ? 0 : 1
};
$this_item->{XSLTBloc} = XSLTParse4Display(
$biblionumber, $record,
"OPACXSLTListsDisplay", 1,
undef, $sysxml,
$xslfile, $lang,
$variables, $items->reset
{
biblionumber => $biblionumber,
record => $record,
xsl_syspref => "OPACXSLTListsDisplay",
fix_amps => 1,
xslt_variables => $variables,
items_rs => $items->reset,
}
);
if ( grep {$_ eq $biblionumber} @cart_list) {
$this_item->{incart} = 1;
}

View file

@ -285,19 +285,18 @@ if ($loggedinuser) {
# BZ17530: 'Intelligent' guess if result can be article requested
$tag->{artreqpossible} = ( $art_req_itypes->{ $tag->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{};
my $xslfile = C4::Context->preference('OPACXSLTResultsDisplay') || "default";
my $lang = C4::Languages::getlanguage();
my $sysxml = C4::XSLT::get_xslt_sysprefs();
my $variables = {
anonymous_session => ($loggedinuser) ? 0 : 1
};
$tag->{XSLTBloc} = XSLTParse4Display(
$tag->{biblionumber}, $record,
"OPACXSLTResultsDisplay", 1,
$hidden_items, $sysxml,
$xslfile, $lang,
$variables
{
biblionumber => $tag->{biblionumber},
record => $record,
xsl_filename => 'OPACXSLTResultsDisplay',
fix_amps => 1,
hidden_items => $hidden_items,
xslt_variables => $variables
}
);
my $date = $tag->{date_created} || '';

View file

@ -258,18 +258,20 @@ if ( $op eq 'view' ) {
}
);
my $xslfile = C4::Context->preference('XSLTListsDisplay');
my $lang = C4::Languages::getlanguage();
my $sysxml = C4::XSLT::get_xslt_sysprefs();
my @items;
while ( my $content = $contents->next ) {
my $this_item;
my $biblionumber = $content->biblionumber;
my $record = GetMarcBiblio({ biblionumber => $biblionumber });
$this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "XSLTListsDisplay",
1, undef, $sysxml, $xslfile, $lang);
$this_item->{XSLTBloc} = XSLTParse4Display(
{
biblionumber => $biblionumber,
record => $record,
xsl_filename => "XSLTListsDisplay",
fix_amps => 1,
}
);
my $marcflavour = C4::Context->preference("marcflavour");
my $itemtype = Koha::Biblioitems->search({ biblionumber => $content->biblionumber })->next->itemtype;