From a5a23bcebcb0cfce65b72f9ccef484e9d44fe33a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 21 Dec 2015 17:13:12 +0000 Subject: [PATCH] Bug 15407: Koha::Patron::Categories - replace GetBorrowercategory The purpose of C4::Members::GetBorrowercategory was to return the patron category for a given categorycode. This can be done easily with the Koha::Patron::Categories->find method. Test plan: - Same prerequisite as before - Edit a guarantor and confirm the information will be updated for his/her guarantee(s). - Update a child to adult patron (Note: Should not we hide the patron categories limited to others libraries? If yes, it must be done on another bug report). There is a special behavior if there is only 1 adult category, the user does not need to select a category. So the same as before with only 1 adult patron category. - Import a patron with a category_code which does not exist. You should be warned. - Modify some patron using the batch patron modification tool. The patron category descriptions should correctly be displayed. Note that the overduerules page has already been tested in a previous patch. Signed-off-by: Chris Cormack Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- C4/Members.pm | 29 ----------------------------- members/memberentry.pl | 11 ++++++----- members/update-child.pl | 11 ++++++----- t/db_dependent/Reserves.t | 3 ++- tools/import_borrowers.pl | 3 ++- tools/modborrowers.pl | 3 ++- tools/overduerules.pl | 4 ++-- 7 files changed, 20 insertions(+), 44 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 061172fee9..bb177964b8 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -79,7 +79,6 @@ BEGIN { &GetBorNotifyAcctRecord &GetborCatFromCatType - &GetBorrowercategory GetBorrowerCategorycode &GetBorrowercategoryList @@ -1351,34 +1350,6 @@ sub GetborCatFromCatType { return ( \@codes, \%labels ); } -=head2 GetBorrowercategory - - $hashref = &GetBorrowercategory($categorycode); - -Given the borrower's category code, the function returns the corresponding -data hashref for a comprehensive information display. - -=cut - -sub GetBorrowercategory { - my ($catcode) = @_; - my $dbh = C4::Context->dbh; - if ($catcode){ - my $sth = - $dbh->prepare( - "SELECT description,dateofbirthrequired,upperagelimit,category_type - FROM categories - WHERE categorycode = ?" - ); - $sth->execute($catcode); - my $data = - $sth->fetchrow_hashref; - return $data; - } - return; -} # sub getborrowercategory - - =head2 GetBorrowerCategorycode $categorycode = &GetBorrowerCategoryCode( $borrowernumber ); diff --git a/members/memberentry.pl b/members/memberentry.pl index 413db97a74..5aa0b4a544 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -42,6 +42,7 @@ use C4::Form::MessagingPreferences; use Koha::Patron::Debarments; use Koha::Cities; use Koha::DateUtils; +use Koha::Patron::Categories; use Koha::Token; use Email::Valid; use Module::Load; @@ -153,9 +154,9 @@ $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 ); my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'}; my $category_type = $input->param('category_type') || ''; unless ($category_type or !($categorycode)){ - my $borrowercategory = GetBorrowercategory($categorycode); - $category_type = $borrowercategory->{'category_type'}; - my $category_name = $borrowercategory->{'description'}; + my $borrowercategory = Koha::Patron::Categories->find($categorycode); + $category_type = $borrowercategory->category_type; + my $category_name = $borrowercategory->description; $template->param("categoryname"=>$category_name); } $category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error ! @@ -303,8 +304,8 @@ if ($op eq 'save' || $op eq 'insert'){ if ( $newdata{dateofbirth} ) { my $age = GetAge($newdata{dateofbirth}); - my $borrowercategory=GetBorrowercategory($newdata{'categorycode'}); - my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'}); + my $borrowercategory = Koha::Patron::Categories->find($newdata{categorycode}); + my ($low,$high) = ($borrowercategory->dateofbirthrequired, $borrowercategory->upperagelimit); if (($high && ($age > $high)) or ($age < $low)) { push @errors, 'ERROR_age_limitations'; $template->param( age_low => $low); diff --git a/members/update-child.pl b/members/update-child.pl index e5e230200b..b0a51548d0 100755 --- a/members/update-child.pl +++ b/members/update-child.pl @@ -33,6 +33,7 @@ use C4::Context; use C4::Auth; use C4::Output; use C4::Members; +use Koha::Patron::Categories; # use Smart::Comments; @@ -66,8 +67,8 @@ if ( $op eq 'multi' ) { my $row; $row->{catcode} = $k; $row->{catdesc} = $labels->{$k}; - my $borcat = GetBorrowercategory( $row->{catcode} ); - $row->{cattype} = $borcat->{'category_type'}; + my $borcat = Koha::Patron::Categories->find($row->{catcode}); + $row->{cattype} = $borcat->category_type; push @rows, $row; } $template->param( @@ -83,9 +84,9 @@ elsif ( $op eq 'update' ) { my $member = GetMember('borrowernumber'=>$borrowernumber); $member->{'guarantorid'} = 0; $member->{'categorycode'} = $catcode; - my $borcat = GetBorrowercategory($catcode); - $member->{'category_type'} = $borcat->{'category_type'}; - $member->{'description'} = $borcat->{'description'}; + my $borcat = Koha::Patron::Categories->find($catcode); + $member->{'category_type'} = $borcat->category_type; + $member->{'description'} = $borcat->description; delete $member->{password}; ModMember(%$member); diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index e9f1e6b81c..771008b5f9 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -33,6 +33,7 @@ use Koha::Holds; use t::lib::Mocks; use Koha::DateUtils; +use Koha::Patron::Categories; use Data::Dumper; BEGIN { @@ -63,7 +64,7 @@ foreach my $addbra ('CPL', 'FPL', 'RPL') { # Add categories if not existing foreach my $addcat ('S', 'PT') { - $dbh->do("INSERT INTO categories (categorycode,hidelostitems,category_type) VALUES (?,?,?)",undef,($addcat, 0, $addcat eq 'S'? 'S': 'A')) unless GetBorrowercategory($addcat); + $dbh->do("INSERT INTO categories (categorycode,hidelostitems,category_type) VALUES (?,?,?)",undef,($addcat, 0, $addcat eq 'S'? 'S': 'A')) unless Koha::Patron::Categories->find($addcat); } # Create a helper biblio diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl index d350a7f297..8f86d7fd94 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -51,6 +51,7 @@ use Koha::Patron::Debarments; use Koha::Patrons; use Koha::DateUtils; use Koha::Token; +use Koha::Patron::Categories; use Text::CSV; # Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals: @@ -188,7 +189,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { #warn join(':',%borrower); if ($borrower{categorycode}) { push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline, value=>$borrower{categorycode}, category_map=>1} - unless GetBorrowercategory($borrower{categorycode}); + unless Koha::Patron::Categories->find($borrower{categorycode}); } else { push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline}; } diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl index 6416343f82..f16544080f 100755 --- a/tools/modborrowers.pl +++ b/tools/modborrowers.pl @@ -37,6 +37,7 @@ use C4::Output; use List::MoreUtils qw /any uniq/; use Koha::DateUtils qw( dt_from_string ); use Koha::List::Patron; +use Koha::Patron::Categories; my $input = new CGI; my $op = $input->param('op') || 'show_form'; @@ -377,7 +378,7 @@ sub GetBorrowerInfos { } $borrower->{$_} = $userdate || ''; } - $borrower->{category_description} = GetBorrowercategory( $borrower->{categorycode} )->{description}; + $borrower->{category_description} = Koha::Patron::Categories->find( $borrower->{categorycode} )->{description}; my $attr_loop = C4::Members::Attributes::GetBorrowerAttributes( $borrower->{borrowernumber} ); $borrower->{patron_attributes} = $attr_loop; } diff --git a/tools/overduerules.pl b/tools/overduerules.pl index d77a6ad6fc..8ce3f3c3af 100755 --- a/tools/overduerules.pl +++ b/tools/overduerules.pl @@ -129,8 +129,8 @@ if ($op eq 'save') { foreach my $bor (keys %temphash){ # get category name if we need it for an error message - my $bor_category = GetBorrowercategory($bor); - my $bor_category_name = defined($bor_category) ? $bor_category->{description} : $bor; + my $bor_category = Koha::Patron::Categories->find($bor); + my $bor_category_name = $bor_category ? $bor_category->description : $bor; # Do some Checking here : delay1 < delay2