Bug 11175: (QA follow-up) Do not fetch twice

We were fetching components in the first call of XSLTParse4Display
(opac-detail around L220). And again (opac-detail around L660).
Same for catalogue/detail.pl.
Moving the XSLT block in both scripts and removing the code from
XSLT.pm which again makes the tests obsolete.

Not hiding the link when there are components. Might be helpful too.

Also fixing biblionumber in the XSLTParse4Display call for parts.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Marcel de Rooy 2021-10-24 12:11:02 +00:00 committed by Jonathan Druart
parent 936e86366c
commit dfce3d3c0c
3 changed files with 50 additions and 69 deletions

View file

@ -281,24 +281,6 @@ sub XSLTParse4Display {
}
}
# possibly show analytics link in Detail views
if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" ) {
$biblio //= Koha::Biblios->find( $biblionumber );
my $components = $biblio->get_marc_components();
$variables->{show_analytics_link} = ( scalar @{$components} == 0 ) ? 0 : 1;
my $showcomp = C4::Context->preference('ShowComponentRecords');
if (
$variables->{show_analytics_link}
&& ( $showcomp eq 'both'
|| ( $showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ )
|| ( $showcomp eq 'opac' && $xslsyspref =~ m/OPAC/ ) )
)
{
$variables->{show_analytics_link} = 0;
}
}
my $varxml = "<variables>\n";
while (my ($key, $value) = each %$variables) {
$varxml .= "<variable name=\"$key\">$value</variable>\n";

View file

@ -123,22 +123,6 @@ my $fw = GetFrameworkCode($biblionumber);
my $showallitems = $query->param('showallitems');
my $marcflavour = C4::Context->preference("marcflavour");
{
# XSLT processing of some stuff
$template->param(
XSLTDetailsDisplay => '1',
XSLTBloc => XSLTParse4Display(
{
biblionumber => $biblionumber,
record => $record,
xsl_syspref => "XSLTDetailsDisplay",
fix_amps => 1,
}
),
);
}
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
# Catch the exception as Koha::Biblio::Metadata->record can explode if the MARCXML is invalid
@ -213,16 +197,19 @@ foreach my $subscription (@subscriptions) {
# Get component parts details
my $showcomp = C4::Context->preference('ShowComponentRecords');
my $show_analytics;
if ( $showcomp eq 'both' || $showcomp eq 'staff' ) {
if ( my $components = $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) ) {
$show_analytics = 1; # just show link when having results
my $parts;
for my $part ( @{$components} ) {
$part = C4::Search::new_record_from_zebra( 'biblioserver', $part );
my $id = Koha::SearchEngine::Search::extract_biblionumber( $part );
push @{$parts},
XSLTParse4Display(
{
biblionumber => $biblionumber,
biblionumber => $id,
record => $part,
xsl_syspref => "XSLTResultsDisplay",
fix_amps => 1,
@ -232,8 +219,23 @@ if ( $showcomp eq 'both' || $showcomp eq 'staff' ) {
$template->param( ComponentParts => $parts );
$template->param( ComponentPartsQuery => $biblio->get_components_query );
}
} else { # check if we should show analytics anyway
$show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not
}
# XSLT processing of some stuff
my $xslt_variables = { show_analytics_link => $show_analytics };
$template->param(
XSLTDetailsDisplay => '1',
XSLTBloc => XSLTParse4Display({
biblionumber => $biblionumber,
record => $record,
xsl_syspref => "XSLTDetailsDisplay",
fix_amps => 1,
xslt_variables => $xslt_variables,
}),
);
# Get acquisition details
if ( C4::Context->preference('AcquisitionDetails') ) {
my $orders = Koha::Acquisition::Orders->search(

View file

@ -195,38 +195,6 @@ SetUTF8Flag($record);
my $marcflavour = C4::Context->preference("marcflavour");
my $ean = GetNormalizedEAN( $record, $marcflavour );
{
my $variables = {
anonymous_session => ($borrowernumber) ? 0 : 1,
};
my $lang = C4::Languages::getlanguage();
my @plugin_responses = Koha::Plugins->call(
'opac_detail_xslt_variables',
{
biblio_id => $biblionumber,
lang => $lang,
patron_id => $borrowernumber
}
);
for my $plugin_variables ( @plugin_responses ) {
$variables = { %$variables, %$plugin_variables };
}
$template->param(
XSLTBloc => XSLTParse4Display(
{
biblionumber => $biblionumber,
record => $record,
xsl_syspref => 'OPACXSLTDetailsDisplay',
fix_amps => 1,
xslt_variables => $variables
}
),
);
}
my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
# We look for the busc param to build the simple paging from the search
@ -659,16 +627,18 @@ my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 5
# Get component parts details
my $showcomp = C4::Context->preference('ShowComponentRecords');
my $parts;
my ( $parts, $show_analytics );
if ( $showcomp eq 'both' || $showcomp eq 'opac' ) {
if ( my $components = $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) ) {
$show_analytics = 1; # just show link when having results
for my $part ( @{$components} ) {
$part = C4::Search::new_record_from_zebra( 'biblioserver', $part );
my $id = Koha::SearchEngine::Search::extract_biblionumber( $part );
push @{$parts},
XSLTParse4Display(
{
biblionumber => $biblionumber,
biblionumber => $id,
record => $part,
xsl_syspref => 'OPACXSLTResultsDisplay',
fix_amps => 1,
@ -678,8 +648,35 @@ if ( $showcomp eq 'both' || $showcomp eq 'opac' ) {
$template->param( ComponentParts => $parts );
$template->param( ComponentPartsQuery => $biblio->get_components_query );
}
} else { # check if we should show analytics anyway
$show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not
}
# XSLT processing of some stuff
my $variables = {};
my @plugin_responses = Koha::Plugins->call(
'opac_detail_xslt_variables',
{
biblio_id => $biblionumber,
lang => C4::Languages::getlanguage(),
patron_id => $borrowernumber,
},
);
for my $plugin_variables ( @plugin_responses ) {
$variables = { %$variables, %$plugin_variables };
}
$variables->{anonymous_session} = $borrowernumber ? 0 : 1;
$variables->{show_analytics_link} = $show_analytics;
$template->param(
XSLTBloc => XSLTParse4Display({
biblionumber => $biblionumber,
record => $record,
xsl_syspref => 'OPACXSLTDetailsDisplay',
fix_amps => 1,
xslt_variables => $variables,
}),
);
# Get items on order
my ( @itemnumbers_on_order );
if ( C4::Context->preference('OPACAcquisitionDetails' ) ) {