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/],
64 order_by => [qw/status backend/],
67 while ( my $request = $ill_requests->next ) {
68 my $status_data = $request->strings_map;
70 if ( $status_data->{status} ) {
72 $status_data->{status}->{str} ? ( str => $status_data->{status}->{str} )
73 : $status_data->{status}->{code} ? ( str => $status_data->{status}->{code} )
75 $status_data->{status}->{code} ? ( code => $status_data->{status}->{code} ) : (),
80 # Now do the same to get all status_aliases
81 $ill_requests = Koha::Illrequests->search(
82 { backend => $backend_id },
84 select => [ 'status_alias', \'MAX(illrequest_id)', 'backend' ],
85 as => [qw/ status_alias illrequest_id backend /],
86 group_by => [qw/status_alias backend/],
87 order_by => [qw/status_alias backend/],
90 while ( my $request = $ill_requests->next ) {
91 my $status_data = $request->strings_map;
93 if ( $status_data->{status_alias} ) {
95 $status_data->{status_alias}->{str} ? ( str => $status_data->{status_alias}->{str} )
96 : $status_data->{status_alias}->{code} ? ( str => $status_data->{status_alias}->{code} )
98 $status_data->{status_alias}->{code} ? ( code => $status_data->{status_alias}->{code} ) : (),
108 Embed info in backend for API response
113 my ( $self, $backend_id, $embed_header ) = @_;
114 $embed_header ||= q{};
118 foreach my $embed_req ( split /\s*,\s*/, $embed_header ) {
119 if ( $embed_req eq 'statuses+strings' ) {
120 $return_embed->{statuses} = $self->existing_statuses( $backend_id );
123 return $return_embed;
126 =head2 Internal methods
130 my $type = Koha::Illbackend->_type;
132 Return this object's type
142 Pedro Amorim <pedro.amorim@ptfs-europe.com>