Bug 24254: (QA follow-up) Inlines opachiddenitems handling
We decided to inline the opachiddenitems filter as we don't believe it
will be used exclusively.
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
(cherry picked from commit 67f5a26077)
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
This commit is contained in:
parent
809b3308ef
commit
cb294fa488
|
|
@ -48,7 +48,8 @@ Koha::Items - Koha Item object set class
|
|||
Returns a new resultset, containing those items that are not expected to be hidden in OPAC
|
||||
for the passed I<Koha::Patron> object that is passed.
|
||||
|
||||
The I<OpacHiddenItems> and I<hidelostitems> system preferences are honoured.
|
||||
The I<OpacHiddenItems>, I<hidelostitems> and I<OpacHiddenItemsExceptions> system preferences
|
||||
are honoured.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -59,8 +60,16 @@ sub filter_by_visible_in_opac {
|
|||
|
||||
my $result = $self;
|
||||
|
||||
# Filter out OpacHiddenItems unless disabled by OpacHiddenItemsExceptions
|
||||
unless ( $patron and $patron->category->override_hidden_items ) {
|
||||
$result = $result->filter_out_opachiddenitems;
|
||||
my $rules = C4::Context->yaml_preference('OpacHiddenItems') // {};
|
||||
|
||||
my $rules_params;
|
||||
foreach my $field (keys %$rules){
|
||||
$rules_params->{$field}->{'-not_in'} = $rules->{$field};
|
||||
}
|
||||
|
||||
$result = $result->search( $rules_params );
|
||||
}
|
||||
|
||||
if (C4::Context->preference('hidelostitems')) {
|
||||
|
|
@ -70,28 +79,6 @@ sub filter_by_visible_in_opac {
|
|||
return $result;
|
||||
}
|
||||
|
||||
=head3 filter_out_opachiddenitems
|
||||
|
||||
my $filered_items = $items->filter_out_opachiddenitems;
|
||||
|
||||
Returns a new resultset, containing those items that are not expected to be hidden in OPAC.
|
||||
The I<OpacHiddenItems> system preference is honoured.
|
||||
|
||||
=cut
|
||||
|
||||
sub filter_out_opachiddenitems {
|
||||
my ($self) = @_;
|
||||
|
||||
my $rules = C4::Context->yaml_preference('OpacHiddenItems') // {};
|
||||
|
||||
my $rules_params;
|
||||
foreach my $field (keys %$rules){
|
||||
$rules_params->{$field}->{'-not_in'} = $rules->{$field};
|
||||
}
|
||||
|
||||
return $self->search( $rules_params );
|
||||
}
|
||||
|
||||
=head3 filter_out_lost
|
||||
|
||||
my $filered_items = $items->filter_out_lost;
|
||||
|
|
@ -129,6 +116,8 @@ sub object_class {
|
|||
=head1 AUTHOR
|
||||
|
||||
Kyle M Hall <kyle@bywatersolutions.com>
|
||||
Tomas Cohen Arazi <tomascohen@theke.io>
|
||||
Martin Renvoize <martin.renvoize@ptfs-europe.com>
|
||||
|
||||
=cut
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 14;
|
||||
use Test::More tests => 12;
|
||||
|
||||
use Test::MockModule;
|
||||
use Test::Exception;
|
||||
|
|
@ -356,88 +356,3 @@ subtest 'filter_out_lost() tests' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'filter_out_opachiddenitems() tests' => sub {
|
||||
|
||||
plan tests => 6;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
# have a fresh biblio
|
||||
my $biblio = $builder->build_sample_biblio;
|
||||
# have two itemtypes
|
||||
my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' });
|
||||
my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' });
|
||||
# have 5 items on that biblio
|
||||
my $item_1 = $builder->build_sample_item(
|
||||
{
|
||||
biblionumber => $biblio->biblionumber,
|
||||
itype => $itype_1->itemtype,
|
||||
withdrawn => 1
|
||||
}
|
||||
);
|
||||
my $item_2 = $builder->build_sample_item(
|
||||
{
|
||||
biblionumber => $biblio->biblionumber,
|
||||
itype => $itype_2->itemtype,
|
||||
withdrawn => 2
|
||||
}
|
||||
);
|
||||
my $item_3 = $builder->build_sample_item(
|
||||
{
|
||||
biblionumber => $biblio->biblionumber,
|
||||
itype => $itype_1->itemtype,
|
||||
withdrawn => 3
|
||||
}
|
||||
);
|
||||
my $item_4 = $builder->build_sample_item(
|
||||
{
|
||||
biblionumber => $biblio->biblionumber,
|
||||
itype => $itype_2->itemtype,
|
||||
withdrawn => 4
|
||||
}
|
||||
);
|
||||
my $item_5 = $builder->build_sample_item(
|
||||
{
|
||||
biblionumber => $biblio->biblionumber,
|
||||
itype => $itype_1->itemtype,
|
||||
withdrawn => 5
|
||||
}
|
||||
);
|
||||
my $item_6 = $builder->build_sample_item(
|
||||
{
|
||||
biblionumber => $biblio->biblionumber,
|
||||
itype => $itype_1->itemtype,
|
||||
withdrawn => 5
|
||||
}
|
||||
);
|
||||
|
||||
my $rules = undef;
|
||||
|
||||
my $mocked_context = Test::MockModule->new('C4::Context');
|
||||
$mocked_context->mock( 'yaml_preference', sub {
|
||||
return $rules;
|
||||
});
|
||||
|
||||
is( $biblio->items->filter_out_opachiddenitems->count, 6, 'No rules passed' );
|
||||
|
||||
$rules = {};
|
||||
|
||||
$rules = { withdrawn => [ 1, 2 ] };
|
||||
is( $biblio->items->filter_out_opachiddenitems->count, 4, 'Rules on withdrawn' );
|
||||
|
||||
$rules = { itype => [ $itype_1->itemtype ] };
|
||||
is( $biblio->items->filter_out_opachiddenitems->count, 2, 'Rules on itype' );
|
||||
|
||||
$rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] };
|
||||
is( $biblio->items->filter_out_opachiddenitems->count, 1, 'Rules on itype and withdrawn' );
|
||||
is( $biblio->items->filter_out_opachiddenitems->next->itemnumber,
|
||||
$item_4->itemnumber,
|
||||
'The right item is returned'
|
||||
);
|
||||
|
||||
$rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] };
|
||||
is( $biblio->items->filter_out_opachiddenitems->count, 3, 'Rules on itype and withdrawn' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue