@@ -, +, @@ --- Koha/Exceptions/Ill.pm | 16 ++++++++++++++++ Koha/Illrequest.pm | 18 ++++++++++++------ Koha/Illrequest/Config.pm | 15 +++++++++++++++ ill/ill-requests.pl | 13 +++++++------ .../intranet-tmpl/prog/en/includes/ill-toolbar.inc | 10 ++++++++-- .../intranet-tmpl/prog/en/modules/ill/ill-requests.tt | 3 +-- 6 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 Koha/Exceptions/Ill.pm --- a/Koha/Exceptions/Ill.pm +++ a/Koha/Exceptions/Ill.pm @@ -0,0 +1,16 @@ +package Koha::Exceptions::Ill; + +use Modern::Perl; + +use Exception::Class ( + + 'Koha::Exceptions::Ill' => { + description => 'Something went wrong!', + }, + 'Koha::Exceptions::Ill::InvalidBackendId' => { + isa => 'Koha::Exceptions::Ill', + description => "Invalid backend name required", + } +); + +1; --- a/Koha/Illrequest.pm +++ a/Koha/Illrequest.pm @@ -18,16 +18,18 @@ package Koha::Illrequest; # Koha; if not, write to the Free Software Foundation, Inc., 51 Franklin # Street, Fifth Floor, Boston, MA 02110-1301 USA. +use Modern::Perl; + use Clone 'clone'; use File::Basename qw/basename/; use Koha::Database; use Koha::Email; +use Koha::Exceptions::Ill; use Koha::Illrequest; use Koha::Illrequestattributes; use Koha::Patron; use Mail::Sendmail; use Try::Tiny; -use Modern::Perl; use base qw(Koha::Object); @@ -139,13 +141,20 @@ sub load_backend { my @raw = qw/Koha Illbackends/; # Base Path my $backend_name = $backend_id || $self->backend; - my $location = join "/", @raw, $backend_name, "Base.pm"; # File to load + + unless ( defined $backend_id && $backend_id ne '' ) { + Koha::Exceptions::Ill::InvalidBackendId->throw( + "An invalid backend ID was requested ('')"); + } + + my $location = join "/", @raw, $backend_name, "Base.pm"; # File to load my $backend_class = join "::", @raw, $backend_name, "Base"; # Package name require $location; $self->{_my_backend} = $backend_class->new({ config => $self->_config }); return $self; } + =head3 _backend my $backend = $abstract->_backend($new_backend); @@ -468,10 +477,7 @@ Return a list of available backends. sub available_backends { my ( $self ) = @_; - my $backend_dir = $self->_config->backend_dir; - my @backends = (); - @backends = glob "$backend_dir/*" if ( $backend_dir ); - @backends = map { basename($_) } @backends; + my @backends = $self->_config->available_backends; return \@backends; } --- a/Koha/Illrequest/Config.pm +++ a/Koha/Illrequest/Config.pm @@ -100,6 +100,21 @@ sub backend_dir { return $self->{configuration}->{backend_directory}; } +=head3 available_backends + +Return a list of available backends. + +=cut + +sub available_backends { + my ( $self ) = @_; + my $backend_dir = $self->backend_dir; + my @backends = (); + @backends = glob "$backend_dir/*" if ( $backend_dir ); + @backends = map { basename($_) } @backends; + return \@backends; +} + =head3 partner_code $partner_code = $config->partner_code($new_code); --- a/ill/ill-requests.pl +++ a/ill/ill-requests.pl @@ -224,14 +224,15 @@ if ( $op eq 'illview' ) { } # Get a list of backends -my $ir = Koha::Illrequest->new; +my $available_backends = Koha::Illrequest::Config->new->available_backends; $template->param( - backends => $ir->available_backends, - media => [ "Book", "Article", "Journal" ], - query_type => $op, - branches => Koha::Libraries->search->unblessed, - here_link => "/cgi-bin/koha/ill/ill-requests.pl" + backends_available => ( scalar $available_backends > 0 ), + backends => $available_backends, + media => [ "Book", "Article", "Journal" ], + query_type => $op, + branches => Koha::Libraries->search, + here_link => "/cgi-bin/koha/ill/ill-requests.pl" ); output_html_with_http_headers( $cgi, $cookie, $template->output ); --- a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-toolbar.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-toolbar.inc @@ -1,7 +1,8 @@ [% USE Koha %] [% IF Koha.Preference('ILLModule ') %]
- [% IF backends.size > 1 %] + [% IF available_backends %] + [% IF backends.size > 1 %] - [% ELSE %] + [% ELSE %] New ILL request + [% END %] + [% ELSE %] + + New ILL request + [% END %] List requests --- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt @@ -4,8 +4,7 @@ [% INCLUDE 'doc-head-open.inc' %] Koha › ILL requests › [% INCLUDE 'doc-head-close.inc' %] - - + [% INCLUDE 'datatables.inc' %]