Lines 22-27
use Modern::Perl;
Link Here
|
22 |
use Carp qw( carp ); |
22 |
use Carp qw( carp ); |
23 |
use List::MoreUtils qw( none ); |
23 |
use List::MoreUtils qw( none ); |
24 |
use Class::Inspector; |
24 |
use Class::Inspector; |
|
|
25 |
use Scalar::Util qw( reftype ); |
25 |
|
26 |
|
26 |
use Koha::Database; |
27 |
use Koha::Database; |
27 |
use Koha::Exceptions::Object; |
28 |
use Koha::Exceptions::Object; |
Lines 136-147
based on the query I<$params> and I<$attributes> that are passed (like in DBIC).
Link Here
|
136 |
sub search { |
137 |
sub search { |
137 |
my ( $self, $params, $attributes ) = @_; |
138 |
my ( $self, $params, $attributes ) = @_; |
138 |
|
139 |
|
|
|
140 |
if ( reftype( $attributes->{prefetch} ) |
141 |
&& reftype( $attributes->{prefetch} ) eq 'ARRAY' |
142 |
&& grep ( /extended_attributes/, @{ $attributes->{prefetch} } ) ) |
143 |
{ |
144 |
my $ea_entries = $self->extended_attributes_entries( $params, 0 ); |
145 |
my $ea_queries = $ea_entries / 2; |
146 |
while ( $ea_entries > 0 ) { |
147 |
push( @{ $attributes->{join} }, 'extended_attributes' ); |
148 |
$ea_entries--; |
149 |
} |
150 |
} |
151 |
|
139 |
my $class = ref($self) ? ref($self) : $self; |
152 |
my $class = ref($self) ? ref($self) : $self; |
140 |
my $rs = $self->_resultset()->search($params, $attributes); |
153 |
my $rs = $self->_resultset()->search($params, $attributes); |
141 |
|
154 |
|
142 |
return $class->_new_from_dbic($rs); |
155 |
return $class->_new_from_dbic($rs); |
143 |
} |
156 |
} |
144 |
|
157 |
|
|
|
158 |
sub extended_attributes_entries { |
159 |
my ( $self, $params, $extended_attributes_search_instances ) = @_; |
160 |
|
161 |
if ( reftype($params) && reftype($params) eq 'HASH' ) { |
162 |
|
163 |
# rewrite additional_field_values table params |
164 |
if ( $params->{'extended_attributes.field_id'} ) { |
165 |
$extended_attributes_search_instances++; |
166 |
if ( $extended_attributes_search_instances > 1 ) { |
167 |
my $old_key_value = delete $params->{'extended_attributes.field_id'}; |
168 |
my $new_key_value = "extended_attributes_$extended_attributes_search_instances" . ".field_id"; |
169 |
$params->{$new_key_value} = $old_key_value; |
170 |
|
171 |
my $old_value_value = delete $params->{'extended_attributes.value'}; |
172 |
my $new_value_value = "extended_attributes_$extended_attributes_search_instances" . ".value"; |
173 |
$params->{$new_value_value} = $old_value_value; |
174 |
} |
175 |
} |
176 |
|
177 |
# rewrite borrower_attributes table params |
178 |
if ( $params->{'extended_attributes.code'} ) { |
179 |
$extended_attributes_search_instances++; |
180 |
if ( $extended_attributes_search_instances > 1 ) { |
181 |
my $old_key_value = delete $params->{'extended_attributes.code'}; |
182 |
my $new_key_value = "extended_attributes_$extended_attributes_search_instances" . ".code"; |
183 |
$params->{$new_key_value} = $old_key_value; |
184 |
|
185 |
my $old_value_value = delete $params->{'extended_attributes.attribute'}; |
186 |
my $new_value_value = "extended_attributes_$extended_attributes_search_instances" . ".attribute"; |
187 |
$params->{$new_value_value} = $old_value_value; |
188 |
} |
189 |
} |
190 |
|
191 |
# rewrite illrequestattributes table params |
192 |
if ( $params->{'extended_attributes.type'} ) { |
193 |
$extended_attributes_search_instances++; |
194 |
if ( $extended_attributes_search_instances > 1 ) { |
195 |
my $old_key_value = delete $params->{'extended_attributes.type'}; |
196 |
my $new_key_value = "extended_attributes_$extended_attributes_search_instances" . ".type"; |
197 |
$params->{$new_key_value} = $old_key_value; |
198 |
|
199 |
my $old_value_value = delete $params->{'extended_attributes.value'}; |
200 |
my $new_value_value = "extended_attributes_$extended_attributes_search_instances" . ".value"; |
201 |
$params->{$new_value_value} = $old_value_value; |
202 |
} |
203 |
} |
204 |
|
205 |
foreach my $key ( keys %{$params} ) { |
206 |
return $self->extended_attributes_entries( $params->{$key}, $extended_attributes_search_instances ); |
207 |
} |
208 |
return $extended_attributes_search_instances; |
209 |
} elsif ( reftype($params) && reftype($params) eq 'ARRAY' ) { |
210 |
foreach my $ea_instance (@$params) { |
211 |
$extended_attributes_search_instances = |
212 |
+$self->extended_attributes_entries( $ea_instance, $extended_attributes_search_instances ); |
213 |
} |
214 |
return $extended_attributes_search_instances; |
215 |
} else { |
216 |
return $extended_attributes_search_instances; |
217 |
} |
218 |
} |
219 |
|
145 |
=head3 search_related |
220 |
=head3 search_related |
146 |
|
221 |
|
147 |
my $objects = Koha::Objects->search_related( $rel_name, $cond?, \%attrs? ); |
222 |
my $objects = Koha::Objects->search_related( $rel_name, $cond?, \%attrs? ); |
148 |
- |
|
|