From 0e4afcc28e11642bf83d1729935939ddb35799ca Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 12 May 2022 18:37:17 +0200 Subject: [PATCH] Bug 32030: ERM - related agreements - Koha classes Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/Agreement.pm | 26 ++++++++++++++++++++++++++ Koha/ERM/Agreement/Relationship.pm | 14 +++++++++++++- Koha/ERM/Agreement/Relationships.pm | 12 ++++++++---- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Koha/ERM/Agreement.pm b/Koha/ERM/Agreement.pm index 1e4c073562..611906a282 100644 --- a/Koha/ERM/Agreement.pm +++ b/Koha/ERM/Agreement.pm @@ -24,6 +24,7 @@ use base qw(Koha::Object); use Koha::ERM::Agreement::Periods; use Koha::ERM::Agreement::UserRoles; use Koha::ERM::Agreement::Licenses; +use Koha::ERM::Agreement::Relationships; =head1 NAME @@ -111,6 +112,31 @@ sub agreement_licenses { return Koha::ERM::Agreement::Licenses->_new_from_dbic($agreement_licenses_rs); } +=head3 agreement_relationships + +Returns the agreement relationships of this agreement + +=cut + +sub agreement_relationships { + my ( $self, $relationships ) = @_; + + if ( $relationships ) { + my $schema = $self->_result->result_source->schema; + $schema->txn_do( + sub { + $self->agreement_relationships->delete; + + for my $relationship (@$relationships) { + $self->_result->add_to_erm_agreement_relationships_agreements($relationship); + } + } + ); + } + my $related_agreements_rs = $self->_result->erm_agreement_relationships_agreements; + return Koha::ERM::Agreement::Relationships->_new_from_dbic($related_agreements_rs); +} + =head2 Internal methods =head3 _type diff --git a/Koha/ERM/Agreement/Relationship.pm b/Koha/ERM/Agreement/Relationship.pm index eac0b28325..0186ec70f5 100644 --- a/Koha/ERM/Agreement/Relationship.pm +++ b/Koha/ERM/Agreement/Relationship.pm @@ -35,7 +35,7 @@ Koha::ERM::Agreement::Relationship - Koha Agreement Relationship Object class =head3 agreement -Return the agreement linked to this relationship +Return the agreement of this relationship =cut @@ -45,6 +45,18 @@ sub agreement { return Koha::ERM::Agreement->_new_from_dbic($agreement_rs); } +=head3 related_agreement + +Return the agreement linked to this relationship + +=cut + +sub related_agreement { + my ( $self ) = @_; + my $agreement_rs = $self->_result->related_agreement; + return Koha::ERM::Agreement->_new_from_dbic($agreement_rs); +} + =head2 Internal methods =head3 _type diff --git a/Koha/ERM/Agreement/Relationships.pm b/Koha/ERM/Agreement/Relationships.pm index ae501723d7..501eba44d0 100644 --- a/Koha/ERM/Agreement/Relationships.pm +++ b/Koha/ERM/Agreement/Relationships.pm @@ -1,4 +1,4 @@ -package Koha::ERM::Agreement::RelatedAgreements; +package Koha::ERM::Agreement::Relationships; # This file is part of Koha. # @@ -20,13 +20,13 @@ use Modern::Perl; use Koha::Database; -use Koha::ERM::Agreement::RelatedAgreement; +use Koha::ERM::Agreement::Relationship; use base qw(Koha::Objects); =head1 NAME -Koha::ERM::Agreement::RelatedAgreements- Koha Agreement RelatedAgreement Object set class +Koha::ERM::Agreement::Relationships- Koha Agreement RelatedAgreement Object set class =head1 API @@ -42,8 +42,12 @@ sub _type { return 'ErmAgreementRelationship'; } +=head3 object_class + +=cut + sub object_class { - return 'Koha::ERM::Agreement::RelatedAgreement'; + return 'Koha::ERM::Agreement::Relationship'; } 1; -- 2.39.5