@@ -, +, @@ GetBorrowercategoryList - Same prerequisite as before - On the "patron attribute types" admin page (admin/patron-attr-types.pl). - On the "Batch patron deletion/anonymization" (tools/cleanborrowers.pl), the dropdown list should be filled correctly. - On the following report: reports/reserves_stats.pl --- C4/Members.pm | 27 --------------------------- admin/patron-attr-types.pl | 9 ++++++--- reports/issues_stats.pl | 28 ++++++++++++++-------------- reports/reserves_stats.pl | 11 ++++++----- tools/cleanborrowers.pl | 5 ++++- tools/import_borrowers.pl | 4 ++-- tools/modborrowers.pl | 9 ++++----- 7 files changed, 36 insertions(+), 57 deletions(-) --- a/C4/Members.pm +++ a/C4/Members.pm @@ -89,7 +89,6 @@ BEGIN { &GetborCatFromCatType GetBorrowerCategorycode - &GetBorrowercategoryList &GetBorrowersToExpunge &GetBorrowersWhoHaveNeverBorrowed @@ -1583,32 +1582,6 @@ sub GetBorrowerCategorycode { return $sth->fetchrow; } -=head2 GetBorrowercategoryList - - $arrayref_hashref = &GetBorrowercategoryList; -If no category code provided, the function returns all the categories. - -=cut - -sub GetBorrowercategoryList { - my $no_branch_limit = @_ ? shift : 0; - my $branch_limit = $no_branch_limit - ? 0 - : C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; - my $dbh = C4::Context->dbh; - my $query = "SELECT categories.* FROM categories"; - $query .= qq{ - LEFT JOIN categories_branches ON categories.categorycode = categories_branches.categorycode - WHERE branchcode = ? OR branchcode IS NULL GROUP BY description - } if $branch_limit; - $query .= " ORDER BY description"; - my $sth = $dbh->prepare( $query ); - $sth->execute( $branch_limit ? $branch_limit : () ); - my $data = $sth->fetchall_arrayref( {} ); - $sth->finish; - return $data; -} # sub getborrowercategory - =head2 GetAge $dateofbirth,$date = &GetAge($date); --- a/admin/patron-attr-types.pl +++ a/admin/patron-attr-types.pl @@ -29,9 +29,10 @@ use C4::Branch; use C4::Context; use C4::Output; use C4::Koha; -use C4::Members qw/GetBorrowercategoryList/; use C4::Members::AttributeTypes; +use Koha::Patron::Categories; + my $script_name = "/cgi-bin/koha/admin/patron-attr-types.pl"; our $input = new CGI; @@ -92,10 +93,11 @@ sub add_attribute_type_form { }; } + my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']}); $template->param( attribute_type_form => 1, confirm_op => 'add_attribute_type_confirmed', - categories => GetBorrowercategoryList, + categories => $patron_categories, branches_loop => \@branches_loop, ); authorised_value_category_list($template); @@ -274,11 +276,12 @@ sub edit_attribute_type_form { $template->param ( category_code => $attr_type->category_code ); $template->param ( category_description => $attr_type->category_description ); + my @patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']}); $template->param( attribute_type_form => 1, edit_attribute_type => 1, confirm_op => 'edit_attribute_type_confirmed', - categories => GetBorrowercategoryList, + categories => \@patron_categories, ); } --- a/reports/issues_stats.pl +++ a/reports/issues_stats.pl @@ -76,7 +76,7 @@ $template->param(do_it => $do_it, ); my $itemtypes = GetItemTypes(); -my $categoryloop = GetBorrowercategoryList; +my @patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']}); my $ccodes = GetKohaAuthorisedValues("items.ccode"); my $locations = GetKohaAuthorisedValues("items.location"); @@ -152,7 +152,7 @@ my $CGIextChoice = ( 'CSV' ); # FIXME translation my $CGIsepChoice=GetDelimiterChoices; $template->param( - categoryloop => $categoryloop, + categoryloop => \@patron_categories, itemtypeloop => \@itemtypeloop, locationloop => \@locations, ccodeloop => \@ccodes, @@ -322,12 +322,12 @@ sub calculate { ($celvalue eq $_->{authorised_value}) or next; $cell{rowtitle_display} = $_->{lib} and last; } - } elsif ($line =~ /category/) { - foreach (@$categoryloop) { - ($celvalue eq $_->{categorycode}) or next; - $cell{rowtitle_display} = $_->{description} and last; - } - } + } elsif ($line =~ /category/) { + foreach my $patron_category ( @patron_categories ) { + ($celvalue eq $patron_category->categorycode) or next; + $cell{rowtitle_display} = $patron_category->description and last; + } + } push @loopline, \%cell; } @@ -396,12 +396,12 @@ sub calculate { ($celvalue eq $_->{authorised_value}) or next; $cell{coltitle_display} = $_->{lib} and last; } - } elsif ($column =~ /category/) { - foreach (@$categoryloop) { - ($celvalue eq $_->{categorycode}) or next; - $cell{coltitle_display} = $_->{description} and last; - } - } + } elsif ($column =~ /category/) { + foreach my $patron_category ( @patron_categories ) { + ($celvalue eq $patron_category->categorycode) or next; + $cell{coltitle_display} = $patron_category->description and last; + } + } push @loopcol, \%cell; } --- a/reports/reserves_stats.pl +++ a/reports/reserves_stats.pl @@ -32,6 +32,7 @@ use C4::Output; use C4::Reports; use C4::Members; use Koha::DateUtils; +use Koha::Patron::Categories; use List::MoreUtils qw/any/; use YAML; @@ -80,7 +81,7 @@ $template->param(do_it => $do_it, ); my $itemtypes = GetItemTypes(); -my $categoryloop = GetBorrowercategoryList; +my @patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']}); my $ccodes = GetKohaAuthorisedValues("items.ccode"); my $locations = GetKohaAuthorisedValues("items.location"); @@ -158,7 +159,7 @@ my $CGIextChoice = ( 'CSV' ); # FIXME translation my $CGIsepChoice=GetDelimiterChoices; $template->param( - categoryloop => $categoryloop, + categoryloop => \@patron_categories, itemtypeloop => \@itemtypeloop, locationloop => \@locations, ccodeloop => \@ccodes, @@ -353,9 +354,9 @@ sub display_value { } } elsif ( $crit =~ /category/ ) { - foreach (@$categoryloop) { - ( $value eq $_->{categorycode} ) or next; - $display_value = $_->{description} and last; + foreach my $patron_category ( @patron_categories ) { + ( $value eq $patron_category->categorycode ) or next; + $display_value = $patron_category->description and last; } } return $display_value; --- a/tools/cleanborrowers.pl +++ a/tools/cleanborrowers.pl @@ -40,6 +40,7 @@ use C4::Output; use C4::Members; # GetBorrowersWhoHavexxxBorrowed. use C4::Circulation; # AnonymiseIssueHistory. use Koha::DateUtils qw( dt_from_string output_pref ); +use Koha::Patron::Categories; use Date::Calc qw/Today Add_Delta_YM/; my $cgi = new CGI; @@ -147,12 +148,14 @@ elsif ( $step == 3 ) { ); } +my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']}); + $template->param( step => $step, not_borrowered_since => $not_borrowered_since, borrower_dateexpiry => $borrower_dateexpiry, last_issue_date => $last_issue_date, - borrower_categorycodes => GetBorrowercategoryList(), + borrower_categorycodes => $patron_categories, borrower_categorycode => $borrower_categorycode, ); --- a/tools/import_borrowers.pl +++ a/tools/import_borrowers.pl @@ -85,8 +85,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ my $branches = GetBranchesLoop(); $template->param( branches => $branches ) if ( $branches ); # get the patron categories and pass them to the template -my $categories = GetBorrowercategoryList(); -$template->param( categories => $categories ) if ( $categories ); +my @patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']}); +$template->param( categories => \@patron_categories ); my $columns = C4::Templates::GetColumnDefs( $input )->{borrowers}; $columns = [ grep { $_->{field} ne 'borrowernumber' ? $_ : () } @$columns ]; $template->param( borrower_fields => $columns ); --- a/tools/modborrowers.pl +++ a/tools/modborrowers.pl @@ -104,7 +104,7 @@ if ( $op eq 'show' ) { my @patron_attributes_values; my @patron_attributes_codes; my $patron_attribute_types = C4::Members::AttributeTypes::GetAttributeTypes_hashref('all'); - my $patron_categories = C4::Members::GetBorrowercategoryList; + my @patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']}); for ( values %$patron_attribute_types ) { my $attr_type = C4::Members::AttributeTypes->fetch( $_->{code} ); my $options = $attr_type->authorised_value_category @@ -118,8 +118,8 @@ if ( $op eq 'show' ) { my $category_code = $_->{category_code}; my ( $category_lib ) = map { - ( defined $category_code and $_->{categorycode} eq $category_code ) ? $_->{description} : () - } @$patron_categories; + ( defined $category_code and $_->categorycode eq $category_code ) ? $_->description : () + } @patron_categories; push @patron_attributes_codes, { attribute_code => $_->{code}, @@ -144,9 +144,8 @@ if ( $op eq 'show' ) { my @branches_option; push @branches_option, { value => $_->{value}, lib => $_->{branchname} } for @$branches; unshift @branches_option, { value => "", lib => "" }; - my $categories = GetBorrowercategoryList; my @categories_option; - push @categories_option, { value => $_->{categorycode}, lib => $_->{description} } for @$categories; + push @categories_option, { value => $_->categorycode, lib => $_->description } for @patron_categories; unshift @categories_option, { value => "", lib => "" }; my $bsort1 = GetAuthorisedValues("Bsort1"); my @sort1_option; --