From 2924f767fdd8b5169b46af31ca3a5dc2291d163f Mon Sep 17 00:00:00 2001 From: Devinim Date: Tue, 3 Dec 2019 10:53:29 +0000 Subject: [PATCH] Bug 22774: Limit Purchase Suggestion in a specified Time period --- .../bootstrap/en/modules/opac-suggestions.tt | 15 ++++++++++++--- opac/opac-suggestions.pl | 19 ++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt index 2da7660e84..f72aad90e6 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt @@ -31,7 +31,10 @@
[% IF ( op_add ) %] - [% IF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %] + [% IF ( Koha.Preference('MaxTotalSuggestions') != '' && patrons_total_suggestions_count >= Koha.Preference('MaxTotalSuggestions') ) %] +

You cannot place any more suggestions

+

You may have only [% Koha.Preference('MaxTotalSuggestions') | html %] suggestions in last [% Koha.Preference('NumberOfSuggestionDays') | html %] days.

+ [% ELSIF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %]

You cannot place any more suggestions

You have reached your limit of suggestions you can place at this time ([% Koha.Preference('MaxOpenSuggestions') | html %]). Once the library has processed those suggestions you will be able to place more.

[% ELSE %] @@ -215,6 +218,8 @@ [% FOR m IN messages %]
[% SWITCH m.code %] + [% CASE 'total_suggestions' %] + The suggestion has not been added. You have reached your limit of suggestions you can place at this time ([% Koha.Preference('MaxTotalSuggestions') | html %] last [% Koha.Preference('NumberOfSuggestionDays') | html %] days). [% CASE 'too_many' %] The suggestion has not been added. You have reached your limit of suggestions you can place at this time ([% Koha.Preference('MaxOpenSuggestions') | html %]). Once the library has processed those suggestions you will be able to place more. [% CASE 'already_exists' %] @@ -257,7 +262,9 @@ [% IF ( loggedinusername || ( Koha.Preference( 'AnonSuggestions' ) == 1 ) ) %]
- [% IF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %] + [% IF ( Koha.Preference('MaxTotalSuggestions') != '' && patrons_total_suggestions_count >= Koha.Preference('MaxTotalSuggestions') ) %] +

You may have only [% Koha.Preference('MaxTotalSuggestions') | html %] suggestions in last [% Koha.Preference('NumberOfSuggestionDays') | html %] days.

+ [% ELSIF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %]

You have reached your limit of suggestions you can place at this time ([% Koha.Preference('MaxOpenSuggestions') | html %]).
Once the library has processed those suggestions you will be able to place more.

[% ELSE %] New purchase suggestion @@ -363,7 +370,9 @@

There are no pending purchase suggestions.

[% END %] [% IF ( loggedinusername || ( Koha.Preference( 'AnonSuggestions' ) == 1 ) ) %] - [% IF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %] + [% IF ( Koha.Preference('MaxTotalSuggestions') != '' && patrons_total_suggestions_count >= Koha.Preference('MaxTotalSuggestions') ) %] +

You may have only [% Koha.Preference('MaxTotalSuggestions') | html %] suggestions in last [% Koha.Preference('NumberOfSuggestionDays') | html %] days.

+ [% ELSIF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %]

You have reached your limit of suggestions you can place at this time.
Once the library has processed those suggestions you will be able to place more.

[% ELSE %]

New purchase suggestion

diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index 8f792cd98f..6eb0ecc2ac 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -115,13 +115,24 @@ if ( $op eq 'else' ) { } my $patrons_pending_suggestions_count = 0; -if ( $borrowernumber && C4::Context->preference("MaxOpenSuggestions") ne '' ) { - $patrons_pending_suggestions_count = scalar @{ SearchSuggestion( { suggestedby => $borrowernumber, STATUS => 'ASKED' } ) } ; +my $patrons_total_suggestions_count = 0; +if ( $borrowernumber ){ + if ( C4::Context->preference("MaxTotalSuggestions") ne '' && C4::Context->preference("NumberOfSuggestionDays") ne '' ) { + my $suggesteddate_from = dt_from_string()->subtract(days=>C4::Context->preference("NumberOfSuggestionDays")); + $patrons_total_suggestions_count = scalar @{ SearchSuggestion( { suggestedby => $borrowernumber, suggesteddate_from => $suggesteddate_from } ) } ; + } + if ( C4::Context->preference("MaxOpenSuggestions") ne '' ) { + $patrons_pending_suggestions_count = scalar @{ SearchSuggestion( { suggestedby => $borrowernumber, STATUS => 'ASKED' } ) } ; + } } my $suggestions_loop = &SearchSuggestion($suggestion); if ( $op eq "add_confirm" ) { - if ( C4::Context->preference("MaxOpenSuggestions") ne '' && $patrons_pending_suggestions_count >= C4::Context->preference("MaxOpenSuggestions") ) #only check limit for signed in borrowers + if ( C4::Context->preference("MaxTotalSuggestions") ne '' && $patrons_total_suggestions_count >= C4::Context->preference("MaxTotalSuggestions") ) + { + push @messages, { type => 'error', code => 'total_suggestions' }; + } + elsif ( C4::Context->preference("MaxOpenSuggestions") ne '' && $patrons_pending_suggestions_count >= C4::Context->preference("MaxOpenSuggestions") ) #only check limit for signed in borrowers { push @messages, { type => 'error', code => 'too_many' }; } @@ -151,6 +162,7 @@ if ( $op eq "add_confirm" ) { &NewSuggestion($suggestion); $patrons_pending_suggestions_count++; + $patrons_total_suggestions_count++; # delete empty fields, to avoid filter in "SearchSuggestion" foreach my $field ( qw( title author publishercode copyrightdate place collectiontitle isbn STATUS ) ) { @@ -228,6 +240,7 @@ $template->param( suggestionsview => 1, suggested_by_anyone => $suggested_by_anyone, patrons_pending_suggestions_count => $patrons_pending_suggestions_count, + patrons_total_suggestions_count => $patrons_total_suggestions_count, ); output_html_with_http_headers $input, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.11.0