Teach Marque.pm to use the from_bare_hash Fieldmapper method.
authorJason Stephenson <jstephenson@mvlc.org>
Thu, 26 Sep 2013 00:34:17 +0000 (20:34 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Tue, 1 Oct 2013 16:56:49 +0000 (12:56 -0400)
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/support-scripts/Marque.pm.in

index 50fc8c9..89be632 100644 (file)
@@ -357,7 +357,7 @@ sub build_query {
     # Now we build the query in pieces:
 
     # We always select the bre fields:
-    my $select = 'select ' . join(',', @breFields);
+    my $select = 'select distinct ' . join(',', @breFields);
     # We always use the bre table.
     my $from = "from $breTable";
 
@@ -415,9 +415,9 @@ sub next {
     my $self = shift;
     my $output;
 
-    my @data = $self->{sth}->fetchrow_array;
-    if (@data) {
-        my $bre = $self->{breClass}->new(\@data);
+    my $data = $self->{sth}->fetchrow_hashref;
+    if ($data) {
+        my $bre = $self->{breClass}->from_bare_hash($data);
         if ($Marque::config->option_value('format') eq 'BRE') {
             $output = OpenSRF::Utils::JSON->perl2JSON($bre);
         } else {
@@ -472,7 +472,7 @@ sub next {
                             ($location ? ('a' => $location) : ()),
                             b => $acp->call_number()->owning_lib()->shortname(),
                             b => $acp->circ_lib()->shortname(),
-                            c => $acp->copy_location()->name(),
+                            c => $acp->location()->name(),
                             j => $acp->call_number()->label(),
                             ($acp->circ_modifier() ? (g => $acp->circ_modifier()) : ()),
                             p => $acp->barcode(),
@@ -509,8 +509,8 @@ sub orgs {
         $query .= "\nfrom $classTable";
         my $sth = $self->{handle}->prepare($query);
         if ($sth->execute()) {
-            my $result = $sth->fetchall_arrayref();
-            my @orgs = map {$fmClass->new($_)} @{$result};
+            my $result = $sth->fetchall_arrayref({});
+            my @orgs = map {$fmClass->from_bare_hash($_)} @{$result};
             $self->{orgs} = \@orgs;
         } else {
             $self->{orgs} = [];
@@ -529,8 +529,8 @@ sub shelves {
         my $classTable = $fmClass->Table();
         my $query = 'select ' . join(',', @classFields);
         $query .= "\nfrom $classTable";
-        my $result = $self->{handle}->selectall_arrayref($query);
-        my @shelves = map {$fmClass->new($_)} @{$result};
+        my $result = $self->{handle}->selectall_arrayref($query, {Slice=>{}});
+        my @shelves = map {$fmClass->from_bare_hash($_)} @{$result};
         $self->{shelves} = \@shelves;
     }
 
@@ -555,8 +555,8 @@ sub acns_for_bre {
     }
 
     if ($self->{acnHandle}->execute($bre)) {
-        my $result = $self->{acnHandle}->fetchall_arrayref();
-        return map {$self->{acnClass}->new($_)} @{$result};
+        my $result = $self->{acnHandle}->fetchall_arrayref({});
+        return map {$self->{acnClass}->from_bare_hash($_)} @{$result};
     }
 
     # If for some reason, we don't find anything.
@@ -579,13 +579,13 @@ sub acps_for_bre {
         $query .= "\nwhere deleted = 'f' and call_number in (";
         $query .= join(',', map {$_->id()} @acns);
         $query .= ")";
-        my $result = $self->{handle}->selectall_arrayref($query);
+        my $result = $self->{handle}->selectall_arrayref($query, {Slice=>{}});
         if ($result && @{$result}) {
-            my @acps = map {$self->{acpClass}->new($_)} @{$result};
-            return map {
+            my @acps = map {$self->{acpClass}->from_bare_hash($_)} @{$result};
+            foreach (@acps) {
                 my $cn = $_->call_number();
                 my $clib = $_->circ_lib();
-                my $loc = $_->copy_loaction();
+                my $loc = $_->location();
                 my ($org) = grep {$_->id() == $clib} @orgs;
                 my ($acn) = grep {$_->id() == $cn} @acns;
                 my ($location) = grep {$_->id() == $loc} @locations;
@@ -594,8 +594,9 @@ sub acps_for_bre {
                 $acn->owning_lib($owner);
                 $_->call_number($acn);
                 $_->circ_lib($org);
-                $_->copy_location($location);
-            } @acps;
+                $_->location($location);
+            }
+            return @acps;
         }
     }
 
@@ -656,11 +657,11 @@ sub execute_query {
 sub next {
     my $self = shift;
     my $output;
-    my @data = $self->{sth}->fetchrow_array;
+    my $data = $self->{sth}->fetchrow_hashref;
 
-    if (@data) {
+    if ($data) {
         my $format = $Marque::config->option_value('format');
-        my $are = $self->{fmClass}->new(\@data);
+        my $are = $self->{fmClass}->from_bare_hash($data);
         if ($format eq 'ARE') {
             $output = OpenSRF::Utils::JSON->perl2JSON($are);
         } else {