From 675ab180b098af15c2a24d90c1015a2291fd9126 Mon Sep 17 00:00:00 2001 From: Devinim Date: Thu, 9 Jan 2020 10:48:15 +0000 Subject: [PATCH] Bug 22774: Limit Purchase Suggestion in a specified Time period Test plan: 1 - Apply this patch 2 - Run updatedatabase.pl 3 - By default the preferences are blank and do not limit. 4 - Set the limits to 3 in 30 days 5 - Go to purchase suggestion page from OPAC as a logged in patron 6 - Place 3 suggestions and confirm you cannot place any more 7 - Alter one of the suggestions to have been made more than 30 days ago UPDATE suggestions SET suggesteddate = '2020-01-01' WHERE suggestionid=3; 8 - Confirm you can place another suggestion 9 - Log out of OPAC 10 - Make sure AnonSyggestions is set to 'Allow' and AnonymousPatron is set 11 - Confirm anonymous suggestions are not limited by the syspref 12 - Confirm that a blank value in either MaxTotalSuggestions or NumberOfSuggestionDays does not limit suggestions Signed-off-by: Kelly McElligott Signed-off-by: Rhonda Kuiper Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- .../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 9829aed40d..75c4f3c18a 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 %] @@ -236,6 +239,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' %] @@ -278,7 +283,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 @@ -392,7 +399,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 1ac168c0f2..b506a1537a 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -126,13 +126,24 @@ if ( $op eq "add_validate" && not $biblionumber ) { # If we are creating the sug } 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' } ) } ; + } } if ( $op eq "add_confirm" ) { my $suggestions_loop = &SearchSuggestion($suggestion); - 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' }; } @@ -162,6 +173,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 ) ) { @@ -254,6 +266,7 @@ $template->param( suggested_by_anyone => $suggested_by_anyone, patrons_pending_suggestions_count => $patrons_pending_suggestions_count, need_confirm => $need_confirm, + patrons_total_suggestions_count => $patrons_total_suggestions_count, ); output_html_with_http_headers $input, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.39.5