Lines 48-82
Return a list of existing ILL statuses
Link Here
|
48 |
sub existing_statuses { |
48 |
sub existing_statuses { |
49 |
my ( $self, $backend_id ) = @_; |
49 |
my ( $self, $backend_id ) = @_; |
50 |
|
50 |
|
51 |
#FIXME: Currently fetching all requests, it'd be great if we could fetch distinct(status). |
|
|
52 |
# Even doing it with distinct status, we need the ILL request object, so that strings_map works and |
53 |
# the ILL request returns the correct status and info respective to its backend. |
54 |
my $ill_requests = Koha::Illrequests->search( |
55 |
{backend => $backend_id}, |
56 |
# { |
57 |
# columns => [ qw/status/ ], |
58 |
# group_by => [ qw/status/ ], |
59 |
# } |
60 |
); |
61 |
|
62 |
my @data; |
51 |
my @data; |
63 |
while (my $request = $ill_requests->next) { |
52 |
|
64 |
my $status_data = $request->strings_map; |
53 |
# Fetch all existing statuses for the provided backend |
65 |
|
54 |
my $backend_existing_statuses = Koha::Illrequests->search( |
66 |
foreach my $status_class ( qw(status_alias status) ){ |
55 |
{ backend => $backend_id }, |
67 |
if ($status_data->{$status_class}){ |
56 |
{ |
68 |
push @data, { |
57 |
columns => [qw/status/], |
69 |
$status_data->{$status_class}->{str} ? (str => $status_data->{$status_class}->{str}) : |
58 |
group_by => [qw/status/], |
70 |
$status_data->{$status_class}->{code} ? (str => $status_data->{$status_class}->{code}) : (), |
59 |
} |
71 |
$status_data->{$status_class}->{code} ? (code => $status_data->{$status_class}->{code}) : (), |
60 |
); |
72 |
} |
61 |
|
73 |
} |
62 |
while (my $backend_existing_status = $backend_existing_statuses->next) { |
|
|
63 |
|
64 |
my $illrequest = |
65 |
Koha::Illrequests->search( |
66 |
{ backend => $backend_id, status => $backend_existing_status->status } |
67 |
)->last; |
68 |
|
69 |
my $status_data = $illrequest->strings_map; |
70 |
|
71 |
if ( $status_data->{status} ) { |
72 |
push @data, { |
73 |
$status_data->{status}->{str} ? ( str => $status_data->{status}->{str} ) |
74 |
: $status_data->{status}->{code} ? ( str => $status_data->{status}->{code} ) |
75 |
: (), |
76 |
$status_data->{status}->{code} ? ( code => $status_data->{status}->{code} ) : (), |
77 |
}; |
74 |
} |
78 |
} |
75 |
} |
79 |
} |
76 |
|
80 |
|
77 |
# Remove duplicate statuses |
81 |
# Fetch all existing status_alias for the provided backend |
78 |
my %seen; |
82 |
my $backend_existing_status_aliases = Koha::Illrequests->search( |
79 |
@data = grep { my $e = $_; my $key = join '___', map { $e->{$_}; } sort keys %$_;!$seen{$key}++ } @data; |
83 |
{ backend => $backend_id }, |
|
|
84 |
{ |
85 |
columns => [qw/status_alias/], |
86 |
group_by => [qw/status_alias/], |
87 |
} |
88 |
); |
89 |
|
90 |
while ( my $backend_existing_status_alias = $backend_existing_status_aliases->next ) { |
91 |
|
92 |
my $illrequest = |
93 |
Koha::Illrequests->search( |
94 |
{ backend => $backend_id, status_alias => $backend_existing_status_alias->status_alias } ) |
95 |
->last; |
96 |
|
97 |
my $status_data = $illrequest->strings_map; |
98 |
|
99 |
if ( $status_data->{status_alias} ) { |
100 |
push @data, { |
101 |
$status_data->{status_alias}->{str} ? ( str => $status_data->{status_alias}->{str} ) |
102 |
: $status_data->{status_alias}->{code} ? ( str => $status_data->{status_alias}->{code} ) |
103 |
: (), |
104 |
$status_data->{status_alias}->{code} ? ( code => $status_data->{status_alias}->{code} ) : (), |
105 |
}; |
106 |
} |
107 |
} |
80 |
|
108 |
|
81 |
return \@data; |
109 |
return \@data; |
82 |
} |
110 |
} |
83 |
- |
|
|