From 2aecc0c36600473f02fa573e40b8ae894e2ba13b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 24 Jun 2020 14:50:37 -0300 Subject: [PATCH] Bug 15851: Only display the analytics link when required This patch makes opac-detail.pl query for analytics the same way it would do with the generated link (i.e. based on UseControlNumber) and passes a flag to the XSLT so it displays (or not) the 'Analytics' link. To test: 1. Apply the first patch 2. Have a known record without analytics 3. Open the record in the OPAC => FAIL: It shows the 'Analytics' link 4. Have a record known to have analytics and open in OPAC, on a separate tab => SUCCESS: It shows the 'Analytics' link 5. Apply this patch and restart_all 6. Reload the tabs => SUCCESS: It shows the link where it has to, and hides it where it shouldn't be displayed 7. Sign off :-D Sponsored-by: Orex Digital Signed-off-by: Hugo Agud --- .../en/xslt/MARC21slim2OPACDetail.xsl | 33 ++++++++++--------- opac/opac-detail.pl | 18 +++++++++- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slim2OPACDetail.xsl b/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slim2OPACDetail.xsl index b2d2c67cc5..daca6d55b6 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slim2OPACDetail.xsl +++ b/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slim2OPACDetail.xsl @@ -353,21 +353,24 @@ - - results_summary analytics - Analytics: - - - - /cgi-bin/koha/opac-search.pl?q=rcn:+and+(bib-level:a+or+bib-level:b) - - - /cgi-bin/koha/opac-search.pl?q=Host-item: - - - Show analytics - - + + + + results_summary analytics + Analytics: + + + + /cgi-bin/koha/opac-search.pl?q=rcn:+and+(bib-level:a+or+bib-level:b) + + + /cgi-bin/koha/opac-search.pl?q=Host-item: + + + Show analytics + + + diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index f4bdf3dd70..4e789cb8b5 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -62,6 +62,7 @@ use Koha::Patrons; use Koha::Plugins; use Koha::Ratings; use Koha::Reviews; +use Koha::SearchEngine::Search; use Try::Tiny; @@ -181,8 +182,23 @@ my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; if ( $xslfile ) { + my $searcher = Koha::SearchEngine::Search->new( + { index => $Koha::SearchEngine::BIBLIOS_INDEX } + ); + my $cleaned_title = $biblio->title; + $cleaned_title =~ tr|/||; + my $query = + ( C4::Context->preference('UseControlNumber') and $record->field('001') ) + ? 'rcn:'. $record->field('001')->data . ' and (bib-level:a or bib-level:b)' + : "Host-item:$cleaned_title"; + my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 ); + + warn "Warning from simple_search_compat: $err" + if $err; + my $variables = { - anonymous_session => ($borrowernumber) ? 0 : 1 + anonymous_session => ($borrowernumber) ? 0 : 1, + show_analytics_link => $count > 0 ? 1 : 0 }; my @plugin_responses = Koha::Plugins->call( -- 2.28.0