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

(-)a/Koha/Items.pm (-3 / +14 lines)
Lines 52-65 sub filter_by_visible_in_opac { Link Here
52
52
53
    my $rules = $params->{rules} // {};
53
    my $rules = $params->{rules} // {};
54
54
55
    my $search_params;
55
    my $rules_params;
56
    foreach my $field (keys %$rules){
56
    foreach my $field (keys %$rules){
57
        $search_params->{$field}->{'-not_in'} = $rules->{$field};
57
        $rules_params->{$field}->{'-not_in'} = $rules->{$field};
58
    }
58
    }
59
59
60
    $search_params->{itemlost}->{'<='} = 0
60
    my $itemlost_params;
61
    $itemlost_params = { itemlost => 0 }
61
        if C4::Context->preference('hidelostitems');
62
        if C4::Context->preference('hidelostitems');
62
63
64
    my $search_params;
65
    if ( $rules_params and $itemlost_params ) {
66
        $search_params = {
67
            '-and' => [ $rules_params, $itemlost_params ]
68
        };
69
    }
70
    else {
71
        $search_params = $rules_params // $itemlost_params;
72
    }
73
63
    return $self->search( $search_params );
74
    return $self->search( $search_params );
64
}
75
}
65
76
(-)a/t/db_dependent/Koha/Items.t (-4 / +11 lines)
Lines 289-295 subtest 'filter_by_visible_in_opac() tests' => sub { Link Here
289
    my $item_5 = $builder->build_sample_item(
289
    my $item_5 = $builder->build_sample_item(
290
        {
290
        {
291
            biblionumber => $biblio->biblionumber,
291
            biblionumber => $biblio->biblionumber,
292
            itemlost     => undef,
292
            itemlost     => 0,
293
            itype        => $itype_1->itemtype,
294
            withdrawn    => 5
295
        }
296
    );
297
    my $item_6 = $builder->build_sample_item(
298
        {
299
            biblionumber => $biblio->biblionumber,
300
            itemlost     => 2,
293
            itype        => $itype_1->itemtype,
301
            itype        => $itype_1->itemtype,
294
            withdrawn    => 5
302
            withdrawn    => 5
295
        }
303
        }
Lines 299-310 subtest 'filter_by_visible_in_opac() tests' => sub { Link Here
299
307
300
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
308
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
301
    is( $biblio->items->filter_by_visible_in_opac->count,
309
    is( $biblio->items->filter_by_visible_in_opac->count,
302
        5, 'No rules passed, hidelostitems unset' );
310
        6, 'No rules passed, hidelostitems unset' );
303
311
304
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
312
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
305
    is(
313
    is(
306
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
314
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
307
        4,
315
        3,
308
        'No rules passed, hidelostitems set'
316
        'No rules passed, hidelostitems set'
309
    );
317
    );
310
318
311
- 

Return to bug 24254