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

(-)a/Koha/Items.pm (-4 / +3 lines)
Lines 39-56 Koha::Items - Koha Item object set class Link Here
39
39
40
=head3 filter_by_visible_in_opac
40
=head3 filter_by_visible_in_opac
41
41
42
    my $filered_items = $items->filter_by_visible_in_opac({ rules => $rules });
42
    my $filered_items = $items->filter_by_visible_in_opac;
43
43
44
Returns a new resultset, containing those items that are not expected to be hidden in OPAC.
44
Returns a new resultset, containing those items that are not expected to be hidden in OPAC.
45
If no I<rules> are passed, it returns the whole resultset, with the only caveat that the
45
The I<OpacHiddenItems> and I<hidelostitems> system preferences are honoured.
46
I<hidelostitems> system preference is honoured.
47
46
48
=cut
47
=cut
49
48
50
sub filter_by_visible_in_opac {
49
sub filter_by_visible_in_opac {
51
    my ($self, $params) = @_;
50
    my ($self, $params) = @_;
52
51
53
    my $rules = $params->{rules} // {};
52
    my $rules = C4::Context->yaml_preference('OpacHiddenItems') // {};
54
53
55
    my $rules_params;
54
    my $rules_params;
56
    foreach my $field (keys %$rules){
55
    foreach my $field (keys %$rules){
(-)a/t/db_dependent/Koha/Items.t (-9 / +15 lines)
Lines 303-343 subtest 'filter_by_visible_in_opac() tests' => sub { Link Here
303
        }
303
        }
304
    );
304
    );
305
305
306
    my $rules = {};
306
    my $rules = undef;
307
308
    my $mocked_context = Test::MockModule->new('C4::Context');
309
    $mocked_context->mock( 'yaml_preference', sub {
310
        return $rules;
311
    });
307
312
308
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
313
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
309
    is( $biblio->items->filter_by_visible_in_opac->count,
314
    is( $biblio->items->filter_by_visible_in_opac->count,
310
        6, 'No rules passed, hidelostitems unset' );
315
        6, 'No rules passed, hidelostitems unset' );
311
316
317
    $rules = {};
318
312
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
319
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
313
    is(
320
    is(
314
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
321
        $biblio->items->filter_by_visible_in_opac->count,
315
        3,
322
        3,
316
        'No rules passed, hidelostitems set'
323
        'No rules passed, hidelostitems set'
317
    );
324
    );
318
325
319
    $rules = { withdrawn => [ 1, 2 ] };
326
    $rules = { withdrawn => [ 1, 2 ] };
320
    is(
327
    is(
321
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
328
        $biblio->items->filter_by_visible_in_opac->count,
322
        2,
329
        2,
323
        'Rules on withdrawn, hidelostitems set'
330
        'Rules on withdrawn, hidelostitems set'
324
    );
331
    );
325
332
326
    $rules = { itype => [ $itype_1->itemtype ] };
333
    $rules = { itype => [ $itype_1->itemtype ] };
327
    is(
334
    is(
328
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
335
        $biblio->items->filter_by_visible_in_opac->count,
329
        2,
336
        2,
330
        'Rules on itype, hidelostitems set'
337
        'Rules on itype, hidelostitems set'
331
    );
338
    );
332
339
333
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] };
340
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] };
334
    is(
341
    is(
335
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
342
        $biblio->items->filter_by_visible_in_opac->count,
336
        1,
343
        1,
337
        'Rules on itype and withdrawn, hidelostitems set'
344
        'Rules on itype and withdrawn, hidelostitems set'
338
    );
345
    );
339
    is(
346
    is(
340
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )
347
        $biblio->items->filter_by_visible_in_opac
341
          ->next->itemnumber,
348
          ->next->itemnumber,
342
        $item_4->itemnumber,
349
        $item_4->itemnumber,
343
        'The right item is returned'
350
        'The right item is returned'
Lines 345-356 subtest 'filter_by_visible_in_opac() tests' => sub { Link Here
345
352
346
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] };
353
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] };
347
    is(
354
    is(
348
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
355
        $biblio->items->filter_by_visible_in_opac->count,
349
        1,
356
        1,
350
        'Rules on itype and withdrawn, hidelostitems set'
357
        'Rules on itype and withdrawn, hidelostitems set'
351
    );
358
    );
352
    is(
359
    is(
353
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )
360
        $biblio->items->filter_by_visible_in_opac
354
          ->next->itemnumber,
361
          ->next->itemnumber,
355
        $item_5->itemnumber,
362
        $item_5->itemnumber,
356
        'The right item is returned'
363
        'The right item is returned'
357
- 

Return to bug 24254