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

(-)a/Koha/AuthorisedValue.pm (-15 / +28 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
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
164
This 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
165
166
=cut
166
=cut
167
167
168
sub GetAuthValues {
168
sub GetAuthValues {
169
    my ($self, $authcat, $dbh) = @_;
169
    my ($self, $authcat) = @_;
170
    my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib };
170
    my @Getauthorised_values =
171
    my $sth   = $dbh->prepare($query);
171
    Koha::AuthorisedValues->new()->search({
172
    $sth->execute($authcat);
172
        category => $authcat,
173
    return $sth;
173
    },
174
}
174
    {
175
        order_by => [qw/ lib /]
176
    });
177
    return @Getauthorised_values;
178
};
179
175
180
176
=head3 GetDistinctCat
181
=head3 GetDistinctCat
177
my $sth = Koha::AuthorisedValue->GetDistinctCat($dbh);
182
my @DistinctAuthValues = Koha::AuthorisedValue->GetDistinctCat();
178
183
179
This subroutine retrieves and returns all the different category values starting with 'A' in the authorised_values table
184
This subroutine retrieves and returns all the different category values starting with 'a' in the authorised_values table
180
185
181
=cut
186
=cut
182
187
183
sub GetDistinctCat {
188
sub GetDistinctCat {
184
    my ($self, $dbh) = @_;
189
      my @distinctauthorised_values =
185
    my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
190
      Koha::AuthorisedValues->new()->search({
186
    $sth->execute;
191
          category => { 'like','%a%'},
187
    return $sth;
192
      });
188
}
193
      return @distinctauthorised_values;
194
};
195
196
197
#    my ($self, $dbh) = @_;
198
#    my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
199
#    $sth->execute;
200
#    return $sth;
201
#}
189
202
190
=head3 type
203
=head3 type
191
204
(-)a/Koha/ItemType.pm (-7 / +7 lines)
Lines 84-98 sub translated_descriptions { Link Here
84
=head3 GetItemTypes
84
=head3 GetItemTypes
85
my $sth = Koha::ItemType->GetItemTypes($dbh);
85
my $sth = Koha::ItemType->GetItemTypes($dbh);
86
86
87
This subroutine retrieves and returns all the values for the fields: itemtype and description from the itemtypes table.
87
This subroutine retrieves and returns all values for the fields: itemtype and description in the itemtypes table.
88
=cut
88
=cut
89
89
90
sub GetItemTypes{
90
sub GetItemTypes {
91
     my ($self, $dbh) = @_;
91
    my ($self, $dbh) = @_;
92
     my $query = qq| SELECT itemtype, description FROM itemtypes |;
92
    my $query = qq| SELECT itemtype, description FROM itemtypes |;
93
     my $sth   = $dbh->prepare($query);
93
    my $sth   = $dbh->prepare($query);
94
     $sth->execute(  );
94
    $sth->execute();
95
     return $sth;
95
    return $sth;
96
}
96
}
97
97
98
98
(-)a/admin/aqplan.pl (-17 / +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;
199
              push @authvals, $results->{authorised_value};
198
              push @authvals, $results->{authorised_value};
200
              $labels{ $results->{authorised_value} } = $results->{lib};
199
              $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' ) {
228
     my $sth = Koha::ItemType->GetItemTypes($dbh);
229
230
     if ( $sth->rows > 0 ) {
231
          for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
232
                my $results = $sth->fetchrow_hashref;
233
                push @authvals, $results->{itemtype};
234
                $labels{ $results->{itemtype} } = $results->{description};
235
          }
236
     }
237
238
230
239
231
   my $sth = Koha::ItemType->GetItemTypes($dbh);
232
   if ( $sth->rows > 0 ) {
233
      for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
234
            my $results = $sth->fetchrow_hashref;
235
            push @authvals, $results->{itemtype};
236
           $labels{ $results->{itemtype} } = $results->{description};
237
      }
238
   }
239
   $sth->finish;
240
240
241
} elsif ( $authcat eq 'BRANCHES' ) {
241
} elsif ( $authcat eq 'BRANCHES' ) {
242
242
(-)a/t/db_dependent/AuthorisedValues.t (-33 / +27 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 => 16;
4
use Test::More tests => 17;
5
5
6
use C4::Context;
6
use C4::Context;
7
use Koha::AuthorisedValue;
7
use Koha::AuthorisedValue;
Lines 20-25 $dbh->do("DELETE FROM authorised_value_categories"); Link Here
20
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store;
20
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store;
21
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store;
21
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store;
22
Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store;
22
Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store;
23
23
my $av1 = Koha::AuthorisedValue->new(
24
my $av1 = Koha::AuthorisedValue->new(
24
    {
25
    {
25
        category         => 'av_for_testing',
26
        category         => 'av_for_testing',
Lines 81-86 ok( $av2->id(), 'AV 2 is inserted' ); Link Here
81
ok( $av3->id(), 'AV 3 is inserted' );
82
ok( $av3->id(), 'AV 3 is inserted' );
82
ok( $av4->id(), 'AV 4 is inserted' );
83
ok( $av4->id(), 'AV 4 is inserted' );
83
84
85
 sub GetAuthValues {
86
    require Test::More;
87
    my @Getauthorised_values =
88
    Koha::AuthorisedValues->new()->search({
89
             category => 'av_for_testing',
90
         },
91
         {
92
             order_by => [qw/ lib /]
93
    });
94
  };
95
  my @Getauthorised_values = GetAuthValues();
96
  is( @Getauthorised_values, 3, "Get correct number of values" );
97
98
  sub GetDistinctCat {
99
        require Test::More;
100
        my @distinctauthorised_values =
101
        Koha::AuthorisedValues->new()->search({
102
                category => { 'like','%a%'},
103
                });
104
  };
105
  my @distinctauthorised_values = GetDistinctCat();
106
  is( @distinctauthorised_values, 4, "Correct number of distinct values" );
107
108
109
84
is( $av3->opac_description, 'opac display value 3', 'Got correction opac description if lib_opac is set' );
110
is( $av3->opac_description, 'opac display value 3', 'Got correction opac description if lib_opac is set' );
85
$av3->lib_opac('');
111
$av3->lib_opac('');
86
is( $av3->opac_description, 'display value 3', 'Got correction opac description if lib_opac is *not* set' );
112
is( $av3->opac_description, 'display value 3', 'Got correction opac description if lib_opac is *not* set' );
Lines 225-262 subtest 'search_by_*_field + find_by_koha_field + get_description' => sub { Link Here
225
        );
251
        );
226
    };
252
    };
227
};
253
};
228
  sub GetAuthValues {
229
       require Test::More; 
230
       my $dbh = C4::Context->dbh;
231
       my ($self, $authcat) = @_;
232
       my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib };
233
       my $sth   = $dbh->prepare($query);
234
       $sth->execute($authcat);
235
       my $AuthValue = 0;
236
       if ($sth->rows > 0) {
237
           $AuthValue = 1;
238
       }
239
       return $AuthValue;
240
   };
241
   my $AuthValues = GetAuthValues('av_for_testing');
242
   is ( $AuthValues,0, 'Does not exist in the database: Test successful');
243
244
    sub GetDistinctCat {
245
        require Test::More;
246
        my $dbh = C4::Context->dbh;
247
        my ($self, $dbh) = @_;
248
        my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
249
        $sth->execute;
250
        return $sth;
251
        my $DistAuth = 0;
252
        if ($sth->rows > 0){
253
            $DistAuth = 1;
254
        }
255
        return $DistAuth;
256
    };
257
    my $DistAuth = GetDistinctCat();
258
    is ( $DistAuth, 0, 'Does not exist in the database successful');
259
260
254
261
255
262
256
(-)a/t/db_dependent/Koha/ItemTypes.t (-1 / +14 lines)
Lines 19-27 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 18;
22
use Test::More tests => 19;
23
use Data::Dumper;
23
use Data::Dumper;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::ItemType;
25
26
26
BEGIN {
27
BEGIN {
27
    use_ok('Koha::ItemType');
28
    use_ok('Koha::ItemType');
Lines 76-79 is( $type->summary, 'summary', 'summary' ); Link Here
76
is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
77
is( $type->checkinmsg,     'checkinmsg',     'checkinmsg' );
77
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
78
is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' );
78
79
80
sub GetItemTypes {
81
   my $dbh = C4::Context->dbh;
82
   my $query =  qq| SELECT itemtype, description FROM itemtypes |;
83
   my $sth   = $dbh->prepare($query);
84
   $sth->execute();
85
   warn $sth->rows;
86
   return $sth->rows;
87
}
88
89
my $ItemTypes = GetItemTypes();
90
is($ItemTypes, 10, "Correct number of item types" );
91
79
$schema->txn_rollback;
92
$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 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