Bugzilla – Attachment 126955 Details for
Bug 26314
"Volumes: show volumes" showing regardless of whether there are volumes linked to the record
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26314: Update for changes to bug 11175 methodology
Bug-26314-Update-for-changes-to-bug-11175-methodol.patch (text/plain), 8.12 KB, created by
Martin Renvoize (ashimema)
on 2021-10-27 07:52:53 UTC
(
hide
)
Description:
Bug 26314: Update for changes to bug 11175 methodology
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-10-27 07:52:53 UTC
Size:
8.12 KB
patch
obsolete
>From e44593471298ca38ea2e7914f689c1ed875fd9d9 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 27 Oct 2021 08:50:47 +0100 >Subject: [PATCH] Bug 26314: Update for changes to bug 11175 methodology > >This moves the show_volumes calculation back out of C4::XSLT into the >controller scripts and refined the search query builder slightly based >on the XSLT equivilent. >--- > C4/XSLT.pm | 7 -- > Koha/Biblio.pm | 163 ++++++++++++++++++++++++-------------------- > catalogue/detail.pl | 8 ++- > opac/opac-detail.pl | 4 ++ > 4 files changed, 101 insertions(+), 81 deletions(-) > >diff --git a/C4/XSLT.pm b/C4/XSLT.pm >index cdf90929eb..2e4df1a592 100644 >--- a/C4/XSLT.pm >+++ b/C4/XSLT.pm >@@ -281,13 +281,6 @@ sub XSLTParse4Display { > } > } > >- # possibly show volumes link in Detail views >- if ($xslsyspref =~ m/Details/) { >- $biblio //= Koha::Biblios->find( $biblionumber ); >- my $volumes = $biblio->get_marc_volumes(); >- $variables->{show_volumes_link} = ( scalar @{$volumes} == 0 ) ? 0 : 1; >- } >- > # embed variables > my $varxml = "<variables>\n"; > while (my ($key, $value) = each %$variables) { >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index b597f87ff8..94a8058cba 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -568,6 +568,96 @@ sub get_components_query { > return $searchstr; > } > >+=head3 get_marc_volumes >+ >+ my $volumes = $self->get_marc_volumes(); >+ >+Returns an array of MARCXML data, which are volumes parts of >+this object (MARC21 773$w points to this) >+ >+=cut >+ >+sub get_marc_volumes { >+ my ( $self, $max_results ) = @_; >+ >+ return $self->{_volumes} if defined( $self->{_volumes} ); >+ >+ my $searchstr = $self->get_volumes_query; >+ >+ if ( defined($searchstr) ) { >+ my $searcher = Koha::SearchEngine::Search->new( >+ { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); >+ my ( $errors, $results, $total_hits ) = >+ $searcher->simple_search_compat( $searchstr, 0, $max_results ); >+ $self->{_volumes} = >+ ( defined($results) && scalar(@$results) ) ? $results : []; >+ } >+ else { >+ $self->{_volumes} = []; >+ } >+ >+ return $self->{_volumes}; >+} >+ >+=head2 get_volumes_query >+ >+Returns a query which can be used to search for all component parts of MARC21 biblios >+ >+=cut >+ >+sub get_volumes_query { >+ my ($self) = @_; >+ >+ # MARC21 Only for now >+ return if (C4::Context->preference('marcflavour') ne 'MARC21'); >+ >+ my $marc = $self->metadata->record; >+ >+ # Only build volumes query if we're in a 'Set' record >+ # or we have a monographic series. >+ my $leader19 = substr( $marc->leader, 19, 1 ); >+ my $pf008 = $marc->field('008') || ''; >+ my $mseries = ( $pf008 && substr( $pf008->data(), 21, 1 ) eq 'm' ) ? 1 : 0; >+ return unless ( $leader19 eq 'a' || $mseries ); >+ >+ my $builder = Koha::SearchEngine::QueryBuilder->new( >+ { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); >+ >+ my $searchstr; >+ if ( C4::Context->preference('UseControlNumber') ) { >+ my $pf001 = $marc->field('001') || undef; >+ >+ if ( defined($pf001) ) { >+ $searchstr = "("; >+ my $pf003 = $marc->field('003') || undef; >+ >+ if ( !defined($pf003) ) { >+ # search for 773$w='Host001' >+ $searchstr .= "rcn:" . $pf001->data(); >+ } >+ else { >+ $searchstr .= "("; >+ # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001' >+ $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")"; >+ $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\""; >+ $searchstr .= ")"; >+ } >+ >+ # exclude monograph and serial component part records >+ $searchstr .= " NOT (bib-level:a OR bib-level:b)"; >+ $searchstr .= ")"; >+ } >+ } >+ else { >+ my $cleaned_title = $marc->subfield('245', "a"); >+ $cleaned_title =~ tr|/||; >+ $cleaned_title = $builder->clean_search_term($cleaned_title); >+ $searchstr = "ti,phr:($cleaned_title)"; >+ } >+ >+ return $searchstr; >+} >+ > =head3 subscriptions > > my $subscriptions = $self->subscriptions >@@ -1034,79 +1124,6 @@ sub get_marc_host { > } > } > >-=head3 get_marc_volumes >- >- my $volumes = $self->get_marc_volumes(); >- >-Returns an array of MARCXML data, which are volumes parts of >-this object (MARC21 773$w points to this) >- >-=cut >- >-sub get_marc_volumes { >- my ($self, $max_results) = @_; >- >- return [] if (C4::Context->preference('marcflavour') ne 'MARC21'); >- >- my $searchstr = $self->get_volumes_query; >- >- if (defined($searchstr)) { >- my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); >- my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, $max_results ); >- $self->{_volumes} = $results if ( defined($results) && scalar(@$results) ); >- } >- >- return $self->{_volumes} || []; >-} >- >-=head2 get_volumes_query >- >-Returns a query which can be used to search for all component parts of MARC21 biblios >- >-=cut >- >-sub get_volumes_query { >- my ($self) = @_; >- >- my $builder = Koha::SearchEngine::QueryBuilder->new( >- { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); >- my $marc = $self->metadata->record; >- >- my $searchstr; >- if ( C4::Context->preference('UseControlNumber') ) { >- my $pf001 = $marc->field('001') || undef; >- >- if ( defined($pf001) ) { >- $searchstr = "("; >- my $pf003 = $marc->field('003') || undef; >- >- if ( !defined($pf003) ) { >- # search for 773$w='Host001' >- $searchstr .= "rcn:" . $pf001->data(); >- } >- else { >- $searchstr .= "("; >- # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001' >- $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")"; >- $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\""; >- $searchstr .= ")"; >- } >- >- # exclude monograph and serial component part records >- $searchstr .= " NOT (bib-level:a OR bib-level:b)"; >- $searchstr .= ")"; >- } >- } >- else { >- my $cleaned_title = $marc->subfield('245', "a"); >- $cleaned_title =~ tr|/||; >- $cleaned_title = $builder->clean_search_term($cleaned_title); >- $searchstr = "ti,phr:($cleaned_title)"; >- } >- >- return $searchstr; >-} >- > =head2 Internal methods > > =head3 type >diff --git a/catalogue/detail.pl b/catalogue/detail.pl >index 0c2bc884d2..26a9e9cd8a 100755 >--- a/catalogue/detail.pl >+++ b/catalogue/detail.pl >@@ -225,8 +225,14 @@ if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { > $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->messages}; > } > >+# Display volumes link >+my $show_volumes = 1 if @{$biblio->get_marc_volumes(1)}; >+ > # XSLT processing of some stuff >-my $xslt_variables = { show_analytics_link => $show_analytics }; >+my $xslt_variables = { >+ show_analytics_link => $show_analytics, >+ show_volumes_link => $show_volumes >+}; > $template->param( > XSLTDetailsDisplay => '1', > XSLTBloc => XSLTParse4Display({ >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 73ea3b46a0..48b4bf2a6f 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -652,6 +652,9 @@ if ( $showcomp eq 'both' || $showcomp eq 'opac' ) { > $show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not > } > >+# Display volumes link >+my $show_volumes = 1 if @{$biblio->get_marc_volumes(1)}; >+ > # XSLT processing of some stuff > my $variables = {}; > my @plugin_responses = Koha::Plugins->call( >@@ -667,6 +670,7 @@ for my $plugin_variables ( @plugin_responses ) { > } > $variables->{anonymous_session} = $borrowernumber ? 0 : 1; > $variables->{show_analytics_link} = $show_analytics; >+$variables->{show_volumes_link} = $show_volumes; > $template->param( > XSLTBloc => XSLTParse4Display({ > biblionumber => $biblionumber, >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26314
:
123615
|
124367
|
124380
|
124381
|
126448
|
126449
|
126450
|
126952
|
126953
|
126954
|
126955
|
155437
|
155438
|
155439
|
155440
|
155441
|
155446
|
155447
|
155448
|
155449
|
155450
|
155670
|
155671
|
155672
|
155673
|
155674
|
155675
|
155676
|
155677
|
155678
|
155679
|
155680
|
155681
|
162163
|
162164