From a151ce9b1a2f4afd99f420a3ead594cd26e97d94 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 28 Feb 2024 16:48:28 +0000 Subject: [PATCH] Bug 36197: Refactor -> opac_available_backends method Signed-off-by: David Nind --- Koha/ILL/Backends.pm | 23 +++++++++++++++++++++++ opac/opac-illrequests.pl | 6 +++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Koha/ILL/Backends.pm b/Koha/ILL/Backends.pm index eec8d27863..4b469a017a 100644 --- a/Koha/ILL/Backends.pm +++ b/Koha/ILL/Backends.pm @@ -19,6 +19,8 @@ package Koha::ILL::Backends; use Modern::Perl; +use Koha::ILL::Request::Config; + use base qw(Koha::Objects); =head1 NAME @@ -51,6 +53,27 @@ sub installed_backends { return \@installed; } +=head3 opac_available_backends + +Return a list of backends available in the OPAC + +=cut + +sub opac_available_backends { + my ( $self, $loggedinuser ) = @_; + my $reduced = C4::Context->preference('ILLOpacbackends'); + my $backends = Koha::ILL::Request::Config->new->available_backends($reduced); + + if ( !$loggedinuser && C4::Context->preference('ILLOpacUnauthenticatedRequest') ){ + foreach my $backend ( @{$backends} ) { + my $loaded_b = Koha::ILL::Request->new->load_backend($backend); + @$backends = grep { !/$backend/ } @$backends + if ( $loaded_b->_backend_capability('opac_unauthenticated_ill_requests') == 0 ); + } + } + return $backends; +} + =head2 Internal methods =head3 _type diff --git a/opac/opac-illrequests.pl b/opac/opac-illrequests.pl index 906a7262eb..ae28f4ed29 100755 --- a/opac/opac-illrequests.pl +++ b/opac/opac-illrequests.pl @@ -30,6 +30,7 @@ use POSIX qw( strftime ); use Koha::ILL::Request::Config; use Koha::ILL::Requests; use Koha::ILL::Request; +use Koha::ILL::Backends; use Koha::Libraries; use Koha::Patrons; use Koha::ILL::Request::Workflow::Availability; @@ -56,11 +57,10 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ }); # Are we able to actually work? -my $reduced = C4::Context->preference('ILLOpacbackends'); -my $backends = Koha::ILL::Request::Config->new->available_backends($reduced); +my $patron = Koha::Patrons->find($loggedinuser); +my $backends = Koha::ILL::Backends->opac_available_backends($patron); my $backends_available = ( scalar @{$backends} > 0 ); $template->param( backends_available => $backends_available ); -my $patron = Koha::Patrons->find($loggedinuser); my $op = Koha::ILL::Request->get_op_param_deprecation( 'opac', $params ); -- 2.39.5