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

(-)a/C4/Acquisition.pm (+18 lines)
Lines 2978-2983 sub GetOrderUsers { Link Here
2978
    return @borrowernumbers;
2978
    return @borrowernumbers;
2979
}
2979
}
2980
2980
2981
=head3 GetAuthorisedValues
2982
2983
2984
2985
=cut
2986
2987
sub GetAuthValuesForCategory{
2988
    my ($self, $category) = @_;
2989
    my $schema = Koha::Database->new()->schema();
2990
    my $authvalues = Koha::AuthorisedValues->search({
2991
            'category' => $category,
2992
             order_by => { -asc => 'lib'}
2993
            });
2994
    return $authvalues;
2995
}
2996
2997
2998
2981
=head3 ModOrderUsers
2999
=head3 ModOrderUsers
2982
3000
2983
    my @order_users_ids = (1, 2, 3);
3001
    my @order_users_ids = (1, 2, 3);
(-)a/Koha/AuthorisedValue.pm (+29 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 $sth = Koha::AuthorisedValue->GetAuthValues($authcat,$dbh);
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
166
=cut
167
168
sub GetAuthValues {
169
    my ($self, $authcat, $dbh) = @_;
170
    my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib };
171
    my $sth   = $dbh->prepare($query);
172
    $sth->execute($authcat);
173
    return $sth;
174
}
175
176
=head3 GetDistinctCat
177
my $sth = Koha::AuthorisedValue->GetDistinctCat($dbh);
178
179
This subroutine retrieves and returns all the different category values starting with 'A' in the authorised_values table
180
181
=cut
182
183
sub GetDistinctCat {
184
    my ($self, $dbh) = @_;
185
    my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' ");
186
    $sth->execute;
187
    return $sth;
188
}
189
161
=head3 type
190
=head3 type
162
191
163
=cut
192
=cut
(-)a/Koha/ItemType.pm (+17 lines)
Lines 89-98 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 retrieves and returns all the values for the fields: itemtype and description from the itemtypes table.
96
=cut
97
98
sub GetItemTypes{
99
     my ($self, $dbh) = @_;
100
     my $query = qq| SELECT itemtype, description FROM itemtypes |;
101
     my $sth   = $dbh->prepare($query);
102
     $sth->execute(  );
103
     return $sth;
104
}
105
106
107
92
=head3 type
108
=head3 type
93
109
94
=cut
110
=cut
95
111
112
96
sub _type {
113
sub _type {
97
    return 'Itemtype';
114
    return 'Itemtype';
98
}
115
}
(-)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 (-30 / +22 lines)
Lines 110-117 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 $sth = Koha::AuthorisedValue->GetDistinctCat($dbh);
114
$sth->execute;
115
114
116
# the list
115
# the list
117
my @category_list;
116
my @category_list;
Lines 192-205 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 $sth = Koha::AuthorisedValue->GetAuthValues($authcat,$dbh);
196
    my $sth   = $dbh->prepare($query);
195
197
    $sth->execute($authcat  );
198
    if ( $sth->rows > 0 ) {
196
    if ( $sth->rows > 0 ) {
199
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
197
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
200
            my $results = $sth->fetchrow_hashref;
198
              my $results = $sth->fetchrow_hashref;
201
            push @authvals, $results->{authorised_value};
199
              push @authvals, $results->{authorised_value};
202
            $labels{ $results->{authorised_value} } = $results->{lib};
200
              $labels{ $results->{authorised_value} } = $results->{lib};
203
        }
201
        }
204
    }
202
    }
205
    $sth->finish;
203
    $sth->finish;
Lines 229-265 elsif ( $authcat eq 'MONTHS' && $budget_period_startdate && $budget_period_endda Link Here
229
}
227
}
230
228
231
elsif ( $authcat eq 'ITEMTYPES' ) {
229
elsif ( $authcat eq 'ITEMTYPES' ) {
232
    my $query = qq| SELECT itemtype, description FROM itemtypes |;
233
    my $sth   = $dbh->prepare($query);
234
    $sth->execute(  );
235
230
236
    if ( $sth->rows > 0 ) {
231
   my $sth = Koha::ItemType->GetItemTypes($dbh);
237
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
232
   if ( $sth->rows > 0 ) {
233
      for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
238
            my $results = $sth->fetchrow_hashref;
234
            my $results = $sth->fetchrow_hashref;
239
            push @authvals, $results->{itemtype};
235
            push @authvals, $results->{itemtype};
240
            $labels{ $results->{itemtype} } = $results->{description};
236
           $labels{ $results->{itemtype} } = $results->{description};
241
        }
237
      }
242
    }
238
   }
243
    $sth->finish;
239
   $sth->finish;
244
240
245
} elsif ( $authcat eq 'BRANCHES' ) {
241
} elsif ( $authcat eq 'BRANCHES' ) {
246
242
247
    my $query = qq| SELECT branchcode, branchname FROM branches |;
243
    my $sth = Koha::Libraries->GetBranches($dbh);
248
    my $sth   = $dbh->prepare($query);
249
    $sth->execute();
250
244
251
    if ( $sth->rows > 0 ) {
245
    if ( $sth->rows > 0 ) {
252
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
246
         for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
253
            my $results = $sth->fetchrow_hashref;
247
               my $results = $sth->fetchrow_hashref;
254
            push @authvals, $results->{branchcode};
248
               push @authvals, $results->{branchcode};
255
            $labels{ $results->{branchcode} } = $results->{branchname};
249
               $labels{ $results->{branchcode} } = $results->{branchname};
256
        }
250
         }
257
    }
251
     }
258
    $sth->finish;
259
} elsif ($authcat) {
252
} elsif ($authcat) {
260
    my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib };
253
261
    my $sth   = $dbh->prepare($query);
254
    my $sth = Koha::AuthorisedValue->GetAuthValues($authcat,$dbh);
262
    $sth->execute($authcat);
263
    if ( $sth->rows > 0 ) {
255
    if ( $sth->rows > 0 ) {
264
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
256
        for ( my $i = 0 ; $i < $sth->rows ; $i++ ) {
265
            my $results = $sth->fetchrow_hashref;
257
            my $results = $sth->fetchrow_hashref;
(-)a/t/db_dependent/AuthorisedValues.t (-3 / +34 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 226-229 subtest 'search_by_*_field + find_by_koha_field + get_description' => sub { Link Here
226
    };
226
    };
227
};
227
};
228
228
229
$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;
230
- 

Return to bug 18212