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

(-)a/Koha/Items.pm (-4 / +3 lines)
Lines 52-69 sub filter_by_for_loan { Link Here
52
52
53
=head3 filter_by_visible_in_opac
53
=head3 filter_by_visible_in_opac
54
54
55
    my $filered_items = $items->filter_by_visible_in_opac({ rules => $rules });
55
    my $filered_items = $items->filter_by_visible_in_opac;
56
56
57
Returns a new resultset, containing those items that are not expected to be hidden in OPAC.
57
Returns a new resultset, containing those items that are not expected to be hidden in OPAC.
58
If no I<rules> are passed, it returns the whole resultset, with the only caveat that the
58
The I<OpacHiddenItems> and I<hidelostitems> system preferences are honoured.
59
I<hidelostitems> system preference is honoured.
60
59
61
=cut
60
=cut
62
61
63
sub filter_by_visible_in_opac {
62
sub filter_by_visible_in_opac {
64
    my ($self, $params) = @_;
63
    my ($self, $params) = @_;
65
64
66
    my $rules = $params->{rules} // {};
65
    my $rules = C4::Context->yaml_preference('OpacHiddenItems') // {};
67
66
68
    my $rules_params;
67
    my $rules_params;
69
    foreach my $field (keys %$rules){
68
    foreach my $field (keys %$rules){
(-)a/t/db_dependent/Koha/Items.t (-9 / +15 lines)
Lines 1380-1420 subtest 'filter_by_visible_in_opac() tests' => sub { Link Here
1380
        }
1380
        }
1381
    );
1381
    );
1382
1382
1383
    my $rules = {};
1383
    my $rules = undef;
1384
1385
    my $mocked_context = Test::MockModule->new('C4::Context');
1386
    $mocked_context->mock( 'yaml_preference', sub {
1387
        return $rules;
1388
    });
1384
1389
1385
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
1390
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
1386
    is( $biblio->items->filter_by_visible_in_opac->count,
1391
    is( $biblio->items->filter_by_visible_in_opac->count,
1387
        6, 'No rules passed, hidelostitems unset' );
1392
        6, 'No rules passed, hidelostitems unset' );
1388
1393
1394
    $rules = {};
1395
1389
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
1396
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
1390
    is(
1397
    is(
1391
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1398
        $biblio->items->filter_by_visible_in_opac->count,
1392
        3,
1399
        3,
1393
        'No rules passed, hidelostitems set'
1400
        'No rules passed, hidelostitems set'
1394
    );
1401
    );
1395
1402
1396
    $rules = { withdrawn => [ 1, 2 ] };
1403
    $rules = { withdrawn => [ 1, 2 ] };
1397
    is(
1404
    is(
1398
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1405
        $biblio->items->filter_by_visible_in_opac->count,
1399
        2,
1406
        2,
1400
        'Rules on withdrawn, hidelostitems set'
1407
        'Rules on withdrawn, hidelostitems set'
1401
    );
1408
    );
1402
1409
1403
    $rules = { itype => [ $itype_1->itemtype ] };
1410
    $rules = { itype => [ $itype_1->itemtype ] };
1404
    is(
1411
    is(
1405
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1412
        $biblio->items->filter_by_visible_in_opac->count,
1406
        2,
1413
        2,
1407
        'Rules on itype, hidelostitems set'
1414
        'Rules on itype, hidelostitems set'
1408
    );
1415
    );
1409
1416
1410
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] };
1417
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] };
1411
    is(
1418
    is(
1412
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1419
        $biblio->items->filter_by_visible_in_opac->count,
1413
        1,
1420
        1,
1414
        'Rules on itype and withdrawn, hidelostitems set'
1421
        'Rules on itype and withdrawn, hidelostitems set'
1415
    );
1422
    );
1416
    is(
1423
    is(
1417
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )
1424
        $biblio->items->filter_by_visible_in_opac
1418
          ->next->itemnumber,
1425
          ->next->itemnumber,
1419
        $item_4->itemnumber,
1426
        $item_4->itemnumber,
1420
        'The right item is returned'
1427
        'The right item is returned'
Lines 1422-1433 subtest 'filter_by_visible_in_opac() tests' => sub { Link Here
1422
1429
1423
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] };
1430
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] };
1424
    is(
1431
    is(
1425
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1432
        $biblio->items->filter_by_visible_in_opac->count,
1426
        1,
1433
        1,
1427
        'Rules on itype and withdrawn, hidelostitems set'
1434
        'Rules on itype and withdrawn, hidelostitems set'
1428
    );
1435
    );
1429
    is(
1436
    is(
1430
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )
1437
        $biblio->items->filter_by_visible_in_opac
1431
          ->next->itemnumber,
1438
          ->next->itemnumber,
1432
        $item_5->itemnumber,
1439
        $item_5->itemnumber,
1433
        'The right item is returned'
1440
        'The right item is returned'
1434
- 

Return to bug 24254