View | Details | Raw Unified | Return to bug 37389
Collapse All | Expand All

(-)a/Koha/ILL/Requests.pm (-38 / +11 lines)
Lines 22-29 use Modern::Perl; Link Here
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::ILL::Request;
23
use Koha::ILL::Request;
24
use Koha::ILL::Request::Config;
24
use Koha::ILL::Request::Config;
25
use Koha::Objects::Mixin::ExtendedAttributes;
25
26
26
use base qw(Koha::Objects);
27
use base qw(Koha::Objects::Mixin::ExtendedAttributes Koha::Objects);
27
28
28
=head1 NAME
29
=head1 NAME
29
30
Lines 106-153 sub search_incomplete { Link Here
106
    } );
107
    } );
107
}
108
}
108
109
109
=head2 Internal methods
110
=head3 extended_attributes_config
110
111
112
=head3 _build_extended_attributes_relations
113
114
Method to dynamically add has_many relations for each ILLRequestAttribute type stored in the ILLRequestAttributes table.
115
116
Used in the API to allow for advanced joins.
117
118
Returns a list of relation accessor names.
119
111
120
=cut
112
=cut
121
113
122
sub _build_extended_attributes_relations {
114
sub extended_attributes_config {
123
    my ( $self, $types ) = @_;
115
    return {
124
116
        'id_field'     => 'illrequest_id',
125
    my $result_source = $self->_resultset->result_source;
117
        'key_field'    => 'type',
126
    for my $type ( @{$types} ) {
118
        'schema_class' => 'Koha::Schema::Result::Illrequestattribute',
127
        $result_source->add_relationship(
119
    };
128
            "extended_attributes_$type",
129
            "Koha::Schema::Result::Illrequestattribute",
130
            sub {
131
                my $args = shift;
132
133
                return {
134
                    "$args->{foreign_alias}.illrequest_id" => { -ident => "$args->{self_alias}.illrequest_id" },
135
                    "$args->{foreign_alias}.type"          => { '=', $type },
136
                };
137
            },
138
            {
139
                accessor       => 'multi',
140
                join_type      => 'LEFT',
141
                cascade_copy   => 0,
142
                cascade_delete => 0,
143
                is_depends_on  => 0
144
            },
145
        );
146
147
    }
148
    return map { 'extended_attributes_' . $_ } @{$types};
149
}
120
}
150
121
122
=head2 Internal methods
123
151
=head3 _type
124
=head3 _type
152
125
153
=cut
126
=cut
(-)a/Koha/Objects/Mixin/ExtendedAttributes.pm (-1 / +70 lines)
Line 0 Link Here
0
- 
1
package Koha::Objects::Mixin::ExtendedAttributes;
2
3
# Copyright 2024 PTFS Europe Ltd
4
#
5
# This file is part of Koha.
6
#
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.
11
#
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.
16
#
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>.
19
20
use Modern::Perl;
21
22
=head1 NAME
23
24
Koha::Objects::Mixin::ExtendedAttributes
25
26
=head2 Class methods
27
28
=head3 _build_extended_attributes_relations
29
30
Method to dynamically add has_many relations for Koha classes that support extended_attributes.
31
32
Used in the API to allow for advanced joins.
33
34
Returns a list of relation accessor names.
35
36
=cut
37
38
sub _build_extended_attributes_relations {
39
    my ( $self, $types ) = @_;
40
41
    my $ea_config = $self->extended_attributes_config;
42
43
    my $result_source = $self->_resultset->result_source;
44
    for my $type ( @{$types} ) {
45
        $result_source->add_relationship(
46
            "extended_attributes_$type",
47
            "$ea_config->{schema_class}",
48
            sub {
49
                my $args = shift;
50
51
                return {
52
                    "$args->{foreign_alias}.$ea_config->{id_field}" =>
53
                        { -ident => "$args->{self_alias}.$ea_config->{id_field}" },
54
                    "$args->{foreign_alias}.$ea_config->{key_field}" => { '=', $type },
55
                };
56
            },
57
            {
58
                accessor       => 'multi',
59
                join_type      => 'LEFT',
60
                cascade_copy   => 0,
61
                cascade_delete => 0,
62
                is_depends_on  => 0
63
            },
64
        );
65
66
    }
67
    return map { 'extended_attributes_' . $_ } @{$types};
68
}
69
70
1;

Return to bug 37389