From f5270a792c3f1ae53f050dc7fb861e14f9869afe Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 5 Mar 2019 09:44:59 -0300 Subject: [PATCH] Bug 22454: Add Koha::Item::hidden_in_opac method This patch adds a hidden_in_opac method that does the same calculation done in GetHiddenItemnumbers, but for a single item, and doesn't get the OpacHiddenItems syspref, but expects them to be passed as parameters (to avoid multiple reads). To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/Item.t => SUCCESS: Tests pass! Signed-off-by: Michal Denar Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- Koha/Item.pm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Koha/Item.pm b/Koha/Item.pm index f3799eff20..66e0f9c73b 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -20,6 +20,7 @@ package Koha::Item; use Modern::Perl; use Carp; +use List::MoreUtils qw(any); use Koha::Database; use Koha::DateUtils qw( dt_from_string ); @@ -192,6 +193,40 @@ sub can_article_request { return q{}; } +=head3 hidden_in_opac + +my $bool = $item->hidden_in_opac({ [ rules => $rules ] }) + +Returns true if item fields match 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} // {}; + + my $hidden_in_opac = 0; + + foreach my $field ( keys %{$rules} ) { + + if ( any { $self->$field eq $_ } @{ $rules->{$field} } ) { + $hidden_in_opac = 1; + last; + } + } + + return $hidden_in_opac; +} + =head3 can_be_transferred $item->can_be_transferred({ to => $to_library, from => $from_library }) -- 2.39.5