Bugzilla – Attachment 44762 Details for
Bug 15174
Allow borrowers to be members of additional categories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15174: Member of multiple categories
Bug-15174-Member-of-multiple-categories.patch (text/plain), 15.05 KB, created by
Martin Stenberg
on 2015-11-11 14:17:18 UTC
(
hide
)
Description:
Bug 15174: Member of multiple categories
Filename:
MIME Type:
Creator:
Martin Stenberg
Created:
2015-11-11 14:17:18 UTC
Size:
15.05 KB
patch
obsolete
>From f8a1e5e4d9577194972c67e6ee38bef2493a2b51 Mon Sep 17 00:00:00 2001 >From: Martin Stenberg <martin@xinxidi.net> >Date: Tue, 10 Nov 2015 20:08:05 +0100 >Subject: [PATCH] Bug 15174: Member of multiple categories > >This patch makes it possible for borrowers to be members of more than one >category. On checkout, librarian can choose which category to do checkout as. > >Test plan: > > 1. Apply this patch > 2. Run updatedatabase.pl > 3. Log in to staff client and modify a patron > 4. Under "Library managenet" a new field "Additional categories" should be > visible > 5. Select one or more additional catogaries for the patron > 6. Save > 7. Make a checkout for the modified patron > 8. A new dropdown box labled "Choose category for this checkout:" should be > visible on the checkout page > 9. Choose one of the additional categories in the dropdown box and checkout > 10.Confirm that appropriet circulation rules for the category was applied to > the checkout > >Sponsored-by: Halland County Library >--- > C4/Members.pm | 59 +++++++++++++++++++++- > circ/circulation.pl | 10 ++++ > .../bug_15174-additional-categories.sql | 9 ++++ > .../intranet-tmpl/prog/en/includes/circ-menu.inc | 3 ++ > .../prog/en/modules/circ/circulation.tt | 10 ++++ > .../en/modules/circ/circulation_batch_checkouts.tt | 15 ++++++ > .../prog/en/modules/members/memberentrygen.tt | 32 ++++++++++++ > members/memberentry.pl | 10 +++- > 8 files changed, 145 insertions(+), 3 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_15174-additional-categories.sql > >diff --git a/C4/Members.pm b/C4/Members.pm >index 9507b9f..1f53782 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -191,7 +191,6 @@ the value "1". > sub GetMemberDetails { > my ( $borrowernumber, $cardnumber ) = @_; > my $dbh = C4::Context->dbh; >- my $query; > my $sth; > if ($borrowernumber) { > $sth = $dbh->prepare(" >@@ -252,6 +251,16 @@ sub GetMemberDetails { > $borrower->{'showname'} = $borrower->{'firstname'}; > } > >+ # fetch and add additional categories >+ my $query = ' >+ SELECT * FROM categories_additional >+ WHERE borrowernumber = ? >+ '; >+ $sth = $dbh->prepare($query); >+ $sth->execute( $borrower->{'borrowernumber'} ); >+ my @cats = map { $_->{'categorycode'} } @{ $sth->fetchall_arrayref( {} ) }; >+ $borrower->{'additionalcategories'} = \@cats; >+ > # Handle setting the true behavior for BlockExpiredPatronOpacActions > $borrower->{'BlockExpiredPatronOpacActions'} = > C4::Context->preference('BlockExpiredPatronOpacActions') >@@ -462,7 +471,18 @@ sub GetMember { > my $data = $sth->fetchall_arrayref({}); > #FIXME interface to this routine now allows generation of a result set > #so whole array should be returned but bowhere in the current code expects this >- if (@{$data} ) { >+ if ( @{$data} ) { >+ >+ # fetch and add additional categories >+ $select = ' >+ SELECT * FROM categories_additional >+ WHERE borrowernumber = ? >+ '; >+ $sth = $dbh->prepare($select); >+ $sth->execute( $data->[0]->{'borrowernumber'} ); >+ my @cats = map { $_->{'categorycode'} } @{ $sth->fetchall_arrayref( {} ) }; >+ $data->[0]->{'additionalcategories'} = \@cats; >+ > return $data->[0]; > } > >@@ -644,6 +664,7 @@ true on success, or false on failure > > sub ModMember { > my (%data) = @_; >+ my $dbh = C4::Context->dbh; > # test to know if you must update or not the borrower password > if (exists $data{password}) { > if ($data{password} eq '****' or $data{password} eq '') { >@@ -663,6 +684,7 @@ sub ModMember { > my @columns = $schema->source('Borrower')->columns; > my $new_borrower = { map { join(' ', @columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) }; > delete $new_borrower->{flags}; >+ delete $new_borrower->{additionalcategories}; > > $new_borrower->{dateofbirth} ||= undef if exists $new_borrower->{dateofbirth}; > $new_borrower->{dateenrolled} ||= undef if exists $new_borrower->{dateenrolled}; >@@ -708,6 +730,25 @@ sub ModMember { > NLSync({ 'borrowernumber' => $data{'borrowernumber'} }); > } > >+ # Update additional categories >+ my $query = ' >+ DELETE FROM categories_additional >+ WHERE borrowernumber = ? >+ '; >+ my $sth = $dbh->prepare($query); >+ $sth->execute($data{'borrowernumber'}); >+ if ( @{ $data{'additionalcategories'} } ) { >+ $query = ' >+ INSERT INTO categories_additional >+ ( categorycode, borrowernumber ) >+ VALUES ( ?, ? ) >+ '; >+ $sth = $dbh->prepare($query); >+ for my $cat ( @{ $data{'additionalcategories'} } ) { >+ $sth->execute( $cat, $data{'borrowernumber'} ); >+ } >+ } >+ > logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog"); > } > return $execute_success; >@@ -769,6 +810,7 @@ sub AddMember { > my @columns = $schema->source('Borrower')->columns; > my $new_member = { map { join(' ',@columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) } ; > delete $new_member->{borrowernumber}; >+ delete $new_member->{additionalcategories}; > > my $rs = $schema->resultset('Borrower'); > $data{borrowernumber} = $rs->create($new_member)->id; >@@ -785,6 +827,19 @@ sub AddMember { > }); > } > >+ # Add additional categories >+ if ( @{ $data{'additionalcategories'} } ) { >+ my $query = ' >+ INSERT INTO categories_additional >+ ( categorycode, borrowernumber ) >+ VALUES ( ?, ? ) >+ '; >+ my $sth = $dbh->prepare($query); >+ for my $cat ( @{ $data{'additionalcategories'} } ) { >+ $sth->execute( $cat, $data{borrowernumber} ); >+ } >+ } >+ > # mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best. > logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog"); > >diff --git a/circ/circulation.pl b/circ/circulation.pl >index c8e7872..cc29608 100755 >--- a/circ/circulation.pl >+++ b/circ/circulation.pl >@@ -235,6 +235,8 @@ if ( $print eq 'yes' && $borrowernumber ne '' ) { > $borrowernumber = ''; > } > >+my $category = $query->param('category'); >+ > # > # STEP 2 : FIND BORROWER > # if there is a list of find borrowers.... >@@ -329,12 +331,20 @@ if ($borrowernumber) { > > } > >+my %cats; >+map {$cats{$_->{categorycode}} = $_} @{GetBorrowercategoryList()}; >+$template->param(categories => \%cats); >+ > # > # STEP 3 : ISSUING > # > # > if (@$barcodes) { > my $checkout_infos; >+ >+ # set session category >+ $borrower->{categorycode} = $category if $category; >+ > for my $barcode ( @$barcodes ) { > my $template_params = { barcode => $barcode }; > # always check for blockers on issuing >diff --git a/installer/data/mysql/atomicupdate/bug_15174-additional-categories.sql b/installer/data/mysql/atomicupdate/bug_15174-additional-categories.sql >new file mode 100644 >index 0000000..bc90d5a >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_15174-additional-categories.sql >@@ -0,0 +1,9 @@ >+DROP TABLE IF EXISTS `categories_additional`; >+CREATE TABLE `categories_additional` ( -- association table between categories and borrowers >+ `id` int(11) NOT NULL auto_increment, >+ `categorycode` varchar(10) NOT NULL default '', >+ `borrowernumber` int(11) NOT NULL, >+ PRIMARY KEY (`id`), >+ CONSTRAINT `categories_additional_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE, >+ CONSTRAINT `categories_additional_ibfk_2` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE >+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc >index 9137efb..dbac54a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc >@@ -59,6 +59,9 @@ > [% END %] > [% END %][% END %] > <li class="patroncategory">Category: [% categoryname %] ([% categorycode %])</li> >+ [% IF additionalcategories %] >+ <li class="patronadditionalcategory">Additional categories: [% additionalcategories.join(', ') %]</li> >+ [% END %] > <li class="patronlibrary">Home library: [% IF ( branchname ) %][% branchname %][% ELSE %][% branch %][% END %]</li> > </ul></div> > <div id="menu"> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >index 07ef6ce..790e4a2 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >@@ -651,6 +651,16 @@ No patron matched <span class="ex">[% message %]</span> > [% END %] > [% END %] > >+ [% IF additionalcategories %] >+ <div class="hint">Choose category for this checkout:</div> >+ <select name="category"> >+ <option value="[% categorycode %]">[% categories.$categorycode.description %]</option> >+ [% FOR cat IN additionalcategories %] >+ <option value="[% cat %]">[% categories.$cat.description %]</option> >+ [% END %] >+ </select> >+ [% END %] >+ > [% IF Koha.Preference('OnSiteCheckouts') %] > <div class="onsite_checkout-select"> > [% IF noissues %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation_batch_checkouts.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation_batch_checkouts.tt >index 4e392d2..79154a0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation_batch_checkouts.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation_batch_checkouts.tt >@@ -73,6 +73,21 @@ $(document).ready(function() { > </li> > </ol> > </fieldset> >+ [% IF additionalcategories %] >+ <fieldset class="rows"> >+ <ol> >+ <li> >+ <label for="barcodelist">Choose category for this checkout:</label> >+ <select name="category"> >+ <option value="[% categorycode %]">[% categories.$categorycode.description %]</option> >+ [% FOR cat IN additionalcategories %] >+ <option value="[% cat %]">[% categories.$cat.description %]</option> >+ [% END %] >+ </select> >+ </li> >+ </ol> >+ </fieldset> >+ [% END %] > <input type="hidden" name="op" value="show" /> > <fieldset class="action"> > <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" /> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >index a3b7a9d..8e4e45e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >@@ -25,6 +25,7 @@ > document.form.country.value=RegExp.$4; > }); > >+ > [% IF categorycode %] > update_category_code( "[% categorycode %]" ); > [% ELSE %] >@@ -104,6 +105,12 @@ > if ( $(category_code).is("select") ) { > category_code = $("#categorycode_entry").find("option:selected").val(); > } >+ >+ $("#additionalcategories_entry").find('option').removeAttr('disabled'); >+ $("#additionalcategories_entry") >+ .find('option[value="'+category_code+'"]') >+ .attr('disabled', 'disabled'); >+ > var mytables = $(".attributes_table"); > $(mytables).find("li").hide(); > $(mytables).find(" li[data-category_code='"+category_code+"']").show(); >@@ -670,6 +677,31 @@ > </select> > <span class="required">Required</span> > </li> >+ <li> >+ <label for="additionalcategories_entry" class="required">Additonal categories: </label> >+ <select multiple id="additionalcategories_entry" name="additionalcategories"> >+ [% FOREACH typeloo IN typeloop %] >+ [% FOREACH categoryloo IN typeloo.categoryloop %] >+ [% IF ( loop.first ) %] >+ [% IF ( typeloo.typename_C ) %]<optgroup label="Child">[% END %] >+ [% IF ( typeloo.typename_A ) %]<optgroup label="Adult">[% END %] >+ [% IF ( typeloo.typename_S ) %]<optgroup label="Staff">[% END %] >+ [% IF ( typeloo.typename_I ) %]<optgroup label="Organization">[% END %] >+ [% IF ( typeloo.typename_P ) %]<optgroup label="Professional">[% END %] >+ [% IF ( typeloo.typename_X ) %]<optgroup label="Statistical">[% END %] >+ [% END %] >+ [% IF additionalcategories.grep("^$categoryloo.categorycode\$").size %] >+ <option value="[% categoryloo.categorycode %]" selected="selected" data-typename="[% typeloo.typename %]">[% categoryloo.categoryname %]</option> >+ [% ELSE %] >+ <option value="[% categoryloo.categorycode %]" data-typename="[% typeloo.typename %]">[% categoryloo.categoryname %]</option> >+ [% END %] >+ [% IF ( loop.last ) %] >+ </optgroup> >+ [% END %] >+ [% END %] >+ [% END %] >+ </select> >+ </li> > [% UNLESS nosort1 %] > <li> > [% IF ( mandatorysort1 ) %] >diff --git a/members/memberentry.pl b/members/memberentry.pl >index ba705a5..8ac022d 100755 >--- a/members/memberentry.pl >+++ b/members/memberentry.pl >@@ -144,6 +144,7 @@ $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 ); > ( $borrower_data = GetMember( 'borrowernumber' => $borrowernumber ) ) if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' ); > my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'}; > my $category_type = $input->param('category_type') || ''; >+ > unless ($category_type or !($categorycode)){ > my $borrowercategory = GetBorrowercategory($categorycode); > $category_type = $borrowercategory->{'category_type'}; >@@ -160,7 +161,11 @@ my %newdata; > if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) { > my @names = ( $borrower_data && $op ne 'save' ) ? keys %$borrower_data : $input->param(); > foreach my $key (@names) { >- if (defined $input->param($key)) { >+ if ( $key eq 'additionalcategories' ) { >+ my @acats = $input->multi_param('additionalcategories'); >+ $newdata{$key} = \@acats; >+ } >+ elsif ( defined $input->param($key) ) { > $newdata{$key} = $input->param($key); > $newdata{$key} =~ s/\"/"/g unless $key eq 'borrowernotes' or $key eq 'opacnote'; > } >@@ -530,6 +535,9 @@ foreach (qw(C A S P I X)) { > $template->param('typeloop' => \@typeloop, > no_categories => $no_categories); > if($no_categories){ $no_add = 1; } >+ >+$template->param( additionalcategories => $data{'additionalcategories'}); >+ > # test in city > if ( $guarantorid ) { > $select_city = getidcity($data{city}); >-- >2.6.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 15174
: 44762