From 83171f6e3ce98b025755055358ba4bf3f098dbc6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 25 Aug 2022 12:13:08 +0100 Subject: [PATCH] Bug 31458: Add add_restriction to Koha::Patron This patch adds the beggnings of an add_restriction method to Koha::Patron. --- Koha/Patron.pm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 2080c33504..3699574ecb 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1223,8 +1223,9 @@ sub overdues { ); } +=head3 Patron Restrictions -=head3 restrictions +=head4 restrictions my $restrictions = $patron->restrictions; @@ -1238,6 +1239,36 @@ sub restrictions { return Koha::Patron::Restrictions->_new_from_dbic($restrictions_rs); } +=head4 add_restriction + + my $new_restriction = $patron->add_restriction({}); + +Method to add a new restriction to a patrons account + +=cut + +sub add_restriction { + my ($self, $params) = @_; + + my $manager_id = $params->{'manager_id'}; + $manager_id //= C4::Context->userenv ? C4::Context->userenv->{'number'} : undef; + + my $restriction_rs = $self->_result->add_to_borrower_debarments( + { + expiration => $params->{expiration}, + type => $params->{type}, + comment => $params->{comment}, + manager_id => $manager_id, + created => \'NOW()' + } + )->discard_changes; + + # FIXME: Drop this next + Koha::Patron::Debarments::UpdateBorrowerDebarmentFlags($self->borrowernumber); + + return Koha::Patron::Restriction->_new_from_dbic($restriction_rs); +} + =head3 get_routing_lists my $routinglists = $patron->get_routing_lists -- 2.20.1