From 10cb635cd461e4ce080dd1c1d6aa422d0310e591 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 4 Dec 2020 16:00:31 +1300 Subject: [PATCH] Bug 16522: Adding 773 to cart and list displays and emails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds a new subroutine get_host_item_entries in the Koha::Biblio module which retrieves any 773 fields from the biblio record. The subroutine is used to show a host item entry and a link to the record in the following places: - staff client list - staff client cart - staff client send list email - staff client send cart email - opac list - opac cart - opac send list email email - opac send cart email To test: 1. apply patch, restart services 2. log into the staff client and enable the syspref EasyAnalyticalRecords 3. find a record with an item. take note of the barcode. 4. go to another record (biblio 2). click Edit -> Link to host record 5. enter the barcode in the input and submit. 6. click the MARC tab and confirm the host record has been linked under MARC field 773. 7. add biblio 2 to your cart, and to a list. 8. go to your cart. confirm you see the 'host item entry' link. 9. click on 'more details' and confirm you see the 'host item entries' link. 10. click 'send' to email the cart. confirm the email contains the host item entry and the link sends you to the catalogue page for the record in the OPAC. 11. go to the list you added the record to. confirm you see the 'source' link for the host item entry. 12. click 'send list' to email the list. confirm the email contains the host item entry and the link sends you to the catalogue page for the record in the OPAC. 13. log into the OPAC. repeat steps 7 to 12 on the OPAC and confirm they all pass as expected. 14. confirm tests pass: t/db_dependent/Koha/Biblio.t Sponsored-by: Bibliotheksservice-Zentrum Baden-Württemberg (BSZ) --- Koha/Biblio.pm | 19 ++++++++ basket/basket.pl | 1 + basket/sendbasket.pl | 2 + .../intranet-tmpl/prog/en/modules/basket/basket.tt | 28 +++++++++++ .../prog/en/modules/basket/sendbasket.tt | 14 ++++++ .../prog/en/modules/virtualshelves/sendshelf.tt | 14 ++++++ .../prog/en/xslt/MARC21slim2intranetResults.xsl | 54 ++++++++++++++++++++-- .../opac-tmpl/bootstrap/en/modules/opac-basket.tt | 29 ++++++++++++ .../bootstrap/en/modules/opac-sendbasket.tt | 14 ++++++ .../bootstrap/en/modules/opac-sendshelf.tt | 14 ++++++ .../bootstrap/en/xslt/MARC21slim2OPACResults.xsl | 54 ++++++++++++++++++++-- opac/opac-basket.pl | 2 + opac/opac-sendbasket.pl | 2 + opac/opac-sendshelf.pl | 2 + t/db_dependent/Koha/Biblio.t | 34 +++++++++++++- virtualshelves/sendshelf.pl | 2 + 16 files changed, 274 insertions(+), 11 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 1d84f01a7b..f70ff46ff9 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -869,6 +869,25 @@ sub to_api { return { %$response, %$biblioitem }; } +=head2 get_host_item_entries + + my @host_item_entries = $biblio->get_host_item_entries; + +Returns a list of MARC::Field objects of the 773 tag which contain host item entry information. +Returns undef if no 773 defined. + +=cut + +sub get_host_item_entries { + my ( $self ) = @_; + + my $record = $self->metadata->record; + + my @host_item_entries = $record->field('773'); + + return ( @host_item_entries > 0 ) ? \@host_item_entries : undef; +} + =head3 to_api_mapping This method returns the mapping for representing a Koha::Biblio object diff --git a/basket/basket.pl b/basket/basket.pl index 44727d2364..8b1c5d13d6 100755 --- a/basket/basket.pl +++ b/basket/basket.pl @@ -103,6 +103,7 @@ foreach my $biblionumber ( @bibs ) { $dat->{MARCSERIES} = $marcseriesarray; $dat->{MARCURLS} = $marcurlsarray; $dat->{HASAUTHORS} = $hasauthors; + $dat->{HOSTITEMENTRIES} = $biblio->get_host_item_entries; if ( C4::Context->preference("IntranetBiblioDefaultView") eq "normal" ) { $dat->{dest} = "/cgi-bin/koha/catalogue/detail.pl"; diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl index 9e273b1f45..2dc8809fca 100755 --- a/basket/sendbasket.pl +++ b/basket/sendbasket.pl @@ -72,6 +72,7 @@ if ( $email_add ) { my $record = GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }); + my $biblio = Koha::Biblios->find($biblionumber); my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); @@ -88,6 +89,7 @@ if ( $email_add ) { $dat->{HASAUTHORS} = $hasauthors; $dat->{'biblionumber'} = $biblionumber; $dat->{ITEM_RESULTS} = \@items; + $dat->{HOSTITEMENTRIES} = $biblio->get_host_item_entries; $iso2709 .= $record->as_usmarc(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt index 5c62dad4f1..b521c5ad06 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt @@ -217,6 +217,23 @@ [% END %] + [% IF BIBLIO_RESULT.HOSTITEMENTRIES %] + + Host item entries + + [% FOREACH entry IN BIBLIO_RESULT.HOSTITEMENTRIES %] +

+ [% IF entry.subfield('0') %] + [% entry.subfield('t') | html %] + [% ELSE %] + [% entry.subfield('t') | html %] + [% END %] +

+ [% END %] + + + [% END %] + Location(s) @@ -281,6 +298,17 @@ [% IF ( BIBLIO_RESULT.notes ) %]

[% BIBLIO_RESULT.notes | html %]

[% END %] + [% IF BIBLIO_RESULT.HOSTITEMENTRIES %] + [% FOREACH entry IN BIBLIO_RESULT.HOSTITEMENTRIES %] +

Host item entry: + [% IF entry.subfield('0') %] + [% entry.subfield('t') | html %] + [% ELSE %] + [% entry.subfield('t') | html %] + [% END %] +

+ [% END %] + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt index 6af47706d0..e342927fd6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt @@ -126,6 +126,20 @@ Your cart LCCN: [% BIBLIO_RESULT.lccn | $raw %]
[% END %] + + [% IF BIBLIO_RESULT.HOSTITEMENTRIES %] + [% FOREACH entry IN BIBLIO_RESULT.HOSTITEMENTRIES %] + Host item entry: + [% IF entry.subfield('0') %] + [% entry.subfield('t') | html %] + [% ELSE %] + [% entry.subfield('t') | html %] + [% END %] + +
+ [% END %] + [% END %] + [% IF ( BIBLIO_RESULT.url ) %] URL: [% BIBLIO_RESULT.url | html %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelf.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelf.tt index 0310e41c5b..17da2afb88 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelf.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/sendshelf.tt @@ -132,6 +132,20 @@ Your list: [% shelfname | $raw %] LCCN: [% BIBLIO_RESULT.lccn | $raw %]
[% END %] + + [% IF BIBLIO_RESULT.HOSTITEMENTRIES %] + [% FOREACH entry IN BIBLIO_RESULT.HOSTITEMENTRIES %] + Host item entry: + [% IF entry.subfield('0') %] + [% entry.subfield('t') | html %] + [% ELSE %] + [% entry.subfield('t') | html %] + [% END %] + +
+ [% END %] + [% END %] + [% IF ( BIBLIO_RESULT.url ) %] URL: [% BIBLIO_RESULT.url | html %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetResults.xsl b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetResults.xsl index aa11b41975..6f993badc9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetResults.xsl +++ b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetResults.xsl @@ -933,13 +933,57 @@ + - - - Source: - - + + + + + Source: + + + + + + + + + + + + + a_t + + + + + + + /cgi-bin/koha/catalogue/search.pl?q=Control-number: + + + + + /cgi-bin/koha/catalogue/detail.pl?biblionumber= + + + + + /cgi-bin/koha/catalogue/search.pl?q=ti,phr: + + + + + + + + + + + + + diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt index b2d8b79c73..d0d14c6ed6 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt @@ -228,6 +228,23 @@ [% END %] + [% IF BIBLIO_RESULT.HOSTITEMENTRIES %] + + Host item entries + + [% FOREACH entry IN BIBLIO_RESULT.HOSTITEMENTRIES %] +

+ [% IF entry.subfield('0') %] + [% entry.subfield('t') | html %] + [% ELSE %] + [% entry.subfield('t') | html %] + [% END %] +

+ [% END %] + + + [% END %] + Location(s) (Status) @@ -279,6 +296,18 @@ [% IF ( TagsInputEnabled && loggedinusername ) %] [% END %] + + [% IF BIBLIO_RESULT.HOSTITEMENTRIES %] + [% FOREACH entry IN BIBLIO_RESULT.HOSTITEMENTRIES %] +

Host item entry: + [% IF entry.subfield('0') %] + [% entry.subfield('t') | html %] + [% ELSE %] + [% entry.subfield('t') | html %] + [% END %] +

+ [% END %] + [% END %] [% BIBLIO_RESULT.author | html %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasket.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasket.tt index 823e0bf0a5..9b694daa1d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasket.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasket.tt @@ -130,6 +130,20 @@ Your cart LCCN: [% BIBLIO_RESULT.lccn | $raw %]
[% END %] + + [% IF BIBLIO_RESULT.HOSTITEMENTRIES %] + [% FOREACH entry IN BIBLIO_RESULT.HOSTITEMENTRIES %] + Host item entry: + [% IF entry.subfield('0') %] + [% entry.subfield('t') | html %] + [% ELSE %] + [% entry.subfield('t') | html %] + [% END %] + +
+ [% END %] + [% END %] + [% IF ( BIBLIO_RESULT.url ) %] URL: [% BIBLIO_RESULT.url | html %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelf.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelf.tt index be952e2399..cf68dff123 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelf.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendshelf.tt @@ -133,6 +133,20 @@ Your list : [% shelfname | $raw %] LCCN: [% BIBLIO_RESULT.lccn | $raw %]
[% END %] + + [% IF BIBLIO_RESULT.HOSTITEMENTRIES %] + [% FOREACH entry IN BIBLIO_RESULT.HOSTITEMENTRIES %] + Host item entry: + [% IF entry.subfield('0') %] + [% entry.subfield('t') | html %] + [% ELSE %] + [% entry.subfield('t') | html %] + [% END %] + +
+ [% END %] + [% END %] + [% IF ( BIBLIO_RESULT.url ) %] URL: [% BIBLIO_RESULT.url | html %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slim2OPACResults.xsl b/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slim2OPACResults.xsl index 92d1d2ff8f..e7fb415a8f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slim2OPACResults.xsl +++ b/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slim2OPACResults.xsl @@ -659,13 +659,57 @@ + - - - Source: - - + + + + + Source: + + + + + + + + + + + + + a_t + + + + + + + /cgi-bin/koha/opac-search.pl?q=Control-number: + + + + + /cgi-bin/koha/opac-detail.pl?biblionumber= + + + + + /cgi-bin/koha/opac-search.pl?q=ti,phr: + + + + + + + + + + + + + diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl index b746abde67..01dd7caca2 100755 --- a/opac/opac-basket.pl +++ b/opac/opac-basket.pl @@ -75,6 +75,7 @@ foreach my $biblionumber ( @bibs ) { # No filtering on the item records needed for the record itself # since the only reason item information is grabbed is because of branchcodes. + my $biblio = Koha::Biblios->find($biblionumber); my $record = &GetMarcBiblio({ biblionumber => $biblionumber }); my $framework = &GetFrameworkCode( $biblionumber ); $record_processor->options({ @@ -150,6 +151,7 @@ foreach my $biblionumber ( @bibs ) { $dat->{MARCSERIES} = $marcseriesarray; $dat->{MARCURLS} = $marcurlsarray; $dat->{HASAUTHORS} = $hasauthors; + $dat->{HOSTITEMENTRIES} = $biblio->get_host_item_entries; if ( C4::Context->preference("BiblioDefaultView") eq "normal" ) { $dat->{dest} = "opac-detail.pl"; diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl index eee5e2c29b..019fdce47c 100755 --- a/opac/opac-sendbasket.pl +++ b/opac/opac-sendbasket.pl @@ -82,6 +82,7 @@ if ( $email_add ) { embed_items => 1, opac => 1, borcat => $borcat }); + my $biblio = Koha::Biblios->find($biblionumber); my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); @@ -98,6 +99,7 @@ if ( $email_add ) { $dat->{HASAUTHORS} = $hasauthors; $dat->{'biblionumber'} = $biblionumber; $dat->{ITEM_RESULTS} = \@items; + $dat->{HOSTITEMENTRIES} = $biblio->get_host_item_entries; $iso2709 .= $record->as_usmarc(); diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl index c97aa450dc..81710008bf 100755 --- a/opac/opac-sendshelf.pl +++ b/opac/opac-sendshelf.pl @@ -86,6 +86,7 @@ if ( $email ) { opac => 1, borcat => $borcat }); next unless $record; + my $biblio = Koha::Biblios->find($biblionumber); my $fw = GetFrameworkCode($biblionumber); my $dat = GetBiblioData($biblionumber); @@ -100,6 +101,7 @@ if ( $email ) { $dat->{'biblionumber'} = $biblionumber; $dat->{ITEM_RESULTS} = \@items; $dat->{HASAUTHORS} = $dat->{'author'} || @$marcauthorsarray; + $dat->{HOSTITEMENTRIES} = $biblio->get_host_item_entries; $iso2709 .= $record->as_usmarc(); diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index ea5e3f289d..81cca74ed5 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 14; +use Test::More tests => 15; use C4::Biblio; use Koha::Database; @@ -614,6 +614,38 @@ subtest 'get_marc_notes() UNIMARC tests' => sub { is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); is( @$notes, 2, 'No more notes' ); +}; + +subtest 'get_host_item_entries() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + # Set up the host record and an item + my $host_biblio = $builder->build_sample_biblio; + my $host_item = $builder->build_sample_item({ biblionumber => $host_biblio->biblionumber }); + + # Set up the test record + my $test_biblio = $builder->build_sample_biblio; + my $record = $test_biblio->metadata->record; + + # Link the host item to the test record + my $field = MARC::Field->new('245','','','a' => "Test title"); + $record->append_fields( $field ); + $field = MARC::Field->new('773','0','','0' => $host_biblio->biblionumber); + $record->append_fields( $field ); + $field = MARC::Field->new('773','0','','9' => $host_item->itemnumber); + $record->append_fields( $field ); + + # Re-retrieve the record + C4::Biblio::ModBiblio( $record, $test_biblio->biblionumber ); + $test_biblio = Koha::Biblios->find( $test_biblio->biblionumber ); + + my $host_items = $test_biblio->get_host_item_entries; + is( @{$host_items}, 1, "Correctly retrieved number of attached host item entries" ); + my $test_host_biblionumber = @{$host_items}[0]->subfield('0'); + is( $test_host_biblionumber, $host_biblio->biblionumber, "Correctly retrieved data about host item entry"); $schema->storage->txn_rollback; }; diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl index f15e2c9f64..1080c3ffed 100755 --- a/virtualshelves/sendshelf.pl +++ b/virtualshelves/sendshelf.pl @@ -67,6 +67,7 @@ if ($to_address) { while ( my $content = $contents->next ) { my $biblionumber = $content->biblionumber; + my $biblio = Koha::Biblios->find($biblionumber); my $dat = GetBiblioData($biblionumber); my $record = GetMarcBiblio({ biblionumber => $biblionumber, @@ -82,6 +83,7 @@ if ($to_address) { $dat->{'biblionumber'} = $biblionumber; $dat->{ITEM_RESULTS} = \@items; $dat->{HASAUTHORS} = $dat->{'author'} || @$marcauthorsarray; + $dat->{HOSTITEMENTRIES} = $biblio->get_host_item_entries; $iso2709 .= $record->as_usmarc(); -- 2.11.0