From 548833835ef631a6c2f05dbec18d977031973776 Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Thu, 30 Jan 2025 16:16:49 +0000 Subject: [PATCH] Bug 38924: Add Koha::Patron::Quota::Usage(s) classes Add ::Usage(s) classes for working with quota allocation usage. We overload store to ensure data consistency for the checkout_id field which is linked to either the issue or old_issue table appropriatly. We include a checkout relationship that handles the lack of foreign key due to issues/old_issues. --- Koha/Patron/Quota/Usage.pm | 75 +++++++++++++++++++++++++++++++++++++ Koha/Patron/Quota/Usages.pm | 35 +++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 Koha/Patron/Quota/Usage.pm create mode 100644 Koha/Patron/Quota/Usages.pm diff --git a/Koha/Patron/Quota/Usage.pm b/Koha/Patron/Quota/Usage.pm new file mode 100644 index 00000000000..7d3696fc7f7 --- /dev/null +++ b/Koha/Patron/Quota/Usage.pm @@ -0,0 +1,75 @@ +package Koha::Patron::Quota::Usage; + +use base qw(Koha::Object); +use Modern::Perl; +use Koha::Patron::Quota; +use Koha::Patron::Quota::Usages; + +=head1 NAME + +Koha::Patron::Quota::Usage - Koha Patron Quota Usage Object class + +=head1 API + +=head2 Class methods + +=cut + +=head3 patron + +Returns the patron this quota usage belongs to + +=cut + +sub patron { + my ($self) = @_; + my $rs = $self->_result->patron; + return Koha::Patron->_new_from_dbic($rs); +} + +=head3 quota + +Returns the quota this usage belongs to + +=cut + +sub quota { + my ($self) = @_; + my $rs = $self->_result->patron_quota; + return Koha::Patron::Quota->_new_from_dbic($rs); +} + +=head3 store + +Overloaded I method to set implement issue_id foreign key in code + +=cut + +sub store { + my ($self) = @_; + + # Check that we have a valid issue_id + unless ( !$self->issue_id + || Koha::Checkouts->find( $self->issue_id ) + || Koha::Old::Checkouts->find( $self->issue_id ) ) + { + Koha::Exceptions::Object::FKConstraint->throw( + error => 'Broken FK Contraint', + broken_fk => 'issue_id' + ); + } + + return $self->SUPER::store(); +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'PatronQuotaUsage'; +} + +1; diff --git a/Koha/Patron/Quota/Usages.pm b/Koha/Patron/Quota/Usages.pm new file mode 100644 index 00000000000..4fd82e26c67 --- /dev/null +++ b/Koha/Patron/Quota/Usages.pm @@ -0,0 +1,35 @@ +package Koha::Patron::Quota::Usages; + +use base qw(Koha::Objects); +use Modern::Perl; +use Koha::Patron::Quota::Usage; + +=head1 NAME + +Koha::Patron::Quota::Usages - Koha Patron Quota Usages Object set class + +=head1 API + +=head2 Class methods + +=cut + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'PatronQuotaUsage'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Patron::Quota::Usage'; +} + +1; -- 2.39.5