Bugzilla – Attachment 138060 Details for
Bug 31224
Koha::Biblio::Metadata->record should use the EmbedItems filter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[POC] Bug 31224: Add Koha::Biblio->metadata_record
POC-Bug-31224-Add-KohaBiblio-metadatarecord.patch (text/plain), 3.79 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-07-22 20:50:58 UTC
(
hide
)
Description:
[POC] Bug 31224: Add Koha::Biblio->metadata_record
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-07-22 20:50:58 UTC
Size:
3.79 KB
patch
obsolete
>From f2657859f97ec92b930baa40ec8233856ec6a4a4 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 22 Jul 2022 17:42:35 -0300 >Subject: [PATCH] [POC] Bug 31224: Add Koha::Biblio->metadata_record > >This patch introduces a higher-level method for retrieving a 'prepared' >record for using in specific contexts. In particular, I only focused on >embedding item information and OPAC view filtering. But we could add a >way to get the record through the ViewPolicy also for staff. > >The virtue of this patch is that it explains better than my words why I >think having the *embed_items* and *opac* parameters in >Koha::Biblio::Metadata->record is not ideal. And makes the other >implementation feel like is done at the wrong level. > >I know it's been done like that to act as a drop-in replacement fro GetMarcBiblio, >which was a good first step. But we need to revisit how it is used, in general, to come >up with a more refined and useful design. So we do not port the same >design problems from C4::* into Koha::*. > >Try to think how it would be used in contexts like opac-MARCdetail.pl or >any other OPAC controller script. > >Thanks! >--- > Koha/Biblio.pm | 55 +++++++++++++++++++++++++++++++++++++++++ > Koha/Biblio/Metadata.pm | 11 +++------ > 2 files changed, 59 insertions(+), 7 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 0af49b939ec..5e1810092cf 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -88,6 +88,61 @@ sub metadata { > return Koha::Biblio::Metadata->_new_from_dbic($metadata); > } > >+=head3 metadata_record >+ >+ my $record = $biblio->metadata_record( >+ { >+ [ embed_items => 1|0, >+ opac => 1|0, >+ patron => $patron, ] >+ } >+ ); >+ >+Returns the metadata serialized as appropriate for the metadata object >+type. Currently only I<MARC::Record> objects are returned. >+ >+=cut >+ >+sub metadata_record { >+ my ($self, $params) = @_; >+ >+ my $patron = $params->{patron}; >+ >+ my $record = $self->metadata->record; >+ >+ if ( $params->{embed_items} or $params->{opac} ) { >+ # There's need for a RecordProcessor, let's do it! >+ my @filters; >+ my $options = {}; >+ >+ if ($params->{embed_items}) { >+ push @filters, 'EmbedItems'; >+ $options->{items} = $self->items->filter_by_visible_in_opac( >+ { >+ ( $params->{patron} ? patron => $params->{patron} : ()) >+ } >+ ); >+ } >+ >+ if ( $params->{opac} ) { >+ push @filters, 'ViewPolicy'; >+ $options->{interface} = 'opac'; >+ $options->{frameworkcode} = $self->frameworkcode; >+ } >+ >+ my $rp = Koha::RecordProcessor->new( >+ { >+ filters => \@filters, >+ options => $options >+ } >+ ); >+ >+ $rp->process( $record ); >+ } >+ >+ return $record; >+} >+ > =head3 orders > > my $orders = $biblio->orders(); >diff --git a/Koha/Biblio/Metadata.pm b/Koha/Biblio/Metadata.pm >index ad451797e51..b6608919f0a 100644 >--- a/Koha/Biblio/Metadata.pm >+++ b/Koha/Biblio/Metadata.pm >@@ -165,14 +165,11 @@ sub _embed_items { > if ( $opac ) { > $items = $items->filter_by_visible_in_opac({ patron => $patron }); > } >- my @itemnumbers = $items->get_column('itemnumber'); >- my @item_fields; >- for my $itemnumber ( @itemnumbers ) { >- my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); >- push @item_fields, $item_marc->field($itemtag); >- } >- $record->append_fields(@item_fields); > >+ # convert items to MARC::Field objects >+ my @item_fields = map { $_->as_marc_field } @{$items->as_list}; >+ >+ $record->append_fields(@item_fields); > } > else { > Koha::Exceptions::Metadata->throw( >-- >2.34.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 31224
:
138060
|
138061
|
138062
|
138063
|
138064
|
142137
|
142138
|
142139
|
142140
|
142141
|
142142
|
142143
|
161933
|
161934
|
161935
|
161936
|
161937
|
161938
|
161939
|
161940
|
161941
|
161942
|
161943
|
161944
|
173530
|
173531
|
173532
|
173533
|
173534
|
173535
|
173588
|
173597
|
173598
|
173636
|
173637
|
173638
|
173639
|
173640
|
173641
|
173642
|
173643
|
173644
|
174262
|
174263