From f8a1e5e4d9577194972c67e6ee38bef2493a2b51 Mon Sep 17 00:00:00 2001 From: Martin Stenberg 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 %]
  • Category: [% categoryname %] ([% categorycode %])
  • + [% IF additionalcategories %] +
  • Additional categories: [% additionalcategories.join(', ') %]
  • + [% END %]
  • Home library: [% IF ( branchname ) %][% branchname %][% ELSE %][% branch %][% END %]