Utility method for turning the output of a detail request into xml -- just a start... collections-have_balance_api
authorMike Rylander <mrylander@gmail.com>
Tue, 10 Apr 2012 20:30:30 +0000 (16:30 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 10 Apr 2012 20:30:30 +0000 (16:30 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm

index e5da73c..1fe3992 100644 (file)
@@ -11,6 +11,8 @@ use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Event;
 use OpenILS::Const qw/:const/;
 my $U = "OpenILS::Application::AppUtils";
+use XML::LibXML;
+use Scalar::Util 'blessed';
 
 
 # --------------------------------------------------------------
@@ -788,6 +790,44 @@ sub transaction_details {
        return \@data;
 }
 
+sub detailToXML {
+    my $data = shift;
+
+    my $dom = XML::LibXML::Document->new;
+    my $root = $dom->createElement( 'Collections' );
+    $dom->setDocumentElement( $root );
+
+    for my $row (@$data) {
+        my $blob = $dom->createElement( 'User' );
+        $root->appendChild( $blob );
+
+        my $node = $row->{usr}->toXML;
+        next unless $node;
+
+        $node = $node->documentElement;
+        $dom->adoptNode( $node );
+        $blob->appendNode( $node );
+
+        my $trans = $dom->createElement( 'Transactions' );
+        $blob->appendChild( $trans );
+
+               for my $xact ( 
+                       @{$row->{transactions}->{circulations}}, 
+                       @{$row->{transactions}->{reservations}}, 
+                       @{$row->{transactions}->{grocery}} ) {
+
+            $node = $xact->toXML;
+            next unless $node;
+
+            $node = $node->documentElement;
+            $dom->adoptNode( $node );
+            $trans->appendNode( $node );
+        }
+    }
+
+    return $dom;
+}
+
 sub flesh_payment {
        my $e = shift;
        my $p = shift;