Bug 33960: Add api mapping and biblioitems to Old::Biblios to match Biblio

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Nick Clemens 2023-09-07 16:27:07 +00:00 committed by Katrin Fischer
parent eacd6f56a1
commit 61e01ec8a1
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 86 additions and 3 deletions

View File

@ -20,6 +20,7 @@ use Modern::Perl;
use base qw(Koha::Object);
use Koha::Old::Biblio::Metadatas;
use Koha::Old::Biblioitems;
=head1 NAME
@ -40,7 +41,7 @@ Returns a Koha::Biblio::Metadata object
=cut
sub metadata {
my ( $self ) = @_;
my ($self) = @_;
my $metadata = $self->_result->metadata;
return Koha::Old::Biblio::Metadata->_new_from_dbic($metadata);
@ -55,7 +56,7 @@ Returns a Marc::Record object
=cut
sub record {
my ( $self ) = @_;
my ($self) = @_;
return $self->metadata->record;
}
@ -69,11 +70,65 @@ Returns the record schema (MARC21, USMARC or UNIMARC).
=cut
sub record_schema {
my ( $self ) = @_;
my ($self) = @_;
return $self->metadata->schema // C4::Context->preference("marcflavour");
}
=head3 biblioitem
my $field = $self->biblioitem
Returns the related Koha::Old::Biblioitem object for this Biblio object
=cut
sub biblioitem {
my ($self) = @_;
return Koha::Old::Biblioitems->find( { biblionumber => $self->biblionumber } );
}
=head3 to_api
my $json = $deleted_biblio->to_api;
Overloaded method that returns a JSON representation of the Koha::Old::Biblio object,
suitable for API output. The related Koha::Old::Biblioitem object is merged as expected
on the API.
=cut
sub to_api {
my ( $self, $args ) = @_;
my $response = $self->SUPER::to_api($args);
$args = defined $args ? {%$args} : {};
delete $args->{embed};
my $biblioitem = $self->biblioitem->to_api($args);
return { %$response, %$biblioitem };
}
=head3 to_api_mapping
This method returns the mapping for representing a Koha::Old::Biblio object
on the API.
=cut
sub to_api_mapping {
return {
biblionumber => 'biblio_id',
frameworkcode => 'framework_id',
unititle => 'uniform_title',
seriestitle => 'series_title',
copyrightdate => 'copyright_date',
datecreated => 'creation_date',
deleted_on => 'timestamp',
};
}
=head2 Internal methods

View File

@ -33,6 +33,34 @@ Koha::Old::Biblios - Koha Old::Biblio Object set class
=head2 Internal Methods
=head3 api_query_fixer
$query_string = $biblios->api_query_fixer( $query_string, $context, $no_quotes );
Method that takes care of adjusting I<$query_string> as required. An optional I<$context> parameter
will be used to prefix the relevant query atoms if present. A I<$no_quotes> boolean parameter
can be passed to choose not to use quotes on matching. This is particularly useful in the context of I<order_by>.
=cut
sub api_query_fixer {
my ( $self, $query, $context, $no_quotes ) = @_;
my $quotes = $no_quotes ? '' : '"';
if ($context) {
$query =~
s/${quotes}${context}\.(age_restriction|cn_class|cn_item|cn_sort|cn_source|cn_suffix|collection_issn|collection_title|collection_volume|ean|edition_statement|illustrations|isbn|issn|item_type|lc_control_number|notes|number|pages|publication_place|publication_year|publisher|material_size|serial_total_issues|url|volume|volume_date|volume_description)${quotes}/${quotes}${context}\.deletedbiblioitem\.$1${quotes}/g;
} else {
$query =~
s/${quotes}(age_restriction|cn_class|cn_item|cn_sort|cn_source|cn_suffix|collection_issn|collection_title|collection_volume|ean|edition_statement|illustrations|isbn|issn|item_type|lc_control_number|notes|number|pages|publication_place|publication_year|publisher|material_size|serial_total_issues|url|volume|volume_date|volume_description)${quotes}/${quotes}deletedbiblioitem\.$1${quotes}/g;
$query =~ # handle ambiguous 'biblionumber'
s/${quotes}(biblio_id)${quotes}/${quotes}me\.$1${quotes}/g;
}
return $query;
}
=head3 _type
=cut