@@ -, +, @@
---
circ/request-article.pl | 21 +++++++++---
.../prog/en/modules/circ/request-article.tt | 5 ++-
.../en/modules/opac-request-article.tt | 5 ++-
opac/opac-request-article.pl | 32 ++++++++++++++-----
4 files changed, 48 insertions(+), 15 deletions(-)
--- a/circ/request-article.pl
+++ a/circ/request-article.pl
@@ -25,8 +25,11 @@ use C4::Utils::DataTables::Members;
use C4::Search qw( enabled_staff_search_views );
use C4::Serials qw( CountSubscriptionFromBiblionumber );
use Koha::Biblios;
+use Koha::Logger;
use Koha::Patrons;
use Koha::ArticleRequests;
+
+use Scalar::Util qw( blessed );
use Try::Tiny;
my $cgi = CGI->new;
@@ -86,11 +89,19 @@ if ( $action eq 'create' ) {
patron_notes => $patron_notes,
format => $format,
}
- )->store();
+ )->request;
} catch {
- $template->param(
- error_message => $_->{message}
- );
+ if ( blessed $_ and $_->isa('Koha::Exceptions::ArticleRequest::LimitReached') ) {
+ $template->param(
+ error_message => 'article_request_limit_reached'
+ );
+ }
+ else {
+ Koha::Logger->get->debug("Unhandled exception when placing an article request ($_)");
+ $template->param(
+ error_message => 'article_request_unhandled_exception'
+ );
+ }
};
}
@@ -119,7 +130,7 @@ if ( !$patron && $patron_cardnumber ) {
if( $patron && !$patron->can_request_article) {
$patron = undef;
$template->param(
- error_message => 'Patron cannot request more articles for today'
+ error_message => 'article_request_limit_reached'
);
}
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt
@@ -48,7 +48,10 @@
Request article from [% INCLUDE 'biblio-title.inc' link = 1 %]
[% IF error_message %]
-
[% error_message | html %]
+ [% SWITCH error_message %]
+ [% CASE 'article_request_limit_reached' %]
Patron reached daily limit.
+ [% CASE 'article_request_unhandled_exception' %]
An error has occurred. Check the logs.
+ [% END %]
[% END %]
[% IF no_patrons_found %]
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt
+++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt
@@ -219,7 +219,10 @@
[% ELSIF error_message %]
[% biblio.title | html %]
- [% error_message | html %]
+ [% SWITCH error_message %]
+ [% CASE 'article_request_limit_reached' %]You reached your article requests daily limit.
+ [% CASE 'article_request_unhandled_exception' %]An error has occurred.
+ [% END %]
[% ELSE %]
[% biblio.title | html %]
--- a/opac/opac-request-article.pl
+++ a/opac/opac-request-article.pl
@@ -25,7 +25,10 @@ use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
use Koha::Biblios;
+use Koha::Logger;
use Koha::Patrons;
+
+use Scalar::Util qw( blessed );
use Try::Tiny;
my $cgi = CGI->new;
@@ -60,6 +63,9 @@ if ( $action eq 'create' ) {
my $patron_notes = $cgi->param('patron_notes') || undef;
my $format = $cgi->param('format') || undef;
+
+ my $success;
+
try {
my $ar = Koha::ArticleRequest->new(
{
@@ -77,16 +83,26 @@ if ( $action eq 'create' ) {
patron_notes => $patron_notes,
format => $format,
}
- )->store();
+ )->request;
+ $success = 1;
+ } catch {
+ if ( blessed $_ and $_->isa('Koha::Exceptions::ArticleRequest::LimitReached') ) {
+ $template->param(
+ error_message => 'article_request_limit_reached'
+ );
+ }
+ else {
+ Koha::Logger->get->debug("Unhandled exception when placing an article request ($_)");
+ $template->param(
+ error_message => 'article_request_unhandled_exception'
+ );
+ }
+ };
+ if ( $success ) {
print $cgi->redirect("/cgi-bin/koha/opac-user.pl#opac-user-article-requests");
exit;
- } catch {
- exit unless $_->[0] && $_->[0] eq 'EXIT';
- $template->param(
- error_message => $_->{message}
- );
- };
+ }
# Should we redirect?
}
elsif ( !$action && C4::Context->preference('ArticleRequestsOpacHostRedirection') ) {
@@ -106,7 +122,7 @@ my $patron = Koha::Patrons->find($borrowernumber);
if(!$patron->can_request_article) {
$template->param(
- error_message => 'You cannot request more articles for today'
+ error_message => 'article_request_limit_reached'
);
}
--