From f35b120f9bade997d315f76253e0e5b9e55e0ec9 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Thu, 15 Mar 2018 02:00:23 +0000 Subject: [PATCH] Bug 12159: Move borrower_add_additional_fields to Koha::Patron The same function was effectively coded twice. It was removed from members/pay.pl and members/paycollect.pl and placed in Koha/Patron.pm instead. --- Koha/Patron.pm | 29 +++++++++++++++++++++++++++++ members/pay.pl | 24 +----------------------- members/paycollect.pl | 21 +-------------------- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index d0be998..c2d3fec 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -831,6 +831,35 @@ sub is_child { return $self->category->category_type eq 'C' ? 1 : 0; } +=head3 + +foobar + +=cut + +sub borrower_add_additional_fields { + my ( $self, $template ) = @_; + +# some borrower info is not returned in the standard call despite being assumed +# in a number of templates. It should not be the business of this script but in lieu of +# a revised api here it is ... + if ( $self->is_child ) { + my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']} ); + $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; + $template->param( 'catcode' => $patron_categories->next->categorycode ) if $patron_categories->count == 1; + } + + if (C4::Context->preference('ExtendedPatronAttributes')) { + my $b_ref = $self->unblessed; + $b_ref->{extendedattributes} = GetBorrowerAttributes($self->borrowernumber); + $template->param( + ExtendedPatronAttributes => 1, + ); + } + + return; +} + =head3 type =cut diff --git a/members/pay.pl b/members/pay.pl index 05b73e5..624d712 100755 --- a/members/pay.pl +++ b/members/pay.pl @@ -138,7 +138,7 @@ sub add_accounts_to_template { } push @accounts, $account_line; } - borrower_add_additional_fields($patron->unblessed); + $patron->borrower_add_additional_fields($template); $template->param( patron => $patron, @@ -215,28 +215,6 @@ sub writeoff_all { return; } -sub borrower_add_additional_fields { - my $b_ref = shift; - -# some borrower info is not returned in the standard call despite being assumed -# in a number of templates. It should not be the business of this script but in lieu of -# a revised api here it is ... - if ( $b_ref->{category_type} eq 'C' ) { - my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); - $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; - $template->param( 'catcode' => $patron_categories->next->categorycode ) if $patron_categories->count == 1; - } - - if (C4::Context->preference('ExtendedPatronAttributes')) { - $b_ref->{extendedattributes} = GetBorrowerAttributes($borrowernumber); - $template->param( - ExtendedPatronAttributes => 1, - ); - } - - return; -} - sub payselected { my @params = @_; my $amt = 0; diff --git a/members/paycollect.pl b/members/paycollect.pl index 7c16a0a..ea96c13 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -170,7 +170,7 @@ if ( $total_paid and $total_paid ne '0.00' ) { $total_paid = '0.00'; #TODO not right with pay_individual } -borrower_add_additional_fields($borrower, $template); +$patron->borrower_add_additional_fields($template); $template->param(%$borrower); @@ -184,22 +184,3 @@ $template->param( ); output_html_with_http_headers $input, $cookie, $template->output; - -sub borrower_add_additional_fields { - my ( $b_ref, $template ) = @_; - -# some borrower info is not returned in the standard call despite being assumed -# in a number of templates. It should not be the business of this script but in lieu of -# a revised api here it is ... - if ( $b_ref->{category_type} eq 'C' ) { - my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); - $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; - $template->param( 'catcode' => $patron_categories->next->categorycode ) if $patron_categories->count == 1; - } - - if (C4::Context->preference('ExtendedPatronAttributes')) { - $b_ref->{extendedattributes} = GetBorrowerAttributes($b_ref->{borrowernumber}); - } - - return; -} -- 2.1.4