Bugzilla – Attachment 53892 Details for
Bug 15407
Move the patron categories related code to Koha::Patron::Categories - part 2
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15407: Koha::Patron::Categories - replace GetborCatFromCatType
Bug-15407-KohaPatronCategories---replace-GetborCat.patch (text/plain), 37.36 KB, created by
Jonathan Druart
on 2016-08-02 12:39:50 UTC
(
hide
)
Description:
Bug 15407: Koha::Patron::Categories - replace GetborCatFromCatType
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-08-02 12:39:50 UTC
Size:
37.36 KB
patch
obsolete
>From 411da86e0fda431c6a8774dacf638a964848fd28 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 22 Dec 2015 10:12:48 +0000 >Subject: [PATCH] Bug 15407: Koha::Patron::Categories - replace > GetborCatFromCatType > >This unnecessary complicated subroutine returned an arrayref and an >hashref of the patron categories available for the logged in user, for a given >category_type, ordered by categorycode. >This can now be done with the search_limited method. > >Test plan: >- Same prerequisite as before >For the following pages, you should not see patron categories limited to other >libraries. They should be ordered as before this patch, by categorycode. >- Add/edit a patron, change his/her patron category value. >- On the 3 following reports: > reports/bor_issues_top.pl > reports/borrowers_out.pl > reports/cat_issues_top.pl >The display for these 3 reports are different than the 2 from the first >patch (borrowers_stats.pl issues_avg_stats.pl): they are ordered by >categorycode and the ones limited to other libraries are not displayed >(should certainly be fixed). > >Note that the big part of this patch has already been tested before >(update child related: CATCODE_MULTI). > >Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz> >--- > C4/Members.pm | 55 ----------------- > Koha/Patron/Categories.pm | 16 +++-- > circ/circulation.pl | 7 +-- > .../prog/en/modules/members/update-child.tt | 69 +++++++++++----------- > .../prog/en/modules/reports/bor_issues_top.tt | 6 +- > .../prog/en/modules/reports/borrowers_out.tt | 6 +- > .../prog/en/modules/reports/cat_issues_top.tt | 6 +- > .../modules/reports/issues_by_borrower_category.tt | 4 +- > members/boraccount.pl | 9 +-- > members/mancredit.pl | 9 +-- > members/maninvoice.pl | 9 +-- > members/member-flags.pl | 9 +-- > members/member-password.pl | 11 ++-- > members/memberentry.pl | 42 +++++++------ > members/moremember.pl | 9 ++- > members/pay.pl | 14 ++--- > members/paycollect.pl | 14 ++--- > members/printfeercpt.pl | 8 +-- > members/printinvoice.pl | 9 +-- > members/readingrec.pl | 9 +-- > members/update-child.pl | 24 +++----- > reports/bor_issues_top.pl | 19 ++---- > reports/borrowers_out.pl | 15 ++--- > reports/cat_issues_top.pl | 16 +---- > reports/issues_by_borrower_category.plugin | 15 ++--- > t/db_dependent/Koha/Patron/Categories.t | 10 +++- > 26 files changed, 169 insertions(+), 251 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index 138d244..bcd45a7 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -78,7 +78,6 @@ BEGIN { > &GetMemberAccountRecords > &GetBorNotifyAcctRecord > >- &GetborCatFromCatType > GetBorrowerCategorycode > > &GetBorrowersToExpunge >@@ -1295,60 +1294,6 @@ sub GetUpcomingMembershipExpires { > return $results; > } > >-=head2 GetborCatFromCatType >- >- ($codes_arrayref, $labels_hashref) = &GetborCatFromCatType(); >- >-Looks up the different types of borrowers in the database. Returns two >-elements: a reference-to-array, which lists the borrower category >-codes, and a reference-to-hash, which maps the borrower category codes >-to category descriptions. >- >-=cut >- >-#' >-sub GetborCatFromCatType { >- my ( $category_type, $action, $no_branch_limit ) = @_; >- >- my $branch_limit = $no_branch_limit >- ? 0 >- : C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; >- >- # FIXME - This API seems both limited and dangerous. >- my $dbh = C4::Context->dbh; >- >- my $request = qq{ >- SELECT DISTINCT categories.categorycode, categories.description >- FROM categories >- }; >- $request .= qq{ >- LEFT JOIN categories_branches ON categories.categorycode = categories_branches.categorycode >- } if $branch_limit; >- if($action) { >- $request .= " $action "; >- $request .= " AND (branchcode = ? OR branchcode IS NULL)" if $branch_limit; >- } else { >- $request .= " WHERE branchcode = ? OR branchcode IS NULL" if $branch_limit; >- } >- $request .= " ORDER BY categorycode"; >- >- my $sth = $dbh->prepare($request); >- $sth->execute( >- $action ? $category_type : (), >- $branch_limit ? $branch_limit : () >- ); >- >- my %labels; >- my @codes; >- >- while ( my $data = $sth->fetchrow_hashref ) { >- push @codes, $data->{'categorycode'}; >- $labels{ $data->{'categorycode'} } = $data->{'description'}; >- } >- $sth->finish; >- return ( \@codes, \%labels ); >-} >- > =head2 GetBorrowerCategorycode > > $categorycode = &GetBorrowerCategoryCode( $borrowernumber ); >diff --git a/Koha/Patron/Categories.pm b/Koha/Patron/Categories.pm >index ee4d2ac..3673ce0 100644 >--- a/Koha/Patron/Categories.pm >+++ b/Koha/Patron/Categories.pm >@@ -38,16 +38,14 @@ Koha::Patron::Categories - Koha Patron Category Object set class > =cut > > sub search_limited { >- my ( $self ) = @_; >+ my ( $self, $params, $attributes ) = @_; > my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; >- return $self->search({}, {order_by => ['description']}) unless $branch_limit; >- return $self->search({ >- 'categories_branches.branchcode' => [$branch_limit, undef]}, >- { >- join => 'categories_branches', >- order_by => ['description'], >- } >- ); >+ if ( $branch_limit ) { >+ $params->{'categories_branches.branchcode'} = [ $branch_limit, undef ]; >+ $attributes->{join} = 'categories_branches'; >+ } >+ $attributes->{order_by} = ['description'] unless $attributes->{order_by}; >+ return $self->search($params, $attributes); > } > > =head3 type >diff --git a/circ/circulation.pl b/circ/circulation.pl >index ed00e2d..cec2a2d 100755 >--- a/circ/circulation.pl >+++ b/circ/circulation.pl >@@ -555,10 +555,9 @@ $amountold =~ s/^.*\$//; # remove upto the $, if any > my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber ); > > if ( $borrowernumber && $borrower->{'category_type'} eq 'C') { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1; >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > my $librarian_messages = Koha::Patron::Messages->search( >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/update-child.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/update-child.tt >index ccb49ce..8dcd682 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/update-child.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/update-child.tt >@@ -49,40 +49,43 @@ window.close(); > > [% IF ( MULTI ) %] > >-<h3> Choose Adult category </h3> >+ <h3> Choose Adult category </h3> > >-[% IF ( CAT_LOOP ) %] >- >-<form method="post" action="update-child.pl"> >-<fieldset> >-<table id="catst"> >-<thead> >-<tr> >-<th> </th> >-<th>Code</th> >-<th>Description</th> >-</tr> >-</thead> >-<tbody> >-[% FOREACH CAT_LOO IN CAT_LOOP %] >-<tr> >-<td> >-<input type="radio" id="catcode[% CAT_LOO.catcode %]" name="catcode" value="[% CAT_LOO.catcode %]" /></td> >-<td>[% CAT_LOO.catcode %]</td> >-<td><label for="catcode[% CAT_LOO.catcode %]"><strong>[% CAT_LOO.catdesc %]</strong></label></td> >-</tr> >-[% END %] >-</tbody> >-</table> >-<input type="hidden" name="op" value="update" /> >-<input type="hidden" name="borrowernumber" value="[% borrowernumber %]" /> >-<input type="hidden" name="catcode" value="[% catcode %]" /> >-<input type="hidden" name="cattype" value="[% cattype %]" /> >-<input type="hidden" name="catcode_multi" value="[% CATCODE_MULTI %]" /> >-<fieldset class="action"><input class="submit" type="submit" value="Submit" /> <a href="#" class="cancel close">Cancel</a></fieldset> >-[% END %] >-</fieldset> >-</form> >+ [% IF patron_categories %] >+ <form method="post" action="update-child.pl"> >+ <fieldset> >+ <table id="catst"> >+ <thead> >+ <tr> >+ <th> </th> >+ <th>Code</th> >+ <th>Description</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH patron_category IN patron_categories %] >+ <tr> >+ <td> >+ <input type="radio" id="catcode[% patron_category.categorycode %]" name="catcode" value="[% patron_category.categorycode %]" /> >+ </td> >+ <td>[% patron_category.categorycode %]</td> >+ <td><label for="catcode[% patron_category.categorycode %]"><strong>[% patron_category.description %]</strong></label></td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> >+ <input type="hidden" name="op" value="update" /> >+ <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" /> >+ <input type="hidden" name="catcode" value="[% catcode %]" /> >+ <input type="hidden" name="cattype" value="[% cattype %]" /> >+ <input type="hidden" name="catcode_multi" value="[% CATCODE_MULTI %]" /> >+ <fieldset class="action"> >+ <input class="submit" type="submit" value="Submit" /> >+ <a href="#" class="cancel close">Cancel</a> >+ </fieldset> >+ </fieldset> >+ </form> >+ [% END %] > [% END %] > > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt >index e6663ed..88cdeb0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt >@@ -154,9 +154,9 @@ function Dopop(link) { > </li> > <li> > <label for="patroncategory">Patron category: </label><select name="Filter" id="patroncategory"><option value="" > Any category code</option> >- [% FOREACH borcatloo IN borcatloop %] >- <option value="[% borcatloo.value %]" >[% borcatloo.description %] </option> >- [% END %] >+ [% FOREACH patron_category IN patron_categories%] >+ <option value="[% patron_category.categorycode %]" >[% patron_category.description %] </option> >+ [% END %] > </select> > </li> > </ol> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tt >index f9c5aa0..e269042 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tt >@@ -56,9 +56,9 @@ $(document).ready(function(){ > <fieldset class="rows"> > <ol> > <li><label for="patroncategory">Patron category: </label> <select name="Filter" id="patroncategory"><option value="" > Any category code</option> >- [% FOREACH borcatloo IN borcatloop %] >- <option value="[% borcatloo.value %]" >[% borcatloo.description %] </option> >- [% END %] >+ [% FOREACH patron_category IN patron_categories %] >+ <option value="[% patron_category.categorycode %]" >[% patron_category.description %] </option> >+ [% END %] > </select> > </li> > <li><label for="to">Not checked out since: </label> <input size="10" id="to" name="Filter" value="" type="text" /> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt >index 27d2d28..0d1fb5f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt >@@ -143,9 +143,9 @@ > </li> > <li> > <label for="patroncategory">Patron category: </label><select name="Filter" id="patroncategory"><option value="" > Any category code</option> >- [% FOREACH borcatloo IN borcatloop %] >- <option value="[% borcatloo.value %]" >[% borcatloo.description %] </option> >- [% END %] >+ [% FOREACH patron_category IN patron_categories %] >+ <option value="[% patron_category.categorycode %]" >[% patron_category.description %] </option> >+ [% END %] > </select> > </li> > <li><label for="day">Day: </label> <input type="text" name="Filter" id="day" value="" /></li> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_by_borrower_category.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_by_borrower_category.tt >index 4af5165..a07077f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_by_borrower_category.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_by_borrower_category.tt >@@ -59,8 +59,8 @@ > <label for="borrowercategory">Select a borrower category</label> > <select name="value" id="borrowercategory"> > <option value="">Any Category code</option> >- [%- FOREACH loopcategorie IN loopcategories %] >- <option value="[% loopcategorie.value %]" >[% loopcategorie.description %]</option> >+ [%- FOREACH patron_category IN patron_categories %] >+ <option value="[% patron_category.categorycode %]" >[% patron_category.description %]</option> > [%- END %] > </select> > </li> >diff --git a/members/boraccount.pl b/members/boraccount.pl >index 0b64083..7fb52b9 100755 >--- a/members/boraccount.pl >+++ b/members/boraccount.pl >@@ -34,6 +34,8 @@ use C4::Accounts; > use C4::Members::Attributes qw(GetBorrowerAttributes); > use Koha::Patron::Images; > >+use Koha::Patron::Categories; >+ > my $input=new CGI; > > >@@ -60,10 +62,9 @@ if ( $action eq 'reverse' ) { > } > > if ( $data->{'category_type'} eq 'C') { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1; >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > #get account details >diff --git a/members/mancredit.pl b/members/mancredit.pl >index c48f8cd..a4efd50 100755 >--- a/members/mancredit.pl >+++ b/members/mancredit.pl >@@ -36,6 +36,8 @@ use C4::Items; > use C4::Members::Attributes qw(GetBorrowerAttributes); > use Koha::Patron::Images; > >+use Koha::Patron::Categories; >+ > my $input=new CGI; > my $flagsrequired = { borrowers => 1, updatecharges => 1 }; > >@@ -74,10 +76,9 @@ if ($add){ > ); > > if ( $data->{'category_type'} eq 'C') { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1; >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > $template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' ); >diff --git a/members/maninvoice.pl b/members/maninvoice.pl >index 3558871..12dcb9f 100755 >--- a/members/maninvoice.pl >+++ b/members/maninvoice.pl >@@ -35,6 +35,8 @@ use C4::Branch; > use C4::Members::Attributes qw(GetBorrowerAttributes); > use Koha::Patron::Images; > >+use Koha::Patron::Categories; >+ > my $input=new CGI; > my $flagsrequired = { borrowers => 1 }; > >@@ -100,10 +102,9 @@ if ($add){ > $template->param( invoice_types_loop => \@invoice_types ); > > if ( $data->{'category_type'} eq 'C') { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1; >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' ); >diff --git a/members/member-flags.pl b/members/member-flags.pl >index 629a5c9..a956341 100755 >--- a/members/member-flags.pl >+++ b/members/member-flags.pl >@@ -16,6 +16,8 @@ use C4::Branch; > use C4::Members::Attributes qw(GetBorrowerAttributes); > #use C4::Acquisitions; > >+use Koha::Patron::Categories; >+ > use C4::Output; > use Koha::Patron::Images; > >@@ -151,10 +153,9 @@ if ($input->param('newflags')) { > } > > if ( $bor->{'category_type'} eq 'C') { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1; >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > $template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' ); >diff --git a/members/member-password.pl b/members/member-password.pl >index 64d6347..51d528e 100755 >--- a/members/member-password.pl >+++ b/members/member-password.pl >@@ -18,6 +18,8 @@ use CGI qw ( -utf8 ); > use C4::Members::Attributes qw(GetBorrowerAttributes); > use Koha::Patron::Images; > >+use Koha::Patron::Categories; >+ > use Digest::MD5 qw(md5_base64); > > my $input = new CGI; >@@ -92,11 +94,10 @@ else { > $template->param( defaultnewpassword => $defaultnewpassword ); > } > >-if ( $bor->{'category_type'} eq 'C' ) { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1; >+if ( $bor->{'category_type'} eq 'C') { >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > $template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' ); >diff --git a/members/memberentry.pl b/members/memberentry.pl >index b7e29e4..6b90322 100755 >--- a/members/memberentry.pl >+++ b/members/memberentry.pl >@@ -512,27 +512,31 @@ if(!defined($data{'sex'})){ > my @typeloop; > my $no_categories = 1; > my $no_add; >-foreach (qw(C A S P I X)) { >- my $action="WHERE category_type=?"; >- my ($categories,$labels)=GetborCatFromCatType($_,$action); >- if(scalar(@$categories) > 0){ $no_categories = 0; } >- my @categoryloop; >- foreach my $cat (@$categories){ >- push @categoryloop,{'categorycode' => $cat, >- 'categoryname' => $labels->{$cat}, >- 'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) && >- $cat eq $borrower_data->{'categorycode'}) >- || (defined($categorycode) && $cat eq $categorycode)), >- }; >- } >- my %typehash; >- $typehash{'typename'}=$_; >- my $typedescription = "typename_".$typehash{'typename'}; >- $typehash{'categoryloop'}=\@categoryloop; >- push @typeloop,{'typename' => $_, >+foreach my $category_type (qw(C A S P I X)) { >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => $category_type }, {order_by => ['categorycode']}); >+ $no_categories = 0 if $patron_categories->count > 0; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; >+ >+ my @categoryloop; >+ while ( my $patron_category = $patron_categories->next ) { >+ push @categoryloop, >+ { 'categorycode' => $patron_category->categorycode, >+ 'categoryname' => $patron_category->description, >+ 'categorycodeselected' => >+ ( ( defined( $borrower_data->{'categorycode'} ) && $patron_category->categorycode eq $borrower_data->{'categorycode'} ) || ( defined($categorycode) && $patron_category->categorycode eq $categorycode ) ), >+ }; >+ } >+ my %typehash; >+ $typehash{'typename'} = $category_type; >+ my $typedescription = "typename_" . $typehash{'typename'}; >+ $typehash{'categoryloop'} = \@categoryloop; >+ push @typeloop, >+ { 'typename' => $category_type, > $typedescription => 1, >- 'categoryloop' => \@categoryloop}; >+ 'categoryloop' => \@categoryloop >+ }; > } >+ > $template->param('typeloop' => \@typeloop, > no_categories => $no_categories); > if($no_categories){ $no_add = 1; } >diff --git a/members/moremember.pl b/members/moremember.pl >index 98286a0..6e087ad 100755 >--- a/members/moremember.pl >+++ b/members/moremember.pl >@@ -62,6 +62,7 @@ if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preferen > use DateTime; > use Koha::DateUtils; > use Koha::Database; >+use Koha::Patron::Categories; > > use vars qw($debug); > >@@ -156,11 +157,9 @@ if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) { > $data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex}; > > if ( $category_type eq 'C') { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- >- $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1; >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > my $patron = Koha::Patrons->find($data->{borrowernumber}); >diff --git a/members/pay.pl b/members/pay.pl >index 8747dfa..0d20767 100755 >--- a/members/pay.pl >+++ b/members/pay.pl >@@ -43,6 +43,8 @@ use C4::Branch; > use C4::Members::Attributes qw(GetBorrowerAttributes); > use Koha::Patron::Images; > >+use Koha::Patron::Categories; >+ > our $input = CGI->new; > > my $updatecharges_permissions = $input->param('woall') ? 'writeoff' : 'remaining_permissions'; >@@ -215,15 +217,9 @@ sub borrower_add_additional_fields { > # in a number of templates. It should not be the business of this script but in lieu of > # a revised api here it is ... > if ( $b_ref->{category_type} eq 'C' ) { >- my ( $catcodes, $labels ) = >- GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- if ( @{$catcodes} ) { >- if ( @{$catcodes} > 1 ) { >- $b_ref->{CATCODE_MULTI} = 1; >- } elsif ( @{$catcodes} == 1 ) { >- $b_ref->{catcode} = $catcodes->[0]; >- } >- } >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } elsif ( $b_ref->{category_type} eq 'A' ) { > $b_ref->{adultborrower} = 1; > } >diff --git a/members/paycollect.pl b/members/paycollect.pl >index 5dd565c..18902b6 100755 >--- a/members/paycollect.pl >+++ b/members/paycollect.pl >@@ -31,6 +31,8 @@ use C4::Koha; > use C4::Branch; > use Koha::Patron::Images; > >+use Koha::Patron::Categories; >+ > my $input = CGI->new(); > > my $updatecharges_permissions = $input->param('writeoff_individual') ? 'writeoff' : 'remaining_permissions'; >@@ -164,15 +166,9 @@ sub borrower_add_additional_fields { > # in a number of templates. It should not be the business of this script but in lieu of > # a revised api here it is ... > if ( $b_ref->{category_type} eq 'C' ) { >- my ( $catcodes, $labels ) = >- GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- if ( @{$catcodes} ) { >- if ( @{$catcodes} > 1 ) { >- $b_ref->{CATCODE_MULTI} = 1; >- } elsif ( @{$catcodes} == 1 ) { >- $b_ref->{catcode} = $catcodes->[0]; >- } >- } >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } elsif ( $b_ref->{category_type} eq 'A' ) { > $b_ref->{adultborrower} = 1; > } >diff --git a/members/printfeercpt.pl b/members/printfeercpt.pl >index 0808bba..fd3f83e 100755 >--- a/members/printfeercpt.pl >+++ b/members/printfeercpt.pl >@@ -33,6 +33,7 @@ use C4::Branch; > use C4::Accounts; > use Koha::DateUtils; > use Koha::Patron::Images; >+use Koha::Patron::Categories; > > my $input=new CGI; > >@@ -58,10 +59,9 @@ if ( $action eq 'print' ) { > } > > if ( $data->{'category_type'} eq 'C') { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1; >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > #get account details >diff --git a/members/printinvoice.pl b/members/printinvoice.pl >index 4999fbb..38ffa49 100755 >--- a/members/printinvoice.pl >+++ b/members/printinvoice.pl >@@ -32,6 +32,8 @@ use C4::Branch; > use C4::Accounts; > use Koha::Patron::Images; > >+use Koha::Patron::Categories; >+ > my $input = new CGI; > > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >@@ -52,10 +54,9 @@ my $accountlines_id = $input->param('accountlines_id'); > my $data = GetMember( 'borrowernumber' => $borrowernumber ); > > if ( $data->{'category_type'} eq 'C' ) { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1; >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > #get account details >diff --git a/members/readingrec.pl b/members/readingrec.pl >index 35a1ad4..177923e 100755 >--- a/members/readingrec.pl >+++ b/members/readingrec.pl >@@ -34,6 +34,8 @@ use Koha::DateUtils; > use C4::Members::Attributes qw(GetBorrowerAttributes); > use Koha::Patron::Images; > >+use Koha::Patron::Categories; >+ > my $input = CGI->new; > > #get borrower details >@@ -97,10 +99,9 @@ if ( $op eq 'export_barcodes' ) { > } > > if ( $data->{'category_type'} eq 'C') { >- my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my $cnt = scalar(@$catcodes); >- $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1; >- $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1; >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); >+ $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1; >+ $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1; > } > > $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' ); >diff --git a/members/update-child.pl b/members/update-child.pl >index b0a5154..5d50d93 100755 >--- a/members/update-child.pl >+++ b/members/update-child.pl >@@ -58,24 +58,14 @@ my $catcode_multi = $input->param('catcode_multi'); > my $op = $input->param('op'); > > if ( $op eq 'multi' ) { >- my ( $catcodes, $labels ) = >- # FIXME - what are the possible upgrade paths? C -> A , C -> S ... >- # currently just allowing C -> A because of limitation of API. >- GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); >- my @rows; >- foreach my $k ( keys %$labels ) { >- my $row; >- $row->{catcode} = $k; >- $row->{catdesc} = $labels->{$k}; >- my $borcat = Koha::Patron::Categories->find($row->{catcode}); >- $row->{cattype} = $borcat->category_type; >- push @rows, $row; >- } >+ # FIXME - what are the possible upgrade paths? C -> A , C -> S ... >+ # currently just allowing C -> A >+ my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); > $template->param( >- MULTI => 1, >- CATCODE_MULTI => 1, >- borrowernumber => $borrowernumber, >- CAT_LOOP => \@rows, >+ MULTI => 1, >+ CATCODE_MULTI => 1, >+ borrowernumber => $borrowernumber, >+ patron_categories => $patron_categories, > ); > output_html_with_http_headers $input, $cookie, $template->output; > } >diff --git a/reports/bor_issues_top.pl b/reports/bor_issues_top.pl >index 0345a32..1e1dcfd 100755 >--- a/reports/bor_issues_top.pl >+++ b/reports/bor_issues_top.pl >@@ -29,7 +29,9 @@ use C4::Circulation; > use C4::Members; > use C4::Reports; > use C4::Debug; >+ > use Koha::DateUtils; >+use Koha::Patron::Categories; > > =head1 NAME > >@@ -37,8 +39,6 @@ plugin that shows a stats on borrowers > > =head1 DESCRIPTION > >-=over 2 >- > =cut > > $debug = 1; >@@ -129,22 +129,15 @@ foreach (sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}-> > ); > push @itemtypeloop, \%row; > } >- >-my ($codes,$labels) = GetborCatFromCatType(undef,undef); >-my @borcatloop; >-foreach (sort keys %$labels) { >- my %row =(value => $_, >- description => $labels->{$_}, >- ); >- push @borcatloop, \%row; >-} >- >+ >+my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']}); >+ > $template->param( > mimeloop => \@mime, > CGIseplist => $delims, > branchloop => \@branchloop, > itemtypeloop => \@itemtypeloop, >- borcatloop => \@borcatloop, >+patron_categories => $patron_categories, > ); > output_html_with_http_headers $input, $cookie, $template->output; > >diff --git a/reports/borrowers_out.pl b/reports/borrowers_out.pl >index eeb7fb3..50c73b0 100755 >--- a/reports/borrowers_out.pl >+++ b/reports/borrowers_out.pl >@@ -28,7 +28,9 @@ use C4::Output; > use C4::Circulation; > use C4::Reports; > use C4::Members; >+ > use Koha::DateUtils; >+use Koha::Patron::Categories; > > =head1 NAME > >@@ -116,19 +118,12 @@ if ($do_it) { > > my $CGIextChoice = ( 'CSV' ); # FIXME translation > my $CGIsepChoice = GetDelimiterChoices; >- >- my ($codes,$labels) = GetborCatFromCatType(undef,undef); >- my @borcatloop; >- foreach my $thisborcat (sort keys %$labels) { >- my %row =(value => $thisborcat, >- description => $labels->{$thisborcat}, >- ); >- push @borcatloop, \%row; >- } >+ >+ my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']}); > $template->param( > CGIextChoice => $CGIextChoice, > CGIsepChoice => $CGIsepChoice, >- borcatloop =>\@borcatloop, >+ patron_categories => $patron_categories, > ); > output_html_with_http_headers $input, $cookie, $template->output; > } >diff --git a/reports/cat_issues_top.pl b/reports/cat_issues_top.pl >index 949afb7..ce7eded 100755 >--- a/reports/cat_issues_top.pl >+++ b/reports/cat_issues_top.pl >@@ -154,18 +154,8 @@ if ($do_it) { > > @shelvinglocloop = sort {$a->{value} cmp $b->{value}} @shelvinglocloop; > >- #borcat >- my ($codes,$labels) = GetborCatFromCatType(undef,undef); >- my @borcatloop; >- foreach my $thisborcat (sort {$labels->{$a} cmp $labels->{$b}} keys %$labels) { >- my %row =(value => $thisborcat, >- description => $labels->{$thisborcat}, >- ); >- push @borcatloop, \%row; >- } >- >- #Day >- #Month >+ my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']}); >+ > $template->param( > CGIextChoice => $CGIextChoice, > CGIsepChoice => $CGIsepChoice, >@@ -173,7 +163,7 @@ if ($do_it) { > itemtypeloop =>\@itemtypeloop, > ccodeloop =>\@ccodeloop, > shelvinglocloop =>\@shelvinglocloop, >- borcatloop =>\@borcatloop, >+ patron_categories => $patron_categories, > ); > output_html_with_http_headers $input, $cookie, $template->output; > } >diff --git a/reports/issues_by_borrower_category.plugin b/reports/issues_by_borrower_category.plugin >index ad8b166..060d345 100755 >--- a/reports/issues_by_borrower_category.plugin >+++ b/reports/issues_by_borrower_category.plugin >@@ -29,6 +29,8 @@ use C4::Members; > > use C4::Branch; # GetBranches > >+use Koha::Patron::Categories; >+ > =head1 NAME > > plugin that shows a table with issues for categories and borrower >@@ -65,16 +67,9 @@ sub set_parameters { > my ($template) = @_; > > $template->param( branchloop => GetBranchesLoop() ); >- >- my ($codes,$labels)=GetborCatFromCatType(undef,undef); >- my @borcatloop; >- foreach my $thisborcat (sort keys %$labels) { >- push @borcatloop, { >- value => $thisborcat, >- description => $labels->{$thisborcat}, >- }; >- } >- $template->param(loopcategories => \@borcatloop); >+ >+ my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']}); >+ $template->param( patron_categories => $patron_categories ); > return $template; > } > >diff --git a/t/db_dependent/Koha/Patron/Categories.t b/t/db_dependent/Koha/Patron/Categories.t >index 8d87e1e..b82f190 100644 >--- a/t/db_dependent/Koha/Patron/Categories.t >+++ b/t/db_dependent/Koha/Patron/Categories.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 9; >+use Test::More tests => 11; > > use C4::Context; > use Koha::Database; >@@ -35,11 +35,13 @@ my $branch = $builder->build({ source => 'Branch', }); > my $nb_of_categories = Koha::Patron::Categories->search->count; > my $new_category_1 = Koha::Patron::Category->new({ > categorycode => 'mycatcodeX', >+ category_type => 'A', > description => 'mycatdescX', > })->store; > $new_category_1->add_branch_limitation( $branch->{branchcode} ); > my $new_category_2 = Koha::Patron::Category->new({ > categorycode => 'mycatcodeY', >+ category_type => 'S', > description => 'mycatdescY', > })->store; > >@@ -55,6 +57,7 @@ C4::Context->_new_userenv('my_new_userenv'); > C4::Context->set_userenv( 0, 0, 'usercnum', 'firstname', 'surname', $another_branch->{branchcode}, 'My wonderful library', '', '', '' ); > my $new_category_3 = Koha::Patron::Category->new( > { categorycode => 'mycatcodeZ', >+ category_type => 'A', > description => 'mycatdescZ', > } > )->store; >@@ -66,6 +69,11 @@ is( scalar( grep { $_ eq $new_category_1->categorycode } @limited_category_codes > is( scalar( grep { $_ eq $new_category_2->categorycode } @limited_category_codes ), 1, 'The second category is not limited' ); > is( scalar( grep { $_ eq $new_category_3->categorycode } @limited_category_codes ), 1, 'The third category is limited to my branch ' ); > >+my @limited_categories_for_A = Koha::Patron::Categories->search_limited({ category_type => 'A' }); >+my @limited_category_codes_for_A = map { $_->categorycode } @limited_categories_for_A; >+is( scalar( grep { $_ eq $new_category_2->categorycode } @limited_category_codes_for_A ), 0, 'The second category is not limited but has a category_type S' ); >+is( scalar( grep { $_ eq $new_category_3->categorycode } @limited_category_codes_for_A ), 1, 'The third category is limited to my branch and has a category_type A' ); >+ > $retrieved_category_1->delete; > is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'Delete should have deleted the patron category' ); > >-- >2.8.1
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 15407
:
45906
|
45907
|
45908
|
45909
|
45910
|
45913
|
45914
|
47098
|
47099
|
47100
|
47101
|
47102
|
47646
|
47647
|
47648
|
47649
|
47650
|
47754
|
47755
|
47756
|
47757
|
47758
|
50170
|
50171
|
50172
|
50173
|
50174
|
52013
|
52014
|
52015
|
52032
|
52033
|
52034
|
52035
|
52036
|
53419
|
53420
|
53421
|
53422
|
53423
|
53892
|
54342
|
54343
|
54344
|
54345
|
54346
|
54352
|
54353
|
54355
|
54361
|
54362
|
54363
|
54364
|
54365
|
54366
|
54367
|
54368
|
54369
|
54371
|
55517