View | Details | Raw Unified | Return to bug 16877
Collapse All | Expand All

(-)a/C4/Members.pm (-14 / +13 lines)
Lines 42-47 use Text::Unaccent qw( unac_string ); Link Here
42
use Koha::AuthUtils qw(hash_password);
42
use Koha::AuthUtils qw(hash_password);
43
use Koha::Database;
43
use Koha::Database;
44
use Koha::List::Patron;
44
use Koha::List::Patron;
45
use Koha::Patron::Categories;
45
46
46
our (@ISA,@EXPORT,@EXPORT_OK,$debug);
47
our (@ISA,@EXPORT,@EXPORT_OK,$debug);
47
48
Lines 1510-1531 If no category code provided, the function returns all the categories. Link Here
1510
=cut
1511
=cut
1511
1512
1512
sub GetBorrowercategoryList {
1513
sub GetBorrowercategoryList {
1513
    my $no_branch_limit = @_ ? shift : 0;
1514
    my ($no_branch_limit) = @_;
1515
1514
    my $branch_limit = $no_branch_limit
1516
    my $branch_limit = $no_branch_limit
1515
        ? 0
1517
        ? 0
1516
        : C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
1518
        : C4::Context->userenv && C4::Context->userenv->{"branch"};
1517
    my $dbh       = C4::Context->dbh;
1519
1518
    my $query = "SELECT categories.* FROM categories";
1520
1519
    $query .= qq{
1521
    my %cond;
1520
        LEFT JOIN categories_branches ON categories.categorycode = categories_branches.categorycode
1522
    my %clause = (distinct => 1, order_by => 'description');
1521
        WHERE branchcode = ? OR branchcode IS NULL GROUP BY description
1523
    if ($branch_limit) {
1522
    } if $branch_limit;
1524
        $clause{join} = 'categories_branches';
1523
    $query .= " ORDER BY description";
1525
        $cond{'categories_branches.branchcode'} = [undef, $branch_limit];
1524
    my $sth = $dbh->prepare( $query );
1526
    }
1525
    $sth->execute( $branch_limit ? $branch_limit : () );
1527
    return Koha::Patron::Categories->search(\%cond, \%clause)->unblessed;
1526
    my $data = $sth->fetchall_arrayref( {} );
1527
    $sth->finish;
1528
    return $data;
1529
}    # sub getborrowercategory
1528
}    # sub getborrowercategory
1530
1529
1531
=head2 GetAge
1530
=head2 GetAge
(-)a/t/db_dependent/Members.t (-1 / +5 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 77;
20
use Test::More tests => 78;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Data::Dumper;
22
use Data::Dumper;
23
use C4::Context;
23
use C4::Context;
Lines 77-82 C4::Context->set_userenv ( @USERENV ); Link Here
77
my $userenv = C4::Context->userenv
77
my $userenv = C4::Context->userenv
78
  or BAIL_OUT("No userenv");
78
  or BAIL_OUT("No userenv");
79
79
80
# XXX maybe needs a real test
81
my $categories = GetBorrowercategoryList();
82
ok(scalar( @$categories ), "GetBorrowercategoryList()");
83
80
# Make a borrower for testing
84
# Make a borrower for testing
81
my %data = (
85
my %data = (
82
    cardnumber => $CARDNUMBER,
86
    cardnumber => $CARDNUMBER,
(-)a/tools/modborrowers.pl (-2 / +1 lines)
Lines 104-110 if ( $op eq 'show' ) { Link Here
104
    my @patron_attributes_values;
104
    my @patron_attributes_values;
105
    my @patron_attributes_codes;
105
    my @patron_attributes_codes;
106
    my $patron_attribute_types = C4::Members::AttributeTypes::GetAttributeTypes_hashref('all');
106
    my $patron_attribute_types = C4::Members::AttributeTypes::GetAttributeTypes_hashref('all');
107
    my $patron_categories = C4::Members::GetBorrowercategoryList;
107
    my $patron_categories = C4::Members::GetBorrowercategoryList();
108
    for ( values %$patron_attribute_types ) {
108
    for ( values %$patron_attribute_types ) {
109
        my $attr_type = C4::Members::AttributeTypes->fetch( $_->{code} );
109
        my $attr_type = C4::Members::AttributeTypes->fetch( $_->{code} );
110
        # TODO Repeatable attributes are not correctly managed and can cause data lost.
110
        # TODO Repeatable attributes are not correctly managed and can cause data lost.
111
- 

Return to bug 16877