delete $args->{embed};
}
- my $requests = Koha::Illrequests->unblessed;
+ # Get all requests
+ my @requests = Koha::Illrequests->as_list;
# Identify patrons & branches that
# we're going to need and get them
- my $to_fetch = {};
- $to_fetch->{patrons} = {} if $embed{patron};
- $to_fetch->{branches} = {} if $embed{library};
- $to_fetch->{capabilities} = {} if $embed{capabilities};
- foreach my $req(@{$requests}) {
- $to_fetch->{patrons}->{$req->{borrowernumber}} = 1 if $embed{patron};
- $to_fetch->{branches}->{$req->{branchcode}} = 1 if $embed{library};
- $to_fetch->{capabilities}->{$req->{backend}} = 1 if $embed{capabilities};
+ my $to_fetch = {
+ patrons => {},
+ branches => {},
+ capabilities => {}
+ };
+ foreach my $req(@requests) {
+ $to_fetch->{patrons}->{$req->borrowernumber} = 1 if $embed{patron};
+ $to_fetch->{branches}->{$req->branchcode} = 1 if $embed{library};
+ $to_fetch->{capabilities}->{$req->backend} = 1 if $embed{capabilities};
}
# Fetch the patrons we need
}
}
-
# Now we've got all associated users and branches,
# we can augment the request objects
- foreach my $req(@{$requests}) {
- my $r = Koha::Illrequests->new->find($req->{illrequest_id});
- $req->{id_prefix} = $r->id_prefix;
+ my @output = ();
+ foreach my $req(@requests) {
+ my $to_push = $req->unblessed;
foreach my $p(@{$patron_arr}) {
- if ($p->{borrowernumber} == $req->{borrowernumber}) {
- $req->{patron} = {
+ if ($p->{borrowernumber} == $req->borrowernumber) {
+ $to_push->{patron} = {
firstname => $p->{firstname},
surname => $p->{surname},
cardnumber => $p->{cardnumber}
}
}
foreach my $b(@{$branch_arr}) {
- if ($b->{branchcode} eq $req->{branchcode}) {
- $req->{library} = $b;
+ if ($b->{branchcode} eq $req->branchcode) {
+ $to_push->{library} = $b;
last;
}
}
if ($embed{metadata}) {
my $metadata = Koha::Illrequestattributes->search(
- { illrequest_id => $req->{illrequest_id} },
+ { illrequest_id => $req->illrequest_id },
{ columns => [qw/type value/] }
)->unblessed;
my $meta_hash = {};
foreach my $meta(@{$metadata}) {
$meta_hash->{$meta->{type}} = $meta->{value};
}
- $req->{metadata} = $meta_hash;
+ $to_push->{metadata} = $meta_hash;
}
if ($embed{capabilities}) {
- $req->{capabilities} = $to_fetch->{$req->{backend}};
+ $to_push->{capabilities} = $to_fetch->{$req->backend};
}
+ push @output, $to_push;
}
- return $c->render( status => 200, openapi => $requests );
+ return $c->render( status => 200, openapi => \@output );
}
1;