From bff6c46bd51b8e294e216d94599c407889f3c67a Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Thu, 8 Sep 2011 17:26:58 -0400 Subject: [PATCH] Add an API for generating barcodes Add a custom API to open-ils.actor for generating barcodes; accepts one argument, user ID, which gets the barcode set to their new value. If no arg is passed, just generates a new barcode and returns it (should be useful on the patron editor screen). Signed-off-by: Dan Scott --- .../src/perlmods/lib/OpenILS/Application/Actor.pm | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index d6de3db29a..170b129f65 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -4610,7 +4610,6 @@ sub mark_users_contact_invalid { # phone number (or staff manually delete the penalty). my $contact_type = ($self->api_name =~ /invalidate.(\w+)(\.|$)/)[0]; - my $e = new_editor(authtoken => $auth, xact => 1); return $e->die_event unless $e->checkauth; @@ -4620,6 +4619,47 @@ sub mark_users_contact_invalid { ); } +__PACKAGE__->register_method( + method => "generate_patron_barcode", + api_name => "open-ils.actor.generate_patron_barcode", + signature => { + desc => "Generates a new patron barcode. If a user ID is supplied," . + "that user's card will be updated to point at the new barcode." , + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'User ID', type => 'number'}, + ], + return => {desc => 'Generated barcode on success'} + } +); + +# evergreen.lu_update_barcode(user-id) generates a barcode, creates an actor.card +# object, and points actor.usr.card to the new actor.card.id +# +# evergreen.lu_generate_barcode() just generates a barcode +sub generate_patron_barcode { + + my( $self, $client, $auth, $user_id ) = @_; + + my $e = new_editor( authtoken=>$auth ); + return $e->die_event unless $e->checkauth; + + my $barcode; + if ($user_id) { + return $e->die_event unless $e->allowed('UPDATE_USER'); + $barcode = $e->json_query( + {from => ['evergreen.lu_update_barcode', $user_id]})->[0] + or return $e->die_event; + } else { + $barcode = $e->json_query( + {from => ['evergreen.lu_generate_barcode']})->[0] + or return $e->die_event; + } + + return $barcode; +} + + # Putting the following method in open-ils.actor is a bad fit, except in that # it serves an interface that lives under 'actor' in the templates directory, # and in that there's nowhere else obvious to put it (open-ils.trigger is -- 2.11.0