From 7d0623deabe0b020e529ba3eb7eeaccc99d75ef0 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 --- 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 383799d..c189838 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -80,7 +80,6 @@ BEGIN { &GetBorNotifyAcctRecord &GetborCatFromCatType - &GetBorrowercategory GetBorrowerCategorycode &GetBorrowercategoryList @@ -1454,34 +1453,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 597c68d..973efbb 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 Email::Valid; use Module::Load; if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { @@ -150,9 +151,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 ! @@ -295,8 +296,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 e5e2302..b0a5154 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 cfc6eee..b5b0b98 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -32,6 +32,7 @@ use Koha::Holds; use t::lib::Mocks; use Koha::DateUtils; +use Koha::Patron::Categories; use Data::Dumper; BEGIN { @@ -61,7 +62,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 8c03274..e422a67 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -49,6 +49,7 @@ use C4::Reports::Guided; use C4::Templates; use Koha::Patron::Debarments; use Koha::DateUtils; +use Koha::Patron::Categories; use Text::CSV; # Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals: @@ -178,7 +179,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 c776406..c904f09 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'; @@ -371,7 +372,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 d77a6ad..8ce3f3c 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