Bugzilla – Attachment 149465 Details for
Bug 33496
Add 'host_items' param to Koha::Biblio->items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33496: Add 'host_items' param to Koha::Biblio->items
Bug-33496-Add-hostitems-param-to-KohaBiblio-items.patch (text/plain), 3.80 KB, created by
Nick Clemens (kidclamp)
on 2023-04-11 18:50:42 UTC
(
hide
)
Description:
Bug 33496: Add 'host_items' param to Koha::Biblio->items
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-04-11 18:50:42 UTC
Size:
3.80 KB
patch
obsolete
>From c67e37438fe86deb8eb81b664211908e8f0105df Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 10 Mar 2023 12:37:49 +0000 >Subject: [PATCH] Bug 33496: Add 'host_items' param to Koha::Biblio->items > >This patch adds an option to the $biblio->items method to allow >retrieving the items and analytic items for a record. This is intended >to allow fetching a single Items object, and related object, rather than >having to fetch the items, and the host items, and push them together > >This is step towards being able to fetch items using API/DataTables directly > >To test: >1 - prove -v t/db_dependent/Koha/Biblio.t >--- > Koha/Biblio.pm | 35 +++++++++++++++++++++++++++-------- > t/db_dependent/Koha/Biblio.t | 14 +++++++++++++- > 2 files changed, 40 insertions(+), 9 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 8c453a83ef..66635f8065 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -443,11 +443,17 @@ Returns the related Koha::Items object for this biblio > =cut > > sub items { >- my ($self) = @_; >+ my ($self,$params) = @_; > > my $items_rs = $self->_result->items; > >- return Koha::Items->_new_from_dbic( $items_rs ); >+ return Koha::Items->_new_from_dbic( $items_rs ) unless $params->{host_items}; >+ >+ my $host_itemnumbers = $self->_host_itemnumbers(); >+ my $params = { -or => [biblionumber => $self->id] }; >+ push @{$params->{'-or'}}, itemnumber => { -in => $host_itemnumbers } if $host_itemnumbers; >+ >+ return Koha::Items->search($params); > } > > =head3 host_items >@@ -464,12 +470,25 @@ sub host_items { > return Koha::Items->new->empty > unless C4::Context->preference('EasyAnalyticalRecords'); > >+ my $host_itemnumbers = $self->_host_itemnumbers; >+ >+ return Koha::Items->search( { itemnumber => { -in => $host_itemnumbers } } ); >+} >+ >+=head3 _host_itemnumbers >+ >+my $host_itemnumber = $biblio->_host_itemnumbers(); >+ >+Return the itemnumbers for analytical items on this record >+ >+=cut >+ >+sub _host_itemnumbers { >+ my ($self) = @_; >+ > my $marcflavour = C4::Context->preference("marcflavour"); > my $analyticfield = '773'; >- if ( $marcflavour eq 'MARC21' ) { >- $analyticfield = '773'; >- } >- elsif ( $marcflavour eq 'UNIMARC' ) { >+ if ( $marcflavour eq 'UNIMARC' ) { > $analyticfield = '461'; > } > my $marc_record = $self->metadata->record; >@@ -477,10 +496,10 @@ sub host_items { > foreach my $field ( $marc_record->field($analyticfield) ) { > push @itemnumbers, $field->subfield('9'); > } >- >- return Koha::Items->search( { itemnumber => { -in => \@itemnumbers } } ); >+ return \@itemnumbers; > } > >+ > =head3 itemtype > > my $itemtype = $biblio->itemtype(); >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index af3a424bc9..02c2d18218 100755 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -799,7 +799,7 @@ subtest 'get_marc_notes() UNIMARC tests' => sub { > }; > > subtest 'host_items() tests' => sub { >- plan tests => 6; >+ plan tests => 7; > > $schema->storage->txn_begin; > >@@ -835,6 +835,18 @@ subtest 'host_items() tests' => sub { > is( ref($host_items), 'Koha::Items' ); > is( $host_items->count, 0 ); > >+ subtest 'test host_items param in items()' => sub { >+ plan tests => 4; >+ >+ my $items = $biblio->items; >+ is( $items->count, 1, "Without host_items param we only get the items on the biblio"); >+ $items = $biblio->items({ host_items => 1 }); >+ is( $items->count, 3, "With param host_items we get the biblio items plus analytics"); >+ is( ref($items), 'Koha::Items', "We correctly get an Items object"); >+ is_deeply( [ $items->get_column('itemnumber') ], >+ [ $item_1->itemnumber, $host_item_1->itemnumber, $host_item_2->itemnumber ] ); >+ }; >+ > $schema->storage->txn_rollback; > }; > >-- >2.30.2
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 33496
:
149465
|
149572
|
149678
|
151466
|
151467
|
151468