Lines 100-105
Generates the DBIC order_by attributes based on I<$params>, and merges into I<$a
Link Here
|
100 |
} |
100 |
} |
101 |
); |
101 |
); |
102 |
|
102 |
|
|
|
103 |
=head3 dbic_merge_prefetch |
104 |
|
105 |
$attributes = $c->dbic_merge_prefetch({ attributes => $attributes, result_set => $result_set }); |
106 |
|
107 |
Generates the DBIC prefetch attribute based on embedded relations, and merges into I<$attributes>. |
108 |
|
109 |
=cut |
110 |
|
111 |
$app->helper( |
112 |
'dbic_merge_prefetch' => sub { |
113 |
my ( $c, $args ) = @_; |
114 |
my $attributes = $args->{attributes}; |
115 |
my $result_set = $args->{result_set}; |
116 |
my $embed = $c->stash('koha.embed'); |
117 |
|
118 |
return unless defined $embed; |
119 |
|
120 |
my @prefetches; |
121 |
foreach my $key (keys %{$embed}) { |
122 |
my $parsed = _parse_prefetch($key, $embed, $result_set); |
123 |
push @prefetches, $parsed if defined $parsed; |
124 |
} |
125 |
|
126 |
if(scalar(@prefetches)) { |
127 |
$attributes->{prefetch} = \@prefetches; |
128 |
} |
129 |
} |
130 |
); |
131 |
|
103 |
=head3 _build_query_params_from_api |
132 |
=head3 _build_query_params_from_api |
104 |
|
133 |
|
105 |
my $params = _build_query_params_from_api( $filtered_params, $reserved_params ); |
134 |
my $params = _build_query_params_from_api( $filtered_params, $reserved_params ); |
Lines 287-290
sub _merge_embed {
Link Here
|
287 |
} |
316 |
} |
288 |
} |
317 |
} |
289 |
|
318 |
|
|
|
319 |
sub _parse_prefetch { |
320 |
my ( $key, $embed, $result_set) = @_; |
321 |
|
322 |
return unless exists $result_set->prefetch_whitelist->{$key}; |
323 |
|
324 |
my $ko_class = $result_set->prefetch_whitelist->{$key}; |
325 |
return $key unless defined $embed->{$key}->{children} && defined $ko_class; |
326 |
|
327 |
my $prefetch = {}; |
328 |
foreach my $child (keys %{$embed->{$key}->{children}}) { |
329 |
my $parsed = _parse_prefetch($child, $embed->{$key}->{children}, $ko_class->new); |
330 |
$prefetch->{$key} = $parsed if defined $parsed; |
331 |
} |
332 |
|
333 |
return unless scalar(keys %{$prefetch}); |
334 |
|
335 |
return $prefetch; |
336 |
} |
337 |
|
290 |
1; |
338 |
1; |