Bugzilla – Attachment 44334 Details for
Bug 14973
Add an alert during purchase suggestion submissions to warn the user when an existing biblio appears to satisfy the request
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14973: Check existing biblio when submitting a purchase suggestion
Bug-14973-Check-existing-biblio-when-submitting-a-.patch (text/plain), 15.83 KB, created by
Nicole C. Engard
on 2015-11-03 13:49:29 UTC
(
hide
)
Description:
Bug 14973: Check existing biblio when submitting a purchase suggestion
Filename:
MIME Type:
Creator:
Nicole C. Engard
Created:
2015-11-03 13:49:29 UTC
Size:
15.83 KB
patch
obsolete
>From 0433fd4e75036a057544b0af134825908ef96256 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud> >Date: Wed, 7 Oct 2015 17:34:33 +0200 >Subject: [PATCH] Bug 14973: Check existing biblio when submitting a purchase > suggestion > >Test plan: >- Go to opac suggestions page (opac-suggestions.pl) and click on "New purchase suggestion", >- type the title (and author?) of a document that stand in you database >- you should get a warning message about an exiting biblio. >- clicking on confirm your suggestion add it, cancel does nothing > >Signed-off-by: Nicole Engard <nengard@bywatersolutions.com> >--- > C4/Suggestions.pm | 42 +++++++++++++++ > .../bootstrap/en/modules/opac-suggestions.tt | 40 ++++++++++----- > opac/opac-suggestions.pl | 54 +++++++++++--------- > t/db_dependent/Suggestions.t | 20 +++++++- > 4 files changed, 120 insertions(+), 36 deletions(-) > >diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm >index 30746b7..8a14ea2 100644 >--- a/C4/Suggestions.pm >+++ b/C4/Suggestions.pm >@@ -27,6 +27,7 @@ use C4::Context; > use C4::Output; > use C4::Debug; > use C4::Letters; >+use C4::Biblio qw( GetMarcFromKohaField ); > use Koha::DateUtils; > > use List::MoreUtils qw(any); >@@ -48,6 +49,7 @@ our @EXPORT = qw( > SearchSuggestion > DelSuggestionsOlderThan > GetUnprocessedSuggestions >+ MarcRecordFromSuggestion > ); > > =head1 NAME >@@ -618,6 +620,46 @@ sub GetUnprocessedSuggestions { > return $s; > } > >+=head2 MarcRecordFromSuggestion >+ >+ $record = MarcRecordFromSuggestion ( $suggestion ) >+ >+This function build a marc record object from a suggestion >+ >+=cut >+ >+sub MarcRecordFromSuggestion { >+ my ($suggestion) = @_; >+ my $record = MARC::Record->new(); >+ >+ my ($title_tag, $title_subfield) = GetMarcFromKohaField('biblio.title', ''); >+ $record->append_fields( >+ MARC::Field->new($title_tag, ' ', ' ', $title_subfield => $suggestion->{title}) >+ ); >+ >+ my ($author_tag, $author_subfield) = GetMarcFromKohaField('biblio.author', ''); >+ if ($record->field( $author_tag )) { >+ $record->field( $author_tag )->add_subfields( $author_subfield => $suggestion->{author} ); >+ } >+ else { >+ $record->append_fields( >+ MARC::Field->new($author_tag, ' ', ' ', $author_subfield => $suggestion->{author}) >+ ); >+ } >+ >+ my ($it_tag, $it_subfield) = GetMarcFromKohaField('biblioitems.itemtype', ''); >+ if ($record->field( $it_tag )) { >+ $record->field( $it_tag )->add_subfields( $it_subfield => $suggestion->{itemtype} ); >+ } >+ else { >+ $record->append_fields( >+ MARC::Field->new($it_tag, ' ', ' ', $it_subfield => $suggestion->{author}) >+ ); >+ } >+ >+ return $record; >+} >+ > 1; > __END__ > >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 1753d8e..a686c89 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt >@@ -32,21 +32,32 @@ > <p>Please fill out this form to make a purchase suggestion. You will receive an email when the library processes your suggestion</p> > <p>Only the title is required, but the more information you enter the easier it will be for the librarians to find the title you're requesting. The "Notes" field can be used to provide any additional information.</p> > >+ [% FOR m IN messages %] >+ <div class="alert alert-[% m.type %]"> >+ [% SWITCH m.code %] >+ [% CASE 'biblio_exists' %] >+ A similar document already exists: <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% m.id %]">[% m.title %]</a>. Click on "Confirm your suggestion" to ignore this message. >+ [% CASE %] >+ [% m.code %] >+ [% END %] >+ </div> >+ [% END %] >+ > <form action="/cgi-bin/koha/opac-suggestions.pl" method="post"> > <fieldset class="rows"> > <ol> >- <li><label class="required" for="title">Title:</label><input type="text" id="title" name="title" class="span6" maxlength="255" /></li> >- <li><label for="author">Author:</label><input type="text" id="author" name="author" class="span6" maxlength="80" /></li> >- <li><label for="copyrightdate">Copyright date:</label><input type="text" id="copyrightdate" name="copyrightdate" size="4" maxlength="4" /></li> >- <li><label for="isbn">Standard number (ISBN, ISSN or other):</label><input type="text" id="isbn" name="isbn" maxlength="80" /></li> >- <li><label for="publishercode">Publisher:</label><input type="text" id="publishercode" name="publishercode" class="span6" maxlength="80" /></li> >- <li><label for="collectiontitle">Collection title:</label><input type="text" id="collectiontitle" name="collectiontitle" class="span6" maxlength="80" /></li> >- <li><label for="place">Publication place:</label><input type="text" id="place" name="place" maxlength="80" /></li> >+ <li><label class="required" for="title">Title:</label><input type="text" id="title" name="title" class="span6" maxlength="255" value="[% title %]" /></li> >+ <li><label for="author">Author:</label><input type="text" id="author" name="author" class="span6" maxlength="80" value="[% author %]" /></li> >+ <li><label for="copyrightdate">Copyright date:</label><input type="text" id="copyrightdate" name="copyrightdate" size="4" maxlength="4" value="[% copyrightdate %]" /></li> >+ <li><label for="isbn">Standard number (ISBN, ISSN or other):</label><input type="text" id="isbn" name="isbn" maxlength="80" value="[% isbn %]" /></li> >+ <li><label for="publishercode">Publisher:</label><input type="text" id="publishercode" name="publishercode" class="span6" maxlength="80" value="[% publishercode %]"/></li> >+ <li><label for="collectiontitle">Collection title:</label><input type="text" id="collectiontitle" name="collectiontitle" class="span6" maxlength="80" value="[% collectiontitle %]"/></li> >+ <li><label for="place">Publication place:</label><input type="text" id="place" name="place" maxlength="80" valu="[% place %]" /></li> > <li><label for="itemtype">Item type:</label> > <select name="itemtype" id="itemtype"> > <option value="">Default</option> > [% FOREACH itemtypeloo IN itemtypeloop %] >- [% IF ( itemtypeloo.selected ) %] >+ [% IF ( itemtypeloo.itemtype == itemtype ) %] > <option value="[% itemtypeloo.itemtype %]" selected="selected"> > [% ELSE %] > <option value="[% itemtypeloo.itemtype %]"> >@@ -60,7 +71,7 @@ > <li><label for="branch">Library:</label> > <select name="branchcode" id="branch"> > [% FOREACH branchloo IN branchloop %] >- [% IF ( branchloo.selected ) %] >+ [% IF ( branchloo.branchcode == branchcode ) %] > <option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option> > [% ELSE %] > <option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option> >@@ -82,7 +93,7 @@ > [% END %] > <li> > <label for="note">Notes:</label> >- <textarea name="note" id="note" rows="5" cols="40"></textarea> >+ <textarea name="note" id="note" rows="5" cols="40">[% note %]</textarea> > </li> > > <!-- Add a hidden 'negcap' field --> >@@ -94,8 +105,13 @@ > </fieldset> > <fieldset class="action"> > <input type="hidden" name="suggested_by_anyone" value="[% suggested_by_anyone %]" /> >- <input type="hidden" name="op" value="add_confirm" /> >- <input type="submit" onclick="Check(this.form); return false;" class="btn" value="Submit your suggestion" /> <a class="action" href="/cgi-bin/koha/opac-suggestions.pl">Cancel</a> >+ <input type="hidden" name="op" value="add_validate" /> >+ [% IF ( need_confirm ) %] >+ <input type="submit" onclick="this.form.op.value = 'add_confirm'; this.form.submit();" class="btn" value="Confirm your suggestion" /> >+ [% ELSE %] >+ <input type="submit" onclick="Check(this.form); return false;" class="btn" value="Submit your suggestion" /> >+ [% END %] >+ <a class="action" href="/cgi-bin/koha/opac-suggestions.pl">Cancel</a> > </fieldset> > </form> > [% END # IF op_add %] >diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl >index 6b7f8d4..b09eb89 100755 >--- a/opac/opac-suggestions.pl >+++ b/opac/opac-suggestions.pl >@@ -29,6 +29,7 @@ use C4::Suggestions; > use C4::Koha; > use C4::Dates; > use C4::Scrubber; >+use C4::Search qw( FindDuplicate ); > > use Koha::DateUtils qw( dt_from_string ); > >@@ -38,6 +39,7 @@ my $suggestion = $input->Vars; > delete $suggestion->{negcap}; > my $negcaptcha = $input->param('negcap'); > my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0; >+my $need_confirm = 0; > > # If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return. > if ($negcaptcha ) { >@@ -51,7 +53,7 @@ if ( ! C4::Context->preference('suggestion') ) { > exit; > } > >-delete $suggestion->{$_} foreach qw<op suggested_by_anyone>; >+delete $suggestion->{$_} foreach qw<op suggested_by_anyone confirm>; > $op = 'else' unless $op; > > my ( $template, $borrowernumber, $cookie, @messages ); >@@ -109,35 +111,40 @@ if ( $op eq 'else' ) { > } > } > >-my $suggestions_loop = >- &SearchSuggestion( $suggestion); >-if ( $op eq "add_confirm" ) { >- if (@$suggestions_loop>=1){ >+if ( $op eq "add_validate" ) { >+ $op = 'add_confirm'; >+ my $suggestions = &SearchSuggestion($suggestion); >+ my $biblio = MarcRecordFromSuggestion($suggestion); >+ if (@$suggestions >=1 ){ > #some suggestion are answering the request Donot Add >- for my $suggestion ( @$suggestions_loop ) { >+ for my $suggestion ( @$suggestions ) { > push @messages, { type => 'error', code => 'already_exists', id => $suggestion->{suggestionid} }; > last; > } >+ $op = 'else'; > } >- else { >- my $scrubber = C4::Scrubber->new(); >- foreach my $suggest (keys %$suggestion){ >- # Don't know why the encode is needed for Perl v5.10 here >- $suggestion->{$suggest} = Encode::encode("utf8", $scrubber->scrub($suggestion->{$suggest}) ); >- } >- $suggestion->{suggesteddate} = dt_from_string; >- $suggestion->{branchcode} = $input->param('branchcode') || C4::Context->userenv->{"branch"}; >- >- &NewSuggestion($suggestion); >- # empty fields, to avoid filter in "SearchSuggestion" >- $$suggestion{$_}='' foreach qw<title author publishercode copyrightdate place collectiontitle isbn STATUS>; >- $suggestions_loop = >- &SearchSuggestion( $suggestion ); >- push @messages, { type => 'info', code => 'success_on_inserted' }; >- } >+ elsif (my ($duplicatebiblionumber, $duplicatetitle) = FindDuplicate($biblio)) { >+ push @messages, { type => 'error', code => 'biblio_exists', id => $duplicatebiblionumber, title => $duplicatetitle }; >+ $need_confirm = 1; >+ $op = 'add'; >+ } >+} >+ >+if ($op eq "add_confirm") { >+ my $scrubber = C4::Scrubber->new(); >+ foreach my $suggest (keys %$suggestion) { >+ # Don't know why the encode is needed for Perl v5.10 here >+ $suggestion->{$suggest} = Encode::encode("utf8", $scrubber->scrub($suggestion->{$suggest}) ); >+ } >+ $suggestion->{suggesteddate} = dt_from_string; >+ $suggestion->{branchcode} = $input->param('branchcode') || C4::Context->userenv->{"branch"}; >+ >+ &NewSuggestion($suggestion); >+ push @messages, { type => 'info', code => 'success_on_inserted' }; > $op = 'else'; > } > >+my $suggestions_loop = &SearchSuggestion({suggestedby => $suggestion->{suggestedby}}); > if ( $op eq "delete_confirm" ) { > my @delete_field = $input->param("delete_field"); > foreach my $delete_field (@delete_field) { >@@ -189,7 +196,7 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) { > > $template->param( > %$suggestion, >- itemtypeloop=> $supportlist, >+ placeitemtypeloop=> $supportlist, > suggestions_loop => $suggestions_loop, > patron_reason_loop => $patron_reason_loop, > "op_$op" => 1, >@@ -197,6 +204,7 @@ $template->param( > messages => \@messages, > suggestionsview => 1, > suggested_by_anyone => $suggested_by_anyone, >+ need_confirm => $need_confirm, > ); > > output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t >index 29e59bb..8f83974 100644 >--- a/t/db_dependent/Suggestions.t >+++ b/t/db_dependent/Suggestions.t >@@ -26,7 +26,7 @@ use C4::Budgets qw( AddBudgetPeriod AddBudget ); > use Koha::DateUtils qw( dt_from_string ); > > use DateTime::Duration; >-use Test::More tests => 105; >+use Test::More tests => 108; > use Test::Warn; > > BEGIN { >@@ -364,6 +364,24 @@ ModSuggestion( $my_suggestion ); > $suggestion = GetSuggestion($my_suggestionid_test_budgetid); > is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' ); > >+my $suggestion2 = { >+ title => "Cuisine d'automne", >+ author => "Catherine", >+ itemtype => "LIV" >+}; >+ >+my $record = MarcRecordFromSuggestion($suggestion2); >+ >+is("MARC::Record", ref($record), "MarcRecordFromSuggestion should return a MARC::Record object"); >+ >+my ($title_tag, $title_subfield) = C4::Biblio::GetMarcFromKohaField('biblio.title', ''); >+ >+is($record->field( $title_tag )->subfield( $title_subfield ), "Cuisine d'automne", "Record from suggestion title should be 'Cuisine d'automne'"); >+ >+my ($author_tag, $author_subfield) = C4::Biblio::GetMarcFromKohaField('biblio.author', ''); >+ >+is($record->field( $author_tag )->subfield( $author_subfield ), "Catherine", "Record from suggestion author should be 'Catherine'"); >+ > subtest 'GetUnprocessedSuggestions' => sub { > plan tests => 11; > $dbh->do(q|DELETE FROM suggestions|); >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14973
:
43193
|
44091
|
44319
|
44320
|
44334
|
44335
|
60877
|
60913
|
93141
|
93142
|
94297
|
94298
|
94301
|
94302
|
94303
|
94304
|
95113
|
95114
|
95517
|
96255
|
96256
|
96257
|
96258
|
96259
|
96260
|
96261
|
96325
|
96326
|
96327
|
96328
|
96329
|
96330
|
96331