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

(-)a/Koha/Items.pm (-4 / +16 lines)
Lines 65-77 sub filter_by_visible_in_opac { Link Here
65
65
66
    my $rules = $params->{rules} // {};
66
    my $rules = $params->{rules} // {};
67
67
68
    my $search_params;
68
    my $rules_params;
69
    foreach my $field (keys %$rules){
69
    foreach my $field (keys %$rules){
70
        $search_params->{$field}->{'-not_in'} = $rules->{$field};
70
        $rules_params->{$field}->{'-not_in'} = $rules->{$field};
71
    }
71
    }
72
72
73
    $search_params->{itemlost}->{'<='} = 0
73
    my $itemlost_params;
74
        if C4::Context->preference('hidelostitems');
74
    $itemlost_params = {
75
        itemlost => [ 0, undef, '' ] # things Perl evaluates to false
76
    } if C4::Context->preference('hidelostitems');
77
78
    my $search_params;
79
    if ( $rules_params and $itemlost_params ) {
80
        $search_params = {
81
            '-and' => [ $rules_params, $itemlost_params ]
82
        };
83
    }
84
    else {
85
        $search_params = $rules_params // $itemlost_params;
86
    }
75
87
76
    return $self->search( $search_params );
88
    return $self->search( $search_params );
77
}
89
}
(-)a/t/db_dependent/Koha/Items.t (-3 / +10 lines)
Lines 1371-1387 subtest 'filter_by_visible_in_opac() tests' => sub { Link Here
1371
            withdrawn    => 5
1371
            withdrawn    => 5
1372
        }
1372
        }
1373
    );
1373
    );
1374
    my $item_6 = $builder->build_sample_item(
1375
        {
1376
            biblionumber => $biblio->biblionumber,
1377
            itemlost     => 2,
1378
            itype        => $itype_1->itemtype,
1379
            withdrawn    => 5
1380
        }
1381
    );
1374
1382
1375
    my $rules = {};
1383
    my $rules = {};
1376
1384
1377
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
1385
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
1378
    is( $biblio->items->filter_by_visible_in_opac->count,
1386
    is( $biblio->items->filter_by_visible_in_opac->count,
1379
        5, 'No rules passed, hidelostitems unset' );
1387
        6, 'No rules passed, hidelostitems unset' );
1380
1388
1381
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
1389
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
1382
    is(
1390
    is(
1383
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1391
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1384
        4,
1392
        3,
1385
        'No rules passed, hidelostitems set'
1393
        'No rules passed, hidelostitems set'
1386
    );
1394
    );
1387
1395
1388
- 

Return to bug 24254