1 package Koha::Illbackend;
3 # Copyright PTFS Europe 2023
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use base qw(Koha::Object);
26 Koha::Illbackend - Koha Illbackend Object class
39 return bless $self, $class;
42 =head3 existing_statuses
44 Return a list of existing ILL statuses
48 sub existing_statuses {
49 my ( $self, $backend_id ) = @_;
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},
57 # columns => [ qw/status/ ],
58 # group_by => [ qw/status/ ],
63 while (my $request = $ill_requests->next) {
64 my $status_data = $request->strings_map;
66 foreach my $status_class ( qw(status_alias status) ){
67 if ($status_data->{$status_class}){
69 $status_data->{$status_class}->{str} ? (str => $status_data->{$status_class}->{str}) :
70 $status_data->{$status_class}->{code} ? (str => $status_data->{$status_class}->{code}) : (),
71 $status_data->{$status_class}->{code} ? (code => $status_data->{$status_class}->{code}) : (),
77 # Remove duplicate statuses
79 @data = grep { my $e = $_; my $key = join '___', map { $e->{$_}; } sort keys %$_;!$seen{$key}++ } @data;
86 Embed info in backend for API response
91 my ( $self, $backend_id, $embed_header ) = @_;
92 $embed_header ||= q{};
96 foreach my $embed_req ( split /\s*,\s*/, $embed_header ) {
97 if ( $embed_req eq 'statuses+strings' ) {
98 $return_embed->{statuses} = $self->existing_statuses( $backend_id );
101 return $return_embed;
104 =head2 Internal methods
108 my $type = Koha::Illbackend->_type;
110 Return this object's type
120 Pedro Amorim <pedro.amorim@ptfs-europe.com>