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

(-)a/C4/Koha.pm (-19 / +1 lines)
Lines 42-48 BEGIN { Link Here
42
	@EXPORT = qw(
42
	@EXPORT = qw(
43
        &GetPrinters &GetPrinter
43
        &GetPrinters &GetPrinter
44
        &GetItemTypes &getitemtypeinfo
44
        &GetItemTypes &getitemtypeinfo
45
                &GetItemTypesCategorized &GetItemTypesByCategory
45
        &GetItemTypesCategorized
46
        &getallthemes
46
        &getallthemes
47
        &getFacets
47
        &getFacets
48
        &getnbpages
48
        &getnbpages
Lines 207-230 sub GetItemTypesCategorized { Link Here
207
return ($dbh->selectall_hashref($query,'itemtype'));
207
return ($dbh->selectall_hashref($query,'itemtype'));
208
}
208
}
209
209
210
=head2 GetItemTypesByCategory
211
212
    @results = GetItemTypesByCategory( $searchcategory );
213
214
Returns the itemtype code of all itemtypes included in a searchcategory.
215
216
=cut
217
218
sub GetItemTypesByCategory {
219
    my ($category) = @_;
220
    my $count = 0;
221
    my @results;
222
    my $dbh = C4::Context->dbh;
223
    my $query = qq|SELECT itemtype FROM itemtypes WHERE searchcategory=?|;
224
    my $tmp=$dbh->selectcol_arrayref($query,undef,$category);
225
    return @$tmp;
226
}
227
228
=head2 getitemtypeinfo
210
=head2 getitemtypeinfo
229
211
230
  $itemtype = &getitemtypeinfo($itemtype, [$interface]);
212
  $itemtype = &getitemtypeinfo($itemtype, [$interface]);
(-)a/opac/opac-search.pl (-1 / +2 lines)
Lines 479-485 my %is_nolimit = map { $_ => 1 } @nolimits; Link Here
479
if (@searchCategories > 0) {
479
if (@searchCategories > 0) {
480
    my @tabcat;
480
    my @tabcat;
481
    foreach my $typecategory (@searchCategories) {
481
    foreach my $typecategory (@searchCategories) {
482
        push (@tabcat, GetItemTypesByCategory($typecategory));
482
        my @itemtypes = Koha::ItemTypes->search({ searchcategory => $typecategory });
483
        push @tabcat, $_->itemtype for @itemtypes;
483
    }
484
    }
484
485
485
    foreach my $itemtypeInCategory (@tabcat) {
486
    foreach my $itemtypeInCategory (@tabcat) {
(-)a/t/db_dependent/Koha.t (-8 / +8 lines)
Lines 13-19 use Test::More tests => 8; Link Here
13
use DateTime::Format::MySQL;
13
use DateTime::Format::MySQL;
14
14
15
BEGIN {
15
BEGIN {
16
    use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote GetItemTypesByCategory GetItemTypesCategorized));
16
    use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote GetItemTypesCategorized));
17
    use_ok('C4::Members');
17
    use_ok('C4::Members');
18
}
18
}
19
19
Lines 239-245 subtest 'ISBN tests' => sub { Link Here
239
239
240
};
240
};
241
241
242
subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{
242
subtest 'GetItemTypesCategorized test' => sub{
243
    plan tests => 7;
243
    plan tests => 7;
244
244
245
    my $avc = Koha::AuthorisedValueCategories->find('ITEMTYPECAT');
245
    my $avc = Koha::AuthorisedValueCategories->find('ITEMTYPECAT');
Lines 259-270 subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{ Link Here
259
    $insertSth->execute('BKghjklo3', 'Yet another type of book', 'Qwertyware', 0);
259
    $insertSth->execute('BKghjklo3', 'Yet another type of book', 'Qwertyware', 0);
260
260
261
    # Azertyware should not exist.
261
    # Azertyware should not exist.
262
    my @results = GetItemTypesByCategory('Azertyware');
262
    my @itemtypes = Koha::ItemTypes->search({ searchcategory => 'Azertyware' });
263
    is(scalar @results, 0, 'GetItemTypesByCategory: Invalid category returns nothing');
263
    is( @itemtypes, 0, 'Search item types by searchcategory: Invalid category returns nothing');
264
264
265
    @results = GetItemTypesByCategory('Qwertyware');
265
    @itemtypes = Koha::ItemTypes->search({ searchcategory => 'Qwertyware' });
266
    my @got = map { $_->itemtype } @itemtypes;
266
    my @expected = ( 'BKghjklo2', 'BKghjklo3' );
267
    my @expected = ( 'BKghjklo2', 'BKghjklo3' );
267
    is_deeply(\@results,\@expected,'GetItemTypesByCategory: valid category returns itemtypes');
268
    is_deeply(\@got,\@expected,'Search item types by searchcategory: valid category returns itemtypes');
268
269
269
    # add more data since GetItemTypesCategorized's search is more subtle
270
    # add more data since GetItemTypesCategorized's search is more subtle
270
    $insertGroup = Koha::AuthorisedValue->new(
271
    $insertGroup = Koha::AuthorisedValue->new(
Lines 285-291 subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{ Link Here
285
    ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: partially visible category exists');
286
    ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: partially visible category exists');
286
287
287
    my @only = ( 'BKghjklo1', 'BKghjklo2', 'BKghjklo3', 'BKghjklo4', 'BKghjklo5', 'Qwertyware', 'Veryheavybook' );
288
    my @only = ( 'BKghjklo1', 'BKghjklo2', 'BKghjklo3', 'BKghjklo4', 'BKghjklo5', 'Qwertyware', 'Veryheavybook' );
288
    @results = ();
289
    my @results = ();
289
    foreach my $key (@only) {
290
    foreach my $key (@only) {
290
        push @results, $key if exists $hrCat->{$key};
291
        push @results, $key if exists $hrCat->{$key};
291
    }
292
    }
292
- 

Return to bug 17627