From a35d5da3b845aa36a9db5c713a2295b13902277a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 7 May 2014 15:55:54 +0200 Subject: [PATCH] Bug 11742: Change prototype for GetLetters The GetLetters subroutine should return an arrayref with different letters for a module. Test plan: 0/ Delete your notices with module=claimacquisition, claimissues, serial 1/ Go on the late orders page (acqui/lateorders.pl) and verify you cannot choose a notice for claiming 2/ Create a notice with module=claimacquisition 3/ Go on the late orders page (acqui/lateorders.pl) and verify you can choose the notice for claiming 4/ Go on the Claim serials page (serials/claims.pl) and repeat the same thing with the a "claimissues" notice 5/ Create a new subscription (serials/subscription-add.pl) and verify you cannot choose a notification for patrons. 6/ Create a notice with module "serial" and verify you can. --- C4/Letters.pm | 62 ++++++-------------- acqui/lateorders.pl | 8 +-- .../prog/en/modules/serials/claims.tt | 6 +- serials/claims.pl | 12 ++-- serials/subscription-add.pl | 38 +++++++----- t/Letters.t | 4 +- tools/overduerules.pl | 46 ++------------- 7 files changed, 57 insertions(+), 119 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 055c8c1..4e0ea20 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -62,58 +62,30 @@ C4::Letters - Give functions for Letters management Letters are managed through "alerts" sent by Koha on some events. All "alert" related functions are in this module too. -=head2 GetLetters([$category]) +=head2 GetLetters([$module]) - $letters = &GetLetters($category); + $letters = &GetLetters($module); returns informations about letters. - if needed, $category filters for letters given category - Create a letter selector with the following code - -=head3 in PERL SCRIPT - -my $letters = GetLetters($cat); -my @letterloop; -foreach my $thisletter (keys %$letters) { - my $selected = 1 if $thisletter eq $letter; - my %row =( - value => $thisletter, - selected => $selected, - lettername => $letters->{$thisletter}, - ); - push @letterloop, \%row; -} -$template->param(LETTERLOOP => \@letterloop); - -=head3 in TEMPLATE - - + if needed, $module filters for letters given module =cut sub GetLetters { + my ($filters) = @_; + my $module = $filters->{module}; + my $dbh = C4::Context->dbh; + my $letters = $dbh->selectall_arrayref( + q| + SELECT module, code, branchcode, name + FROM letter + WHERE 1 + | + . ( $module ? q| AND module = ?| : q|| ) + . q| GROUP BY code ORDER BY name|, { Slice => {} } + , ( $module ? $module : () ) + ); - # returns a reference to a hash of references to ALL letters... - my ( $cat ) = @_; - my %letters; - my $dbh = C4::Context->dbh; - my $sth; - my $query = q{ - SELECT * FROM letter WHERE 1 - }; - $query .= q{ AND module = ? } if defined $cat; - $query .= q{ GROUP BY code ORDER BY name}; - $sth = $dbh->prepare($query); - $sth->execute((defined $cat ? $cat : ())); - - while ( my $letter = $sth->fetchrow_hashref ) { - $letters{ $letter->{'code'} } = $letter->{'name'}; - } - return \%letters; + return $letters; } # FIXME: using our here means that a Plack server will need to be diff --git a/acqui/lateorders.pl b/acqui/lateorders.pl index 1a64a4c..3c96e11 100755 --- a/acqui/lateorders.pl +++ b/acqui/lateorders.pl @@ -159,17 +159,13 @@ foreach (@lateorders){ $total += $_->{subtotal}; } -my @letters; -my $letters=GetLetters("claimacquisition"); -foreach (keys %$letters){ - push @letters, {code=>$_,name=>$letters->{$_}}; -} -$template->param(letters=>\@letters) if (@letters); +my $letters = GetLetters({ module => "claimacquisition" }); $template->param(ERROR_LOOP => \@errors) if (@errors); $template->param( lateorders => \@lateorders, delay => $delay, + letters => $letters, estimateddeliverydatefrom => $estimateddeliverydatefrom, estimateddeliverydateto => $estimateddeliverydateto, total => $total, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt index 34c6d8c..de9102e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt @@ -177,12 +177,12 @@

Claims

-[% IF ( letter ) %][% UNLESS ( missingissues ) %][% IF ( supplierid ) %]
No missing issues found.
[% ELSE %]
Please choose a vendor.
[% END %][% END %][% END %] +[% IF letters %][% UNLESS ( missingissues ) %][% IF ( supplierid ) %]
No missing issues found.
[% ELSE %]
Please choose a vendor.
[% END %][% END %][% END %] [% IF ( SHOWCONFIRMATION ) %]
Your notification has been sent.
[% END %] -[% UNLESS ( letter ) %]
No claims notice defined. Please define one.
[% END %] +[% UNLESS letters %]
No claims notice defined. Please define one.
[% END %]
@@ -331,7 +331,7 @@ Download selected claims [% END %] -[% IF ( letter ) %] +[% IF ( letters ) %]