From 40d0a77a01be40b21f1190b195f47ae88c889b5b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 5 Mar 2019 11:00:44 -0300 Subject: [PATCH] Bug 22455: Add Koha::Biblio::hidden_in_opac method This patch adds a hidden_in_opac method that does the same calculation done in places like opac-tags.pl. The condition that is checked is that all items belonging to the biblio are hidden. This is the current behaviour in the code. To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/Biblio.t => SUCCESS: Tests pass! Signed-off-by: Michal Denar Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- Koha/Biblio.pm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index d2e4d4d321..56f91859d5 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -20,6 +20,7 @@ package Koha::Biblio; use Modern::Perl; use Carp; +use List::MoreUtils qw(any); use C4::Biblio qw(); @@ -186,6 +187,30 @@ sub can_be_transferred { return 0; } +=head3 hidden_in_opac + +my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] }) + +Returns true if the biblio matches the hidding criteria defined in $rules. +Returns false otherwise. + +Takes HASHref that can have the following parameters: + OPTIONAL PARAMETERS: + $rules : { => [ value_1, ... ], ... } + +Note: $rules inherits its structure from the parsed YAML from reading +the I system preference. + +=cut + +sub hidden_in_opac { + my ( $self, $params ) = @_; + + my $rules = $params->{rules} // {}; + + return !(any { !$_->hidden_in_opac({ rules => $rules }) } $self->items); +} + =head3 article_request_type my $type = $biblio->article_request_type( $borrower ); -- 2.39.5