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:
parent
56c2856e26
commit
977774f095
7 changed files with 85 additions and 57 deletions
22
C4/Search.pm
22
C4/Search.pm
|
@ -1655,10 +1655,6 @@ sub searchResults {
|
||||||
my ($bibliotag,$bibliosubf)=GetMarcFromKohaField( 'biblio.biblionumber' );
|
my ($bibliotag,$bibliosubf)=GetMarcFromKohaField( 'biblio.biblionumber' );
|
||||||
|
|
||||||
# set stuff for XSLT processing here once, not later again for every record we retrieved
|
# 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 $userenv = C4::Context->userenv;
|
||||||
my $logged_in_user
|
my $logged_in_user
|
||||||
|
@ -1955,14 +1951,28 @@ sub searchResults {
|
||||||
|
|
||||||
# XSLT processing of some stuff
|
# XSLT processing of some stuff
|
||||||
# we fetched the sysprefs already before the loop through all retrieved record!
|
# we fetched the sysprefs already before the loop through all retrieved record!
|
||||||
if (!$scan && $xslfile) {
|
if (!$scan) {
|
||||||
$record_processor->options({
|
$record_processor->options({
|
||||||
frameworkcode => $fw,
|
frameworkcode => $fw,
|
||||||
interface => $search_context->{'interface'}
|
interface => $search_context->{'interface'}
|
||||||
});
|
});
|
||||||
|
|
||||||
$record_processor->process($marcrecord);
|
$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
|
# if biblio level itypes are used and itemtype is notforloan, it can't be reserved either
|
||||||
|
|
33
C4/XSLT.pm
33
C4/XSLT.pm
|
@ -188,17 +188,17 @@ sub get_xslt_sysprefs {
|
||||||
return $sysxml;
|
return $sysxml;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub XSLTParse4Display {
|
sub get_xsl_filename {
|
||||||
my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang, $variables, $items_rs ) = @_;
|
my ( $xslsyspref ) = @_;
|
||||||
|
|
||||||
$sysxml ||= C4::Context->preference($xslsyspref);
|
my $lang = C4::Languages::getlanguage();
|
||||||
$xslfilename ||= C4::Context->preference($xslsyspref);
|
|
||||||
$lang ||= C4::Languages::getlanguage();
|
my $xslfilename = C4::Context->preference($xslsyspref) || "default";
|
||||||
|
|
||||||
if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) {
|
if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) {
|
||||||
my $htdocs;
|
|
||||||
my $theme;
|
my ( $htdocs, $theme, $xslfile );
|
||||||
my $xslfile;
|
|
||||||
if ($xslsyspref eq "XSLTDetailsDisplay") {
|
if ($xslsyspref eq "XSLTDetailsDisplay") {
|
||||||
$htdocs = C4::Context->config('intrahtdocs');
|
$htdocs = C4::Context->config('intrahtdocs');
|
||||||
$theme = C4::Context->preference("template");
|
$theme = C4::Context->preference("template");
|
||||||
|
@ -239,6 +239,22 @@ sub XSLTParse4Display {
|
||||||
$xslfilename =~ s/\{langcode\}/$lang/;
|
$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
|
# grab the XML, run it through our stylesheet, push it out to the browser
|
||||||
my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
|
my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
|
||||||
my $itemsxml;
|
my $itemsxml;
|
||||||
|
@ -271,6 +287,7 @@ sub XSLTParse4Display {
|
||||||
}
|
}
|
||||||
$varxml .= "</variables>\n";
|
$varxml .= "</variables>\n";
|
||||||
|
|
||||||
|
my $sysxml = get_xslt_sysprefs();
|
||||||
$xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml\<\/record\>/;
|
$xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml$varxml\<\/record\>/;
|
||||||
if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
|
if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
|
||||||
$xmlrecord =~ s/\&amp;/\&/g;
|
$xmlrecord =~ s/\&amp;/\&/g;
|
||||||
|
|
|
@ -124,9 +124,6 @@ my $marcflavour = C4::Context->preference("marcflavour");
|
||||||
|
|
||||||
{
|
{
|
||||||
# XSLT processing of some stuff
|
# 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(
|
my $searcher = Koha::SearchEngine::Search->new(
|
||||||
{ index => $Koha::SearchEngine::BIBLIOS_INDEX }
|
{ index => $Koha::SearchEngine::BIBLIOS_INDEX }
|
||||||
|
@ -148,11 +145,15 @@ my $marcflavour = C4::Context->preference("marcflavour");
|
||||||
|
|
||||||
$template->param(
|
$template->param(
|
||||||
XSLTDetailsDisplay => '1',
|
XSLTDetailsDisplay => '1',
|
||||||
XSLTBloc => XSLTParse4Display(
|
XSLTBloc => XSLTParse4Display(
|
||||||
$biblionumber, $record, "XSLTDetailsDisplay", 1,
|
{
|
||||||
undef, $sysxml, $xslfile, $lang,
|
biblionumber => $biblionumber,
|
||||||
$variables
|
record => $record,
|
||||||
)
|
xsl_syspref => "XSLTDetailsDisplay",
|
||||||
|
fix_amps => 1,
|
||||||
|
xslt_variables => $variables
|
||||||
|
}
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,12 +194,6 @@ my $marcflavour = C4::Context->preference("marcflavour");
|
||||||
my $ean = GetNormalizedEAN( $record, $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(
|
my $searcher = Koha::SearchEngine::Search->new(
|
||||||
{ index => $Koha::SearchEngine::BIBLIOS_INDEX }
|
{ 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 );
|
my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
|
||||||
|
|
||||||
warn "Warning from simple_search_compat: $err"
|
warn "Warning from simple_search_compat: $err"
|
||||||
if $err;
|
if $err;
|
||||||
|
|
||||||
my $variables = {
|
my $variables = {
|
||||||
anonymous_session => ($borrowernumber) ? 0 : 1,
|
anonymous_session => ($borrowernumber) ? 0 : 1,
|
||||||
show_analytics_link => $count > 0 ? 1 : 0
|
show_analytics_link => $count > 0 ? 1 : 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
my $lang = C4::Languages::getlanguage();
|
||||||
my @plugin_responses = Koha::Plugins->call(
|
my @plugin_responses = Koha::Plugins->call(
|
||||||
'opac_detail_xslt_variables',
|
'opac_detail_xslt_variables',
|
||||||
{
|
{
|
||||||
|
@ -234,9 +229,14 @@ my $ean = GetNormalizedEAN( $record, $marcflavour );
|
||||||
|
|
||||||
$template->param(
|
$template->param(
|
||||||
XSLTBloc => XSLTParse4Display(
|
XSLTBloc => XSLTParse4Display(
|
||||||
$biblionumber, $record, "OPACXSLTDetailsDisplay", 1, undef,
|
{
|
||||||
$sysxml, $xslfile, $lang, $variables
|
biblionumber => $biblionumber,
|
||||||
)
|
record => $record,
|
||||||
|
xsl_syspref => 'OPACXSLTDetailsDisplay',
|
||||||
|
fix_amps => 1,
|
||||||
|
xslt_variables => $variables
|
||||||
|
}
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -303,11 +303,6 @@ if ( $op eq 'view' ) {
|
||||||
$categorycode = $patron ? $patron->categorycode : undef;
|
$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 $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
|
||||||
|
|
||||||
my $art_req_itypes;
|
my $art_req_itypes;
|
||||||
|
@ -374,13 +369,17 @@ if ( $op eq 'view' ) {
|
||||||
anonymous_session => ($loggedinuser) ? 0 : 1
|
anonymous_session => ($loggedinuser) ? 0 : 1
|
||||||
};
|
};
|
||||||
$this_item->{XSLTBloc} = XSLTParse4Display(
|
$this_item->{XSLTBloc} = XSLTParse4Display(
|
||||||
$biblionumber, $record,
|
{
|
||||||
"OPACXSLTListsDisplay", 1,
|
biblionumber => $biblionumber,
|
||||||
undef, $sysxml,
|
record => $record,
|
||||||
$xslfile, $lang,
|
xsl_syspref => "OPACXSLTListsDisplay",
|
||||||
$variables, $items->reset
|
fix_amps => 1,
|
||||||
|
xslt_variables => $variables,
|
||||||
|
items_rs => $items->reset,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if ( grep {$_ eq $biblionumber} @cart_list) {
|
if ( grep {$_ eq $biblionumber} @cart_list) {
|
||||||
$this_item->{incart} = 1;
|
$this_item->{incart} = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,19 +285,18 @@ if ($loggedinuser) {
|
||||||
# BZ17530: 'Intelligent' guess if result can be article requested
|
# BZ17530: 'Intelligent' guess if result can be article requested
|
||||||
$tag->{artreqpossible} = ( $art_req_itypes->{ $tag->{itemtype} // q{} } || $art_req_itypes->{ '*' } ) ? 1 : q{};
|
$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 = {
|
my $variables = {
|
||||||
anonymous_session => ($loggedinuser) ? 0 : 1
|
anonymous_session => ($loggedinuser) ? 0 : 1
|
||||||
};
|
};
|
||||||
$tag->{XSLTBloc} = XSLTParse4Display(
|
$tag->{XSLTBloc} = XSLTParse4Display(
|
||||||
$tag->{biblionumber}, $record,
|
{
|
||||||
"OPACXSLTResultsDisplay", 1,
|
biblionumber => $tag->{biblionumber},
|
||||||
$hidden_items, $sysxml,
|
record => $record,
|
||||||
$xslfile, $lang,
|
xsl_filename => 'OPACXSLTResultsDisplay',
|
||||||
$variables
|
fix_amps => 1,
|
||||||
|
hidden_items => $hidden_items,
|
||||||
|
xslt_variables => $variables
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
my $date = $tag->{date_created} || '';
|
my $date = $tag->{date_created} || '';
|
||||||
|
|
|
@ -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;
|
my @items;
|
||||||
while ( my $content = $contents->next ) {
|
while ( my $content = $contents->next ) {
|
||||||
my $this_item;
|
my $this_item;
|
||||||
my $biblionumber = $content->biblionumber;
|
my $biblionumber = $content->biblionumber;
|
||||||
my $record = GetMarcBiblio({ biblionumber => $biblionumber });
|
my $record = GetMarcBiblio({ biblionumber => $biblionumber });
|
||||||
|
|
||||||
$this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "XSLTListsDisplay",
|
$this_item->{XSLTBloc} = XSLTParse4Display(
|
||||||
1, undef, $sysxml, $xslfile, $lang);
|
{
|
||||||
|
biblionumber => $biblionumber,
|
||||||
|
record => $record,
|
||||||
|
xsl_filename => "XSLTListsDisplay",
|
||||||
|
fix_amps => 1,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
my $marcflavour = C4::Context->preference("marcflavour");
|
my $marcflavour = C4::Context->preference("marcflavour");
|
||||||
my $itemtype = Koha::Biblioitems->search({ biblionumber => $content->biblionumber })->next->itemtype;
|
my $itemtype = Koha::Biblioitems->search({ biblionumber => $content->biblionumber })->next->itemtype;
|
||||||
|
|
Loading…
Reference in a new issue