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

(-)a/Koha/Items.pm (-3 / +14 lines)
Lines 65-78 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
    $itemlost_params = { itemlost => 0 }
74
        if C4::Context->preference('hidelostitems');
75
        if C4::Context->preference('hidelostitems');
75
76
77
    my $search_params;
78
    if ( $rules_params and $itemlost_params ) {
79
        $search_params = {
80
            '-and' => [ $rules_params, $itemlost_params ]
81
        };
82
    }
83
    else {
84
        $search_params = $rules_params // $itemlost_params;
85
    }
86
76
    return $self->search( $search_params );
87
    return $self->search( $search_params );
77
}
88
}
78
89
(-)a/t/db_dependent/Koha/Items.t (-4 / +11 lines)
Lines 1366-1372 subtest 'filter_by_visible_in_opac() tests' => sub { Link Here
1366
    my $item_5 = $builder->build_sample_item(
1366
    my $item_5 = $builder->build_sample_item(
1367
        {
1367
        {
1368
            biblionumber => $biblio->biblionumber,
1368
            biblionumber => $biblio->biblionumber,
1369
            itemlost     => undef,
1369
            itemlost     => 0,
1370
            itype        => $itype_1->itemtype,
1371
            withdrawn    => 5
1372
        }
1373
    );
1374
    my $item_6 = $builder->build_sample_item(
1375
        {
1376
            biblionumber => $biblio->biblionumber,
1377
            itemlost     => 2,
1370
            itype        => $itype_1->itemtype,
1378
            itype        => $itype_1->itemtype,
1371
            withdrawn    => 5
1379
            withdrawn    => 5
1372
        }
1380
        }
Lines 1376-1387 subtest 'filter_by_visible_in_opac() tests' => sub { Link Here
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