Lines 51-68
sub list {
Link Here
|
51 |
delete $args->{embed}; |
51 |
delete $args->{embed}; |
52 |
} |
52 |
} |
53 |
|
53 |
|
54 |
my $requests = Koha::Illrequests->unblessed; |
54 |
# Get all requests |
|
|
55 |
my @requests = Koha::Illrequests->as_list; |
55 |
|
56 |
|
56 |
# Identify patrons & branches that |
57 |
# Identify patrons & branches that |
57 |
# we're going to need and get them |
58 |
# we're going to need and get them |
58 |
my $to_fetch = {}; |
59 |
my $to_fetch = { |
59 |
$to_fetch->{patrons} = {} if $embed{patron}; |
60 |
patrons => {}, |
60 |
$to_fetch->{branches} = {} if $embed{library}; |
61 |
branches => {}, |
61 |
$to_fetch->{capabilities} = {} if $embed{capabilities}; |
62 |
capabilities => {} |
62 |
foreach my $req(@{$requests}) { |
63 |
}; |
63 |
$to_fetch->{patrons}->{$req->{borrowernumber}} = 1 if $embed{patron}; |
64 |
foreach my $req(@requests) { |
64 |
$to_fetch->{branches}->{$req->{branchcode}} = 1 if $embed{library}; |
65 |
$to_fetch->{patrons}->{$req->borrowernumber} = 1 if $embed{patron}; |
65 |
$to_fetch->{capabilities}->{$req->{backend}} = 1 if $embed{capabilities}; |
66 |
$to_fetch->{branches}->{$req->branchcode} = 1 if $embed{library}; |
|
|
67 |
$to_fetch->{capabilities}->{$req->backend} = 1 if $embed{capabilities}; |
66 |
} |
68 |
} |
67 |
|
69 |
|
68 |
# Fetch the patrons we need |
70 |
# Fetch the patrons we need |
Lines 100-114
sub list {
Link Here
|
100 |
} |
102 |
} |
101 |
} |
103 |
} |
102 |
|
104 |
|
103 |
|
|
|
104 |
# Now we've got all associated users and branches, |
105 |
# Now we've got all associated users and branches, |
105 |
# we can augment the request objects |
106 |
# we can augment the request objects |
106 |
foreach my $req(@{$requests}) { |
107 |
my @output = (); |
107 |
my $r = Koha::Illrequests->new->find($req->{illrequest_id}); |
108 |
foreach my $req(@requests) { |
108 |
$req->{id_prefix} = $r->id_prefix; |
109 |
my $to_push = $req->unblessed; |
109 |
foreach my $p(@{$patron_arr}) { |
110 |
foreach my $p(@{$patron_arr}) { |
110 |
if ($p->{borrowernumber} == $req->{borrowernumber}) { |
111 |
if ($p->{borrowernumber} == $req->borrowernumber) { |
111 |
$req->{patron} = { |
112 |
$to_push->{patron} = { |
112 |
firstname => $p->{firstname}, |
113 |
firstname => $p->{firstname}, |
113 |
surname => $p->{surname}, |
114 |
surname => $p->{surname}, |
114 |
cardnumber => $p->{cardnumber} |
115 |
cardnumber => $p->{cardnumber} |
Lines 117-144
sub list {
Link Here
|
117 |
} |
118 |
} |
118 |
} |
119 |
} |
119 |
foreach my $b(@{$branch_arr}) { |
120 |
foreach my $b(@{$branch_arr}) { |
120 |
if ($b->{branchcode} eq $req->{branchcode}) { |
121 |
if ($b->{branchcode} eq $req->branchcode) { |
121 |
$req->{library} = $b; |
122 |
$to_push->{library} = $b; |
122 |
last; |
123 |
last; |
123 |
} |
124 |
} |
124 |
} |
125 |
} |
125 |
if ($embed{metadata}) { |
126 |
if ($embed{metadata}) { |
126 |
my $metadata = Koha::Illrequestattributes->search( |
127 |
my $metadata = Koha::Illrequestattributes->search( |
127 |
{ illrequest_id => $req->{illrequest_id} }, |
128 |
{ illrequest_id => $req->illrequest_id }, |
128 |
{ columns => [qw/type value/] } |
129 |
{ columns => [qw/type value/] } |
129 |
)->unblessed; |
130 |
)->unblessed; |
130 |
my $meta_hash = {}; |
131 |
my $meta_hash = {}; |
131 |
foreach my $meta(@{$metadata}) { |
132 |
foreach my $meta(@{$metadata}) { |
132 |
$meta_hash->{$meta->{type}} = $meta->{value}; |
133 |
$meta_hash->{$meta->{type}} = $meta->{value}; |
133 |
} |
134 |
} |
134 |
$req->{metadata} = $meta_hash; |
135 |
$to_push->{metadata} = $meta_hash; |
135 |
} |
136 |
} |
136 |
if ($embed{capabilities}) { |
137 |
if ($embed{capabilities}) { |
137 |
$req->{capabilities} = $to_fetch->{$req->{backend}}; |
138 |
$to_push->{capabilities} = $to_fetch->{$req->backend}; |
138 |
} |
139 |
} |
|
|
140 |
push @output, $to_push; |
139 |
} |
141 |
} |
140 |
|
142 |
|
141 |
return $c->render( status => 200, openapi => $requests ); |
143 |
return $c->render( status => 200, openapi => \@output ); |
142 |
} |
144 |
} |
143 |
|
145 |
|
144 |
1; |
146 |
1; |
145 |
- |
|
|