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

(-)a/C4/Acquisition.pm (+18 lines)
Lines 3040-3045 sub GetOrderUsers { Link Here
3040
    return @borrowernumbers;
3040
    return @borrowernumbers;
3041
}
3041
}
3042
3042
3043
=head3 GetAuthorisedValues
3044
3045
3046
3047
=cut
3048
3049
sub GetAuthValuesForCategory{
3050
    my ($self, $category) = @_;
3051
    my $schema = Koha::Database->new()->schema();
3052
    my $authvalues = Koha::AuthorisedValues->search({
3053
            'category' => $category,
3054
             order_by => { -asc => 'lib'}
3055
            });
3056
    return $authvalues;
3057
}
3058
3059
3060
3043
=head3 ModOrderUsers
3061
=head3 ModOrderUsers
3044
3062
3045
    my @order_users_ids = (1, 2, 3);
3063
    my @order_users_ids = (1, 2, 3);
(-)a/Koha/AuthorisedValue.pm (+32 lines)
Lines 158-163 sub _avb_resultset { Link Here
158
    $self->{_avb_resultset};
158
    $self->{_avb_resultset};
159
}
159
}
160
160
161
=head3 GetAuthValues
162
my @AuthValues = Koha::AuthorisedValue->GetAuthValues($authcat);
163
164
s subroutine retrieves and returns all fields from the authorised_values table where the category is equal to the parameter $authcat, and orders the records by the value of the lib field
165
=cut
166
167
sub GetAuthValues {
168
    my ($self, $authcat) = @_;
169
    my @Getauthorised_values =
170
    Koha::AuthorisedValues->new()->search({
171
         category => $authcat,
172
    },
173
    {
174
         order_by => [qw/ lib /]
175
    });
176
    return @Getauthorised_values;
177
};
178
179
=head3 GetDistinctCat
180
my @DistinctAuthValues = Koha::AuthorisedValue->GetDistinctCat();
181
182
This subroutine retrieves and returns all the different category values starting with 'a' in the authorised_values table
183
=cut
184
185
sub GetDistinctCat {
186
    my @distinctauthorised_values =
187
    Koha::AuthorisedValues->new()->search({
188
             category => { 'like','%a%'},
189
     });
190
    return @distinctauthorised_values;
191
};
192
161
=head3 type
193
=head3 type
162
194
163
=cut
195
=cut
(-)a/Koha/ItemType.pm (-2 / +15 lines)
Lines 89-96 sub translated_descriptions { Link Here
89
    } @translated_descriptions ];
89
    } @translated_descriptions ];
90
}
90
}
91
91
92
93
94
=head3 can_be_deleted
92
=head3 can_be_deleted
95
93
96
my $can_be_deleted = Koha::ItemType->can_be_deleted();
94
my $can_be_deleted = Koha::ItemType->can_be_deleted();
Lines 106-115 sub can_be_deleted { Link Here
106
    return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
104
    return $nb_items + $nb_biblioitems == 0 ? 1 : 0;
107
}
105
}
108
106
107
=head3 GetItemTypes
108
my $sth = Koha::ItemType->GetItemTypes($dbh);
109
110
This subroutine retrieves and returns all the values for the fields: itemtype and description from the itemtypes table.
111
=cut
112
113
sub GetItemTypes{
114
     my ($self, $dbh) = @_;
115
     my $query = qq| SELECT itemtype, description FROM itemtypes |;
116
     my $sth   = $dbh->prepare($query);
117
     $sth->execute();
118
     return $sth;
119
}
120
109
=head3 type
121
=head3 type
110
122
111
=cut
123
=cut
112
124
125
113
sub _type {
126
sub _type {
114
    return 'Itemtype';
127
    return 'Itemtype';
115
}
128
}
(-)a/Koha/Libraries.pm (+15 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
=head3
56
my $sth = Koha::Libraries->GetBranches($dbh);
57
58
This subroutine retrieves and returns all the values for the fields: branchcode and branchname from the branches table.
59
60
=cut
61
62
sub GetBranches {
63
    my ($self, $dbh) = @_;
64
    my $query = qq| SELECT branchcode, branchname FROM branches |;
65
    my $sth   = $dbh->prepare($query);
66
    $sth->execute();
67
    return $sth;
68
}
69
55
=head3 type
70
=head3 type
56
71
57
=cut
72
=cut
(-)a/admin/aqplan.pl (-34 / +23 lines)
Lines 110-124 my $op = $input->param("op"); Link Here
110
my $budgets_ref = GetBudgetHierarchy( $budget_period_id, $show_mine?$template->{VARS}->{'USER_INFO'}->{'branchcode'}:'', $show_mine?$template->{VARS}->{'USER_INFO'}->{'borrowernumber'}:'' );
110
my $budgets_ref = GetBudgetHierarchy( $budget_period_id, $show_mine?$template->{VARS}->{'USER_INFO'}->{'branchcode'}:'', $show_mine?$template->{VARS}->{'USER_INFO'}->{'borrowernumber'}:'' );
111
111
112
# build categories list
112
# build categories list
113
my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
113
my @DistinctAuthValues = Koha::AuthorisedValue->GetDistinctCat();
114
$sth->execute;
115
114
116
# the list
115
# the list
117
my @category_list;
116
my @category_list;
118
117
119
# a hash, to check that some hardcoded categories exist.
118
# a hash, to check that some hardcoded categories exist.
120
my %categories;
119
my %categories;
121
while ( my ($category) = $sth->fetchrow_array ) {
120
while ( my ($category) = each @DistinctAuthValues ) {
122
    push( @category_list, $category );
121
    push( @category_list, $category );
123
    $categories{$category} = 1;
122
    $categories{$category} = 1;
124
}
123
}
Lines 192-208 HideCols($authcat, @hide_cols); Link Here
192
}
191
}
193
# ------------------------------------------------------------
192
# ------------------------------------------------------------
194
if ( $authcat =~ m/^Asort/ ) {
193
if ( $authcat =~ m/^Asort/ ) {
195
   my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib };
194
    my @AuthValues = Koha::AuthorisedValue->GetAuthValues($authcat);
196
    my $sth   = $dbh->prepare($query);
195
    if ( @AuthValues > 0 ) {
197
    $sth->execute($authcat  );
196
        while ( my ($AuthValue) = each @AuthValues) {
198
    if ( $sth->rows > 0 ) {
197
            my $results = $AuthValue;
199
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
200
            my $results = $sth->fetchrow_hashref;
201
            push @authvals, $results->{authorised_value};
198
            push @authvals, $results->{authorised_value};
202
            $labels{ $results->{authorised_value} } = $results->{lib};
199
            $labels{ $results->{authorised_value} } = $results->{lib};
203
        }
200
        }
204
    }
201
    }
205
    $sth->finish;
206
    @authvals = sort { $a <=> $b } @authvals;
202
    @authvals = sort { $a <=> $b } @authvals;
207
}
203
}
208
elsif ( $authcat eq 'MONTHS' && $budget_period_startdate && $budget_period_enddate ) {
204
elsif ( $authcat eq 'MONTHS' && $budget_period_startdate && $budget_period_enddate ) {
Lines 229-265 elsif ( $authcat eq 'MONTHS' && $budget_period_startdate && $budget_period_endda Link Here
229
}
225
}
230
226
231
elsif ( $authcat eq 'ITEMTYPES' ) {
227
elsif ( $authcat eq 'ITEMTYPES' ) {
232
    my $query = qq| SELECT itemtype, description FROM itemtypes |;
228
     my $sth = Koha::ItemType->GetItemTypes($dbh);
233
    my $sth   = $dbh->prepare($query);
234
    $sth->execute(  );
235
229
236
    if ( $sth->rows > 0 ) {
230
      if ( $sth->rows > 0 ) {
237
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
231
            for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
238
            my $results = $sth->fetchrow_hashref;
232
                 my $results = $sth->fetchrow_hashref;
239
            push @authvals, $results->{itemtype};
233
                 push @authvals, $results->{itemtype};
240
            $labels{ $results->{itemtype} } = $results->{description};
234
                 $labels{ $results->{itemtype} } = $results->{description};
241
        }
235
            }
242
    }
236
       }
243
    $sth->finish;
244
237
245
} elsif ( $authcat eq 'BRANCHES' ) {
238
} elsif ( $authcat eq 'BRANCHES' ) {
246
239
247
    my $query = qq| SELECT branchcode, branchname FROM branches |;
240
    my $sth = Koha::Libraries->GetBranches($dbh);
248
    my $sth   = $dbh->prepare($query);
249
    $sth->execute();
250
241
251
    if ( $sth->rows > 0 ) {
242
    if ( $sth->rows > 0 ) {
252
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
243
         for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
253
            my $results = $sth->fetchrow_hashref;
244
               my $results = $sth->fetchrow_hashref;
254
            push @authvals, $results->{branchcode};
245
               push @authvals, $results->{branchcode};
255
            $labels{ $results->{branchcode} } = $results->{branchname};
246
               $labels{ $results->{branchcode} } = $results->{branchname};
256
        }
247
         }
257
    }
248
     }
258
    $sth->finish;
259
} elsif ($authcat) {
249
} elsif ($authcat) {
260
    my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib };
250
261
    my $sth   = $dbh->prepare($query);
251
    my $sth = Koha::AuthorisedValue->GetAuthValues($authcat,$dbh);
262
    $sth->execute($authcat);
263
    if ( $sth->rows > 0 ) {
252
    if ( $sth->rows > 0 ) {
264
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
253
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
265
            my $results = $sth->fetchrow_hashref;
254
            my $results = $sth->fetchrow_hashref;
(-)a/t/db_dependent/AuthorisedValues.t (-2 / +26 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 92-97 my @authorised_values = Link Here
92
  Koha::AuthorisedValues->new()->search( { category => 'av_for_testing' } );
92
  Koha::AuthorisedValues->new()->search( { category => 'av_for_testing' } );
93
is( @authorised_values, 3, "Get correct number of values" );
93
is( @authorised_values, 3, "Get correct number of values" );
94
94
95
sub GetAuthValues {
96
   require Test::More;
97
   my @Getauthorised_values = Koha::AuthorisedValues->new()->search({
98
        category => 'av_for_testing',
99
   },
100
   {
101
        order_by => [qw/ lib /]
102
   });
103
};
104
105
my @Getauthorised_values = GetAuthValues();
106
is( @Getauthorised_values, 3, "Get correct number of values" );
107
108
sub GetDistinctCat {
109
   require Test::More;
110
   my @distinctauthorised_values =
111
   Koha::AuthorisedValues->new()->search({
112
      category => { 'like','%a%'},
113
   });
114
}
115
116
my @distinctauthorised_values = GetDistinctCat();
117
is( @distinctauthorised_values, 4, "Correct number of distinct values" );
118
119
95
my $branchcode1 = $builder->build({ source => 'Branch' })->{branchcode};
120
my $branchcode1 = $builder->build({ source => 'Branch' })->{branchcode};
96
my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode};
121
my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode};
97
122
Lines 227-231 subtest 'search_by_*_field + find_by_koha_field + get_description' => sub { Link Here
227
        );
252
        );
228
    };
253
    };
229
};
254
};
230
231
$schema->storage->txn_rollback;
255
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/ItemTypes.t (+13 lines)
Lines 26-31 use t::lib::Mocks; Link Here
26
use Koha::Items;
26
use Koha::Items;
27
use Koha::Biblioitems;
27
use Koha::Biblioitems;
28
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
29
use Koha::ItemType;
29
30
30
BEGIN {
31
BEGIN {
31
    use_ok('Koha::ItemType');
32
    use_ok('Koha::ItemType');
Lines 118-123 is( $type->summary, 'summary', 'summary' ); Link Here
118
is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
119
is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
119
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
120
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
120
121
122
123
sub GetItemTypes {
124
    my $dbh = C4::Context->dbh;
125
    my $query =  qq| SELECT itemtype, description FROM itemtypes |;
126
    my $sth   = $dbh->prepare($query);
127
    $sth->execute();
128
    return $sth->rows;
129
}
130
131
my $ItemTypes = GetItemTypes();
132
is($ItemTypes, 3, "Correct number of item types" );
133
121
t::lib::Mocks::mock_preference('language', 'en');
134
t::lib::Mocks::mock_preference('language', 'en');
122
t::lib::Mocks::mock_preference('opaclanguages', 'en');
135
t::lib::Mocks::mock_preference('opaclanguages', 'en');
123
my $itemtypes = Koha::ItemTypes->search_with_localization;
136
my $itemtypes = Koha::ItemTypes->search_with_localization;
(-)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-89 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 GetBranches {
90
    my $dbh = C4::Context->dbh;
91
    my $query = qq| SELECT branchcode, branchname FROM branches |;
92
    my $sth   = $dbh->prepare($query);
93
    $sth->execute();
94
    return $sth->rows;
95
}
96
97
my $branches = GetBranches();
98
is($branches, 13, "correcct number of branches" );
99
89
$schema->storage->txn_rollback;
100
$schema->storage->txn_rollback;
90
- 

Return to bug 18212