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

(-)a/C4/Branch.pm (-10 lines)
Lines 40-46 BEGIN { Link Here
40
		&GetBranchesInCategory
40
		&GetBranchesInCategory
41
		&ModBranchCategoryInfo
41
		&ModBranchCategoryInfo
42
		&mybranch
42
		&mybranch
43
		&GetBranchesCount
44
	);
43
	);
45
    @EXPORT_OK = qw( &onlymine &mybranch );
44
    @EXPORT_OK = qw( &onlymine &mybranch );
46
}
45
}
Lines 403-417 sub ModBranchCategoryInfo { Link Here
403
        $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) );
402
        $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) );
404
    }
403
    }
405
}
404
}
406
sub GetBranchesCount {
407
    my $dbh = C4::Context->dbh();
408
    my $query = "SELECT COUNT(*) AS branches_count FROM branches";
409
    my $sth = $dbh->prepare( $query );
410
    $sth->execute();
411
    my $row = $sth->fetchrow_hashref();
412
    return $row->{'branches_count'};
413
}
414
415
1;
405
1;
416
__END__
406
__END__
417
407
(-)a/C4/Koha.pm (-3 / +4 lines)
Lines 24-32 use strict; Link Here
24
#use warnings; FIXME - Bug 2505
24
#use warnings; FIXME - Bug 2505
25
25
26
use C4::Context;
26
use C4::Context;
27
use C4::Branch qw(GetBranchesCount);
27
use C4::Branch; # Can be removed?
28
use Koha::Cache;
28
use Koha::Cache;
29
use Koha::DateUtils qw(dt_from_string);
29
use Koha::DateUtils qw(dt_from_string);
30
use Koha::Libraries;
30
use DateTime::Format::MySQL;
31
use DateTime::Format::MySQL;
31
use Business::ISBN;
32
use Business::ISBN;
32
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
33
use autouse 'Data::cselectall_arrayref' => qw(Dumper);
Lines 857-863 sub getFacets { Link Here
857
            ];
858
            ];
858
859
859
            unless ( C4::Context->preference("singleBranchMode")
860
            unless ( C4::Context->preference("singleBranchMode")
860
                || GetBranchesCount() == 1 )
861
                || Koha::Libraries->search->count == 1 )
861
            {
862
            {
862
                my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
863
                my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
863
                if (   $DisplayLibraryFacets eq 'both'
864
                if (   $DisplayLibraryFacets eq 'both'
Lines 939-945 sub getFacets { Link Here
939
            ];
940
            ];
940
941
941
            unless ( C4::Context->preference("singleBranchMode")
942
            unless ( C4::Context->preference("singleBranchMode")
942
                || GetBranchesCount() == 1 )
943
                || Koha::Libraries->search->count == 1 )
943
            {
944
            {
944
                my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
945
                my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
945
                if (   $DisplayLibraryFacets eq 'both'
946
                if (   $DisplayLibraryFacets eq 'both'
(-)a/t/db_dependent/Branch.t (-9 / +8 lines)
Lines 45-51 can_ok( Link Here
45
      GetBranchesInCategory
45
      GetBranchesInCategory
46
      ModBranchCategoryInfo
46
      ModBranchCategoryInfo
47
      mybranch
47
      mybranch
48
      GetBranchesCount)
48
      )
49
);
49
);
50
50
51
51
Lines 59-65 $dbh->do('DELETE FROM branchcategories'); Link Here
59
59
60
# Start test
60
# Start test
61
61
62
my $count = GetBranchesCount();
62
my $count = Koha::Libraries->search->count;
63
like( $count, '/^\d+$/', "the count is a number" );
63
like( $count, '/^\d+$/', "the count is a number" );
64
64
65
#add 2 branches
65
#add 2 branches
Lines 111-120 is( ModBranch($b2), undef, 'the field add is missing' ); Link Here
111
111
112
$b2->{add} = 1;
112
$b2->{add} = 1;
113
ModBranch($b2);
113
ModBranch($b2);
114
is( GetBranchesCount(), $count + 2, "two branches added" );
114
is( Koha::Libraries->search->count, $count + 2, "two branches added" );
115
115
116
is( Koha::Libraries->find( $b2->{branchcode} )->delete, 1,          "One row affected" );
116
is( Koha::Libraries->find( $b2->{branchcode} )->delete, 1,          "One row affected" );
117
is( GetBranchesCount(),             $count + 1, "branch BRB deleted" );
117
is( Koha::Libraries->search->count,             $count + 1, "branch BRB deleted" );
118
118
119
#Test GetBranchName
119
#Test GetBranchName
120
is( GetBranchName( $b1->{branchcode} ),
120
is( GetBranchName( $b1->{branchcode} ),
Lines 129-135 is_deeply( $branchdetail, $b1, 'branchdetail is right' ); Link Here
129
#Test Getbranches
129
#Test Getbranches
130
my $branches = GetBranches();
130
my $branches = GetBranches();
131
is( scalar( keys %$branches ),
131
is( scalar( keys %$branches ),
132
    GetBranchesCount(), "GetBranches returns the right number of branches" );
132
    Koha::Libraries->search->count, "GetBranches returns the right number of branches" );
133
133
134
#Test ModBranch
134
#Test ModBranch
135
135
Lines 156-162 $b1 = { Link Here
156
};
156
};
157
157
158
ModBranch($b1);
158
ModBranch($b1);
159
is( GetBranchesCount(), $count + 1,
159
is( Koha::Libraries->search->count, $count + 1,
160
    "A branch has been modified, no new branch added" );
160
    "A branch has been modified, no new branch added" );
161
$branchdetail = GetBranchDetail( $b1->{branchcode} );
161
$branchdetail = GetBranchDetail( $b1->{branchcode} );
162
$b1->{issuing} = undef;
162
$b1->{issuing} = undef;
Lines 211-217 is( Koha::LibraryCategories->search->count, $count_cat + 2, "Category CAT 2 dele Link Here
211
211
212
$b2->{CAT1} = 1;
212
$b2->{CAT1} = 1;
213
ModBranch($b2);
213
ModBranch($b2);
214
is( GetBranchesCount(), $count + 2, 'BRB added' );
214
is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
215
215
216
#Test GetBranchInfo
216
#Test GetBranchInfo
217
my $b1info = GetBranchInfo( $b1->{branchcode} );
217
my $b1info = GetBranchInfo( $b1->{branchcode} );
Lines 297-303 is_deeply( $brCat1, \@b, 'CAT1 has branch BRB and BRC' ); Link Here
297
297
298
#Test GetBranchesLoop
298
#Test GetBranchesLoop
299
my $loop = GetBranchesLoop;
299
my $loop = GetBranchesLoop;
300
is( scalar(@$loop), GetBranchesCount(), 'There is the right number of branches' );
300
is( scalar(@$loop), Koha::Libraries->search->count, 'There is the right number of branches' );
301
301
302
# End transaction
302
# End transaction
303
$dbh->rollback;
303
$dbh->rollback;
304
- 

Return to bug 15295