Extending the handlers
authorChris Cormack <chrisc@catalyst.net.nz>
Sun, 12 Jan 2014 20:59:06 +0000 (09:59 +1300)
committerChris Cormack <chrisc@catalyst.net.nz>
Sun, 12 Jan 2014 20:59:06 +0000 (09:59 +1300)
lib/NCIP/Handler/CheckInItem.pm
lib/NCIP/Handler/CheckOutItem.pm
lib/NCIP/Handler/RenewItem.pm [new file with mode: 0644]
lib/NCIP/ILS/Koha.pm

index 2656f68..ab8b255 100644 (file)
@@ -35,9 +35,9 @@ sub handle {
         $vars->{'messagetype'} = 'CheckInItemResponse';
         $vars->{'barcode'} = $itemid;
         if ( !$checkin->{success} ) {
-            $var->{'processingerror'} = 1;
-            $var->{'processingerrortype'} = $checkin->{'messages'};
-            $var->{'processingerrorelement'} = 'UniqueItemIdentifier';
+            $vars->{'processingerror'} = 1;
+            $vars->{'processingerrortype'} = $checkin->{'messages'};
+            $vars->{'processingerrorelement'} = 'UniqueItemIdentifier';
             $output = $self->render_output( 'problem.tt', $vars );
         }
         else {
index d92e579..4c40a9f 100644 (file)
@@ -31,12 +31,22 @@ sub handle {
         my @elements = $root->findnodes('CheckOutItem/ItemElementType/Value');
 
         # checkout the item
-        my $checkout = $self->ils->checkout( $userid, $itemid );
+        my ( $error, $messages ) = $self->ils->checkout( $userid, $itemid );
         my $vars;
+        my $output;
+        my $vars->{'barcode'}=$itemid;
         $vars->{'messagetype'} = 'CheckOutItemResponse';
-        $vars->{'elements'}    = \@elements;
-        $vars->{'checkout'}    = $checkout;
-        my $output = $self->render_output( 'response.tt', $vars );
+        if ($error) {
+            $vars->{'processingerror'}        = 1;
+            $vars->{'processingerrortype'}    = $messages;
+            $vars->{'processingerrorelement'} = 'UniqueItemIdentifier';
+            $output = $self->render_output( 'problem.tt', $vars );
+        }
+        else {
+            $vars->{'elements'} = \@elements;
+
+            $output = $self->render_output( 'response.tt', $vars );
+        }
         return $output;
     }
 }
diff --git a/lib/NCIP/Handler/RenewItem.pm b/lib/NCIP/Handler/RenewItem.pm
new file mode 100644 (file)
index 0000000..91a9c8a
--- /dev/null
@@ -0,0 +1,53 @@
+package NCIP::Handler::RenewItem;
+
+=head1
+
+  NCIP::Handler::RenewItem
+
+=head1 SYNOPSIS
+
+    Not to be called directly, NCIP::Handler will pick the appropriate Handler 
+    object, given a message type
+
+=head1 FUNCTIONS
+
+=cut
+
+use Modern::Perl;
+
+use NCIP::Handler;
+
+our @ISA = qw(NCIP::Handler);
+
+sub handle {
+    my $self   = shift;
+    my $xmldoc = shift;
+    if ($xmldoc) {
+        my $root = $xmldoc->documentElement();
+        my $itemid =
+          $root->findnodes('RenewItem/UniqueItemId/ItemIdentifierValue');
+        my @elements = $root->findnodes('RenewItem/ItemElementType/Value');
+
+        # checkin the item
+        my $renewed = $self->ils->renew( $itemid );
+        my $output;
+        my $vars;
+        $vars->{'messagetype'} = 'RenewItemResponse';
+        $vars->{'barcode'} = $itemid;
+        if ( !$checkin->{success} ) {
+            $vars->{'processingerror'} = 1;
+            $vars->{'processingerrortype'} = $checkin->{'messages'};
+            $vars->{'processingerrorelement'} = 'UniqueItemIdentifier';
+            $output = $self->render_output( 'problem.tt', $vars );
+        }
+        else {
+
+            $vars->{'elements'} = \@elements;
+            $vars->{'checkin'}  = $checkin;
+            $output = $self->render_output( 'response.tt', $vars );
+        }
+        return $output;
+    }
+}
+
+1;
index 38a4342..c6bc05a 100644 (file)
@@ -43,6 +43,20 @@ sub checkin {
 }
 
 sub checkout {
+    my $self = shift;
+    my $userid = shift;
+    my $barcode = shift;
+    my ($error, $confirm) = CanBookBeIssued ( $userid, $barcode );
+    #( $issuingimpossible, $needsconfirmation ) =  CanBookBeIssued( $borrower, 
+    #                      $barcode, $duedatespec, $inprocess, $ignore_reserves );
+    if ($error) { # plus the confirmation?
+# Can't issue item, return error hash
+        return ( 1, $error);
+    }
+    else {
+        AddIssue($userid,$barcode);
+        return ( 0 );
+    }
 }
 
 1;