From bc849ce8200452157b1b2a7ea01a82b8bd3c560f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 30 Mar 2023 10:54:51 +0200 Subject: [PATCH] Bug 22440: Add standard accessors for later usage Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 4b470e43a2a6d3e7608903f3693e1e7c37853a27) Signed-off-by: Martin Renvoize --- Koha/Illrequest.pm | 61 +++++++++++++++++++++++++++----- Koha/Illrequestattribute.pm | 16 +++++++-- Koha/Schema/Result/Illrequest.pm | 33 ++++++++++++++++- 3 files changed, 99 insertions(+), 11 deletions(-) diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index d160c152b8..4187ba152e 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -192,6 +192,21 @@ sub illcomments { ); } +=head3 comments + + my $ill_comments = $req->comments; + +Returns a I resultset for the linked comments. + +=cut + +sub comments { + my ( $self ) = @_; + return Koha::Illcomments->_new_from_dbic( + scalar $self->_result->comments + ); +} + =head3 logs =cut @@ -204,12 +219,45 @@ sub logs { =head3 patron + my $patron = $request->patron; + +Returns the linked I object. + =cut sub patron { my ( $self ) = @_; - return Koha::Patron->_new_from_dbic( - scalar $self->_result->borrowernumber + + return Koha::Patron->_new_from_dbic( scalar $self->_result->patron ); +} + +=head3 library + + my $library = $request->library; + +Returns the linked I object. + +=cut + +sub library { + my ($self) = @_; + + return Koha::Library->_new_from_dbic( scalar $self->_result->library ); +} + +=head3 ill_extended_attributes + + my $ill_extended_attributes = $request->ill_extended_attributes; + +Returns the linked I resultset object. + +=cut + +sub ill_extended_attributes { + my ( $self ) = @_; + + return Koha::Illrequestattributes->_new_from_dbic( + scalar $self->_result->ill_extended_attributes ); } @@ -1142,12 +1190,9 @@ or undef if none exists sub biblio { my ( $self ) = @_; - - return if !$self->biblio_id; - - return Koha::Biblios->find({ - biblionumber => $self->biblio_id - }); + my $biblio_rs = $self->_result->biblio; + return unless $biblio_rs; + return Koha::Biblio->_new_from_dbic($biblio_rs); } =head3 check_out diff --git a/Koha/Illrequestattribute.pm b/Koha/Illrequestattribute.pm index 715b3f4752..6c0c584ddc 100644 --- a/Koha/Illrequestattribute.pm +++ b/Koha/Illrequestattribute.pm @@ -31,8 +31,6 @@ Koha::Illrequestattribute - Koha Illrequestattribute Object class =head2 Internal methods -=cut - =head3 _type =cut @@ -41,6 +39,20 @@ sub _type { return 'Illrequestattribute'; } +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Illrequestattribute object +on the API. + +=cut + +sub to_api_mapping { + return { + illrequest_id => 'ill_request_id', + readonly => 'read_only', + }; +} + =head1 AUTHOR Alex Sassmannshausen diff --git a/Koha/Schema/Result/Illrequest.pm b/Koha/Schema/Result/Illrequest.pm index adc931336a..51dabbec12 100644 --- a/Koha/Schema/Result/Illrequest.pm +++ b/Koha/Schema/Result/Illrequest.pm @@ -334,6 +334,37 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-06-23 18:44:13 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:on9OCRON/U0uR+m9aPIKPg +__PACKAGE__->has_many( + "comments", + "Koha::Schema::Result::Illcomment", + { "foreign.illrequest_id" => "self.illrequest_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->has_many( + "ill_extended_attributes", + "Koha::Schema::Result::Illrequestattribute", + { "foreign.illrequest_id" => "self.illrequest_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->belongs_to( + "library", + "Koha::Schema::Result::Branch", + { branchcode => "branchcode" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "patron", + "Koha::Schema::Result::Borrower", + { borrowernumber => "borrowernumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); -# You can replace this text with custom code or comments, and it will be preserved on regeneration 1; -- 2.39.5