Bug 29418: Make detail rendering use the cleaned-up title for searching

This patch makes both staff and OPAC detail pages generate a valid
search link so you can trace related records in the Show analytics
link.

To test:
1. Pick a bibliographic record (I chose 'Unconditional' from the sample
   data
2. Add " and ? to the title statement. I changed it to
   'Uncond"itional?¿'
3. Add a child record to it
4. Open the detail page for the host record
=> FAIL: It doesn't show the 'Show analytics' link
5. Repeat 4 for the same record, in the OPAC
=> FAIL: It doesn't show the 'Show analytics' link
6. Apply this patch
7. Repeat 4 and 5.
=> SUCCESS: Links are shown!
8. Follow the links
=> SUCCESS: The links take you to the right resultset!
9. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
This commit is contained in:
Tomas Cohen Arazi 2022-07-01 11:54:34 -03:00 committed by Victor Grousset/tuxayo
parent cc418a482a
commit 73d7d6602a
4 changed files with 14 additions and 6 deletions

View File

@ -138,7 +138,7 @@ if ( $xslfile ) {
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)";
: "Host-item:(\"$cleaned_title\")";
my ( $err, $result, $count );
eval {
( $err, $result, $count ) =
@ -153,8 +153,11 @@ if ( $xslfile ) {
$template->param( analytics_error => 1 );
}
my $show_analytics_link = defined $count && $count > 0 ? 1 : 0;
my $variables = {
show_analytics_link => defined $count && $count > 0 ? 1 : 0
show_analytics_link => $show_analytics_link,
( $show_analytics_link ? ( analytics_query => $cleaned_title ) : () )
};
$template->param(

View File

@ -213,6 +213,7 @@
<xsl:variable name="show_analytics_link" select="marc:variables/marc:variable[@name='show_analytics_link']" />
<xsl:if test="$show_analytics_link='1'">
<xsl:variable name="analytics_query" select="marc:variables/marc:variable[@name='analytics_query']" />
<xsl:element name="span">
<xsl:attribute name="class">results_summary analytics <xsl:value-of select="$leader7_class"/></xsl:attribute>
<span class="label">Analytics: </span>
@ -222,7 +223,7 @@
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=rcn:<xsl:value-of select="str:encode-uri(marc:controlfield[@tag=001], true())"/>+AND+(bib-level:a+OR+bib-level:b)</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=Host-item:(<xsl:value-of select="str:encode-uri(translate(marc:datafield[@tag=245]/marc:subfield[@code='a'], '/', ''), true())"/>)</xsl:attribute>
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=Host-item:("<xsl:value-of select="$analytics_query"/>")</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:text>Show analytics</xsl:text>

View File

@ -248,6 +248,7 @@
<xsl:variable name="show_analytics_link" select="marc:variables/marc:variable[@name='show_analytics_link']" />
<xsl:if test="$show_analytics_link='1'">
<xsl:variable name="analytics_query" select="marc:variables/marc:variable[@name='analytics_query']" />
<xsl:element name="span">
<xsl:attribute name="class">results_summary analytics <xsl:value-of select="$leader7_class"/></xsl:attribute>
<span class="label">Analytics: </span>
@ -257,7 +258,7 @@
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=rcn:<xsl:value-of select="str:encode-uri(marc:controlfield[@tag=001], true())"/>+AND+(bib-level:a+OR+bib-level:b)</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=Host-item:(<xsl:value-of select="str:encode-uri(translate(marc:datafield[@tag=245]/marc:subfield[@code='a'], '/', ''), true())"/>)</xsl:attribute>
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=Host-item:("<xsl:value-of select="$analytics_query"/>")</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:text>Show analytics</xsl:text>

View File

@ -195,7 +195,7 @@ if ( $xslfile ) {
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)";
: "Host-item:(\"$cleaned_title\")";
my ( $err, $result, $count );
eval {
( $err, $result, $count ) =
@ -208,9 +208,12 @@ if ( $xslfile ) {
warn "Warning from simple_search_compat: $error";
}
my $show_analytics_link = defined $count && $count > 0 ? 1 : 0;
my $variables = {
anonymous_session => ($borrowernumber) ? 0 : 1,
show_analytics_link => defined $count && $count > 0 ? 1 : 0
show_analytics_link => $show_analytics_link,
( $show_analytics_link ? ( analytics_query => $cleaned_title ) : () )
};
my @plugin_responses = Koha::Plugins->call(