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

(-)a/Koha/AuthorisedValue.pm (+13 lines)
Lines 158-163 sub _avb_resultset { Link Here
158
    $self->{_avb_resultset};
158
    $self->{_avb_resultset};
159
}
159
}
160
160
161
=head3 GetCatAuthValues
162
$sth = Koha::AuthorisedValue->GetCatAuthValues($dbh);
163
164
This subroutine retrieves and returns all authorised_values (in the authorised_values table where the category=CCODE) in a column named ccode
165
=cut
166
167
sub GetCatAuthValues {
168
    my ($self, $dbh) = @_;
169
    my $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
170
    $sth->execute();
171
    return $sth;
172
}
173
161
=head3 type
174
=head3 type
162
175
163
=cut
176
=cut
(-)a/Koha/ItemType.pm (+15 lines)
Lines 89-94 sub translated_descriptions { Link Here
89
    } @translated_descriptions ];
89
    } @translated_descriptions ];
90
}
90
}
91
91
92
=head3 GetItemTypes
93
my $sth = Koha::ItemType->GetItemTypes($dbh);
94
95
This subroutine retreives and returns all itemtype values in the itemtypes table.
96
97
=cut
98
99
sub GetItemTypes {
100
    my ($self, $dbh) = @_;
101
    my $sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
102
    $sth->execute();
103
    return $sth;
104
}
105
106
92
=head3 type
107
=head3 type
93
108
94
=cut
109
=cut
(-)a/Koha/Libraries.pm (+17 lines)
Lines 52-57 sub search_filtered { Link Here
52
    return $self->SUPER::search( $params, $attributes );
52
    return $self->SUPER::search( $params, $attributes );
53
}
53
}
54
54
55
56
=head3 GetBranchcodes
57
my $sth = Koha::Libraries->GetBranchCodes($dbh);
58
59
This subroutine retrieves and returns all branchcode values in the branches table to the branch_transfer_limits.pl administrative script.
60
61
=cut
62
63
sub GetBranchCodes {
64
    my ($self, $dbh) = @_;
65
    my $query = qq{ SELECT branchcode FROM branches };
66
    my $sth = $dbh->prepare($query);
67
    $sth->execute();
68
    return $sth;
69
}
70
71
55
=head3 type
72
=head3 type
56
73
57
=cut
74
=cut
(-)a/admin/branch_transfer_limits.pl (-8 / +11 lines)
Lines 27-32 use C4::Context; Link Here
27
use C4::Output;
27
use C4::Output;
28
use C4::Koha;
28
use C4::Koha;
29
use C4::Circulation qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit };
29
use C4::Circulation qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit };
30
use Koha::Libraries;
30
31
31
my $input = new CGI;
32
my $input = new CGI;
32
33
Lines 57-73 my @branchcodes; Link Here
57
58
58
my $sth;
59
my $sth;
59
if ( $limitType eq 'ccode' ) {
60
if ( $limitType eq 'ccode' ) {
60
	$sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
61
    $sth = Koha::AuthorisedValue->GetCatAuthValues($dbh);
62
    while ( my $row = $sth->fetchrow_hashref ) {
63
        push( @codes, $row->{ $limitType } );
64
    }
61
} elsif ( $limitType eq 'itemtype' ) {
65
} elsif ( $limitType eq 'itemtype' ) {
62
	$sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
66
    $sth = Koha::ItemType->GetItemTypes($dbh);
63
}
67
    while ( my $row = $sth->fetchrow_hashref ) {
64
$sth->execute();
68
        push( @codes, $row->{ $limitType } );
65
while ( my $row = $sth->fetchrow_hashref ) {
69
    }
66
	push( @codes, $row->{ $limitType } );
67
}
70
}
68
71
69
$sth = $dbh->prepare("SELECT branchcode FROM branches");
72
70
$sth->execute();
73
my $sth = Koha::Libraries->GetBranchCodes($dbh);
71
while ( my $row = $sth->fetchrow_hashref ) {
74
while ( my $row = $sth->fetchrow_hashref ) {
72
	push( @branchcodes, $row->{'branchcode'} );
75
	push( @branchcodes, $row->{'branchcode'} );
73
}
76
}
(-)a/t/db_dependent/AuthorisedValues.t (-2 / +23 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 15;
4
use Test::More tests => 17;
5
5
6
use t::lib::TestBuilder;
6
use t::lib::TestBuilder;
7
7
Lines 23-28 Koha::AuthorisedValueCategories->delete; Link Here
23
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store;
23
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store;
24
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store;
24
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store;
25
Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store;
25
Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store;
26
Koha::AuthorisedValueCategory->new({ category_name => 'CCODE' })->store;
27
26
my $av1 = Koha::AuthorisedValue->new(
28
my $av1 = Koha::AuthorisedValue->new(
27
    {
29
    {
28
        category         => 'av_for_testing',
30
        category         => 'av_for_testing',
Lines 79-84 my $av_0 = Koha::AuthorisedValue->new( Link Here
79
    }
81
    }
80
)->store();
82
)->store();
81
83
84
my $CatAuthValue = Koha::AuthorisedValue->new(
85
   {
86
       category         => 'CCODE',
87
       authorised_value => 'value 5',
88
   }
89
)->store();
90
82
ok( $av1->id(), 'AV 1 is inserted' );
91
ok( $av1->id(), 'AV 1 is inserted' );
83
ok( $av2->id(), 'AV 2 is inserted' );
92
ok( $av2->id(), 'AV 2 is inserted' );
84
ok( $av3->id(), 'AV 3 is inserted' );
93
ok( $av3->id(), 'AV 3 is inserted' );
Lines 114-120 my $limits = $av1->branch_limitations; Link Here
114
is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' );
123
is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' );
115
124
116
my @categories = Koha::AuthorisedValues->new->categories;
125
my @categories = Koha::AuthorisedValues->new->categories;
117
is( @categories, 3, 'There should have 2 categories inserted' );
126
is( @categories, 4, 'There should have 4 categories inserted' );
118
is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' );
127
is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' );
119
is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' );
128
is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' );
120
129
Lines 226-229 subtest 'search_by_*_field + find_by_koha_field + get_description' => sub { Link Here
226
    };
235
    };
227
};
236
};
228
237
238
ok( $CatAuthValue->id(), 'CatAuthValue is inserted' );
239
240
sub GetCatAuthValues {
241
    my $dbh = C4::Context->dbh;
242
    my $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"');
243
    $sth->execute();
244
    return $sth->rows;
245
}
246
247
my $AuthValues = GetCatAuthValues();
248
is($AuthValues, 1, "Correct number of authorised_value's with category=CCODE");
249
229
$schema->storage->txn_rollback;
250
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/ItemTypes.t (-1 / +10 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 20;
22
use Test::More tests => 21;
23
use Data::Dumper;
23
use Data::Dumper;
24
use Koha::Database;
24
use Koha::Database;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 125-129 is( Link Here
125
    'a translated itemtype desc',
125
    'a translated itemtype desc',
126
    'item types should be sorted by translated description'
126
    'item types should be sorted by translated description'
127
);
127
);
128
sub GetItemTypes {
129
    my $dbh = C4::Context->dbh;
130
    my $sth = $dbh->prepare('SELECT itemtype FROM itemtypes');
131
    $sth->execute();
132
    return $sth->rows;
133
}
134
135
my $ItemTypes = GetItemTypes();
136
is($ItemTypes,3, "Correct number of itemtypes");
128
137
129
$schema->txn_rollback;
138
$schema->txn_rollback;
(-)a/t/db_dependent/Koha/Libraries.t (-2 / +12 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 9;
22
use Test::More tests => 10;
23
23
24
use Koha::Library;
24
use Koha::Library;
25
use Koha::Libraries;
25
use Koha::Libraries;
Lines 86-90 is( Koha::Libraries->search->count, $nb_of_libraries + 1, 'Delete should have de Link Here
86
$retrieved_category_2->delete;
86
$retrieved_category_2->delete;
87
is( Koha::LibraryCategories->search->count, $nb_of_categories + 2, 'Delete should have deleted the library category' );
87
is( Koha::LibraryCategories->search->count, $nb_of_categories + 2, 'Delete should have deleted the library category' );
88
88
89
sub GetBranchCodes {
90
    my $dbh = C4::Context->dbh;
91
    my $query = qq{ SELECT branchcode FROM branches };
92
    my $sth = $dbh->prepare($query);
93
    $sth->execute();
94
    return $sth->rows;
95
}
96
97
my $BranchCodes = GetBranchCodes();
98
is($BranchCodes, 13, "Correct number of branchcodes");
99
89
$schema->storage->txn_rollback;
100
$schema->storage->txn_rollback;
90
1;
101
1;
91
- 

Return to bug 18247