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

(-)a/Koha/AuthorisedValue.pm (-17 / +20 lines)
Lines 159-191 sub _avb_resultset { Link Here
159
}
159
}
160
160
161
=head3 GetAuthValues
161
=head3 GetAuthValues
162
my $sth = Koha::AuthorisedValue->GetAuthValues($authcat,$dbh);
162
my @AuthValues = Koha::AuthorisedValue->GetAuthValues($authcat);
163
164
This subroutine retrieves and returns all fields from the authorised_values table where the category is equal to the parameter $authcat, and orders therecords by the value of the lib field
165
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
166
=cut
165
=cut
167
166
168
sub GetAuthValues {
167
sub GetAuthValues {
169
    my ($self, $authcat, $dbh) = @_;
168
    my ($self, $authcat) = @_;
170
    my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib };
169
    my @Getauthorised_values =
171
    my $sth   = $dbh->prepare($query);
170
    Koha::AuthorisedValues->new()->search({
172
    $sth->execute($authcat);
171
         category => $authcat,
173
    return $sth;
172
    },
174
}
173
    {
174
         order_by => [qw/ lib /]
175
    });
176
    return @Getauthorised_values;
177
};
175
178
176
=head3 GetDistinctCat
179
=head3 GetDistinctCat
177
my $sth = Koha::AuthorisedValue->GetDistinctCat($dbh);
180
my @DistinctAuthValues = Koha::AuthorisedValue->GetDistinctCat();
178
179
This subroutine retrieves and returns all the different category values starting with 'A' in the authorised_values table
180
181
182
This subroutine retrieves and returns all the different category values starting with 'a' in the authorised_values table
181
=cut
183
=cut
182
184
183
sub GetDistinctCat {
185
sub GetDistinctCat {
184
    my ($self, $dbh) = @_;
186
    my @distinctauthorised_values =
185
    my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
187
    Koha::AuthorisedValues->new()->search({
186
    $sth->execute;
188
             category => { 'like','%a%'},
187
    return $sth;
189
     });
188
}
190
    return @distinctauthorised_values;
191
};
189
192
190
=head3 type
193
=head3 type
191
194
(-)a/Koha/ItemType.pm (-2 / +2 lines)
Lines 92-105 sub translated_descriptions { Link Here
92
=head3 GetItemTypes
92
=head3 GetItemTypes
93
my $sth = Koha::ItemType->GetItemTypes($dbh);
93
my $sth = Koha::ItemType->GetItemTypes($dbh);
94
94
95
This subroutine retrieves and returns all the values for the fields: itemtype and description from the itemtypes table.
95
This subroutine retrieves and returns all values for the fields: itemtype and description in the itemtypes table.
96
=cut
96
=cut
97
97
98
sub GetItemTypes{
98
sub GetItemTypes{
99
     my ($self, $dbh) = @_;
99
     my ($self, $dbh) = @_;
100
     my $query = qq| SELECT itemtype, description FROM itemtypes |;
100
     my $query = qq| SELECT itemtype, description FROM itemtypes |;
101
     my $sth   = $dbh->prepare($query);
101
     my $sth   = $dbh->prepare($query);
102
     $sth->execute(  );
102
     $sth->execute();
103
     return $sth;
103
     return $sth;
104
}
104
}
105
105
(-)a/admin/aqplan.pl (-20 / +17 lines)
Lines 110-123 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 = Koha::AuthorisedValue->GetDistinctCat($dbh);
113
my @DistinctAuthValues = Koha::AuthorisedValue->GetDistinctCat();
114
114
115
# the list
115
# the list
116
my @category_list;
116
my @category_list;
117
117
118
# a hash, to check that some hardcoded categories exist.
118
# a hash, to check that some hardcoded categories exist.
119
my %categories;
119
my %categories;
120
while ( my ($category) = $sth->fetchrow_array ) {
120
while ( my ($category) = each @DistinctAuthValues ) {
121
    push( @category_list, $category );
121
    push( @category_list, $category );
122
    $categories{$category} = 1;
122
    $categories{$category} = 1;
123
}
123
}
Lines 191-206 HideCols($authcat, @hide_cols); Link Here
191
}
191
}
192
# ------------------------------------------------------------
192
# ------------------------------------------------------------
193
if ( $authcat =~ m/^Asort/ ) {
193
if ( $authcat =~ m/^Asort/ ) {
194
    my $sth = Koha::AuthorisedValue->GetAuthValues($authcat,$dbh);
194
    my @AuthValues = Koha::AuthorisedValue->GetAuthValues($authcat);
195
195
    if ( @AuthValues > 0 ) {
196
    if ( $sth->rows > 0 ) {
196
        while ( my ($AuthValue) = each @AuthValues) {
197
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
197
            my $results = $AuthValue;
198
              my $results = $sth->fetchrow_hashref;
198
            push @authvals, $results->{authorised_value};
199
              push @authvals, $results->{authorised_value};
199
            $labels{ $results->{authorised_value} } = $results->{lib};
200
              $labels{ $results->{authorised_value} } = $results->{lib};
201
        }
200
        }
202
    }
201
    }
203
    $sth->finish;
204
    @authvals = sort { $a <=> $b } @authvals;
202
    @authvals = sort { $a <=> $b } @authvals;
205
}
203
}
206
elsif ( $authcat eq 'MONTHS' && $budget_period_startdate && $budget_period_enddate ) {
204
elsif ( $authcat eq 'MONTHS' && $budget_period_startdate && $budget_period_enddate ) {
Lines 227-242 elsif ( $authcat eq 'MONTHS' && $budget_period_startdate && $budget_period_endda Link Here
227
}
225
}
228
226
229
elsif ( $authcat eq 'ITEMTYPES' ) {
227
elsif ( $authcat eq 'ITEMTYPES' ) {
230
228
     my $sth = Koha::ItemType->GetItemTypes($dbh);
231
   my $sth = Koha::ItemType->GetItemTypes($dbh);
229
232
   if ( $sth->rows > 0 ) {
230
      if ( $sth->rows > 0 ) {
233
      for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
231
            for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
234
            my $results = $sth->fetchrow_hashref;
232
                 my $results = $sth->fetchrow_hashref;
235
            push @authvals, $results->{itemtype};
233
                 push @authvals, $results->{itemtype};
236
           $labels{ $results->{itemtype} } = $results->{description};
234
                 $labels{ $results->{itemtype} } = $results->{description};
237
      }
235
            }
238
   }
236
       }
239
   $sth->finish;
240
237
241
} elsif ( $authcat eq 'BRANCHES' ) {
238
} elsif ( $authcat eq 'BRANCHES' ) {
242
239
(-)a/t/db_dependent/AuthorisedValues.t (-34 / +26 lines)
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 225-261 subtest 'search_by_*_field + find_by_koha_field + get_description' => sub { Link Here
225
        );
250
        );
226
    };
251
    };
227
};
252
};
228
253
$schema->storage->txn_rollback;
229
  sub GetAuthValues {
230
       require Test::More;
231
       my $dbh = C4::Context->dbh;
232
       my ($self, $authcat) = @_;
233
       my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib };
234
       my $sth   = $dbh->prepare($query);
235
       $sth->execute($authcat);
236
       my $AuthValue = 0;
237
       if ($sth->rows > 0) {
238
           $AuthValue = 1;
239
       }
240
       return $AuthValue;
241
   };
242
   my $AuthValues = GetAuthValues('av_for_testing');
243
   is ( $AuthValues,0, 'Does not exist in the database: Test successful');
244
245
    sub GetDistinctCat {
246
        require Test::More;
247
        my $dbh = C4::Context->dbh;
248
        my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
249
        $sth->execute;
250
        my $DistAuth = 0;
251
        warn $sth->rows;
252
        if ($sth->rows == 3){
253
            $DistAuth = 1;
254
        }
255
        warn return $DistAuth;
256
    };
257
    my $DistAuth = GetDistinctCat();
258
    is ( $DistAuth, 1, '3 Distict categories with a name starting with a exist in the database');
259
260
261
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/ItemTypes.t (-1 / +14 lines)
Lines 19-28 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;
26
use Koha::ItemType;
26
27
27
BEGIN {
28
BEGIN {
28
    use_ok('Koha::ItemType');
29
    use_ok('Koha::ItemType');
Lines 115-120 is( $type->summary, 'summary', 'summary' ); Link Here
115
is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
116
is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
116
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
117
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
117
118
119
120
sub GetItemTypes {
121
    my $dbh = C4::Context->dbh;
122
    my $query =  qq| SELECT itemtype, description FROM itemtypes |;
123
    my $sth   = $dbh->prepare($query);
124
    $sth->execute();
125
    return $sth->rows;
126
}
127
128
my $ItemTypes = GetItemTypes();
129
is($ItemTypes, 3, "Correct number of item types" );
130
118
t::lib::Mocks::mock_preference('language', 'en');
131
t::lib::Mocks::mock_preference('language', 'en');
119
t::lib::Mocks::mock_preference('opaclanguages', 'en');
132
t::lib::Mocks::mock_preference('opaclanguages', 'en');
120
my $itemtypes = Koha::ItemTypes->search_with_localization;
133
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-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 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
1;
101
1;
91
- 

Return to bug 18212