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 ) = @_;
53 # NOTE: This query fetches all distinct status's found in the database for this backend.
54 # We need the 'status' field for obvious reasons, the 'backend' field is required to not
55 # throw 'Koha::Exceptions::Ill::InvalidBackendId' when we're converting to a Koha object.
56 # Finally, to get around 'ONLY_FULL_GROUP_BY', we have to be explicit about which
57 # 'request_id' we want to return, hense the 'MAX' call.
58 my $ill_requests = Koha::Illrequests->search(
59 { backend => $backend_id },
61 select => [ 'status', \'MAX(illrequest_id)', 'backend' ],
62 as => [qw/ status illrequest_id backend /],
63 group_by => [qw/status backend/],
66 while ( my $request = $ill_requests->next ) {
67 my $status_data = $request->strings_map;
69 if ( $status_data->{status} ) {
71 $status_data->{status}->{str} ? ( str => $status_data->{status}->{str} )
72 : $status_data->{status}->{code} ? ( str => $status_data->{status}->{code} )
74 $status_data->{status}->{code} ? ( code => $status_data->{status}->{code} ) : (),
79 # Now do the same to get all status_aliases
80 $ill_requests = Koha::Illrequests->search(
81 { backend => $backend_id },
83 select => [ 'status_alias', \'MAX(illrequest_id)', 'backend' ],
84 as => [qw/ status_alias illrequest_id backend /],
85 group_by => [qw/status_alias backend/],
88 while ( my $request = $ill_requests->next ) {
89 my $status_data = $request->strings_map;
91 if ( $status_data->{status_alias} ) {
93 $status_data->{status_alias}->{str} ? ( str => $status_data->{status_alias}->{str} )
94 : $status_data->{status_alias}->{code} ? ( str => $status_data->{status_alias}->{code} )
96 $status_data->{status_alias}->{code} ? ( code => $status_data->{status_alias}->{code} ) : (),
106 Embed info in backend for API response
111 my ( $self, $backend_id, $embed_header ) = @_;
112 $embed_header ||= q{};
116 foreach my $embed_req ( split /\s*,\s*/, $embed_header ) {
117 if ( $embed_req eq 'statuses+strings' ) {
118 $return_embed->{statuses} = $self->existing_statuses( $backend_id );
121 return $return_embed;
124 =head2 Internal methods
128 my $type = Koha::Illbackend->_type;
130 Return this object's type
140 Pedro Amorim <pedro.amorim@ptfs-europe.com>