Lines 105-110
Generates the DBIC order_by attributes based on I<$params>, and merges into I<$a
Link Here
|
105 |
} |
105 |
} |
106 |
); |
106 |
); |
107 |
|
107 |
|
|
|
108 |
=head3 dbic_merge_prefetch |
109 |
|
110 |
$attributes = $c->dbic_merge_prefetch({ attributes => $attributes, result_set => $result_set }); |
111 |
|
112 |
Generates the DBIC prefetch attribute based on embedded relations, and merges into I<$attributes>. |
113 |
|
114 |
=cut |
115 |
|
116 |
$app->helper( |
117 |
'dbic_merge_prefetch' => sub { |
118 |
my ( $c, $args ) = @_; |
119 |
my $attributes = $args->{attributes}; |
120 |
my $result_set = $args->{result_set}; |
121 |
my $embed = $c->stash('koha.embed'); |
122 |
|
123 |
return unless defined $embed; |
124 |
|
125 |
my @prefetches; |
126 |
foreach my $key (keys %{$embed}) { |
127 |
my $parsed = _parse_prefetch($key, $embed, $result_set); |
128 |
push @prefetches, $parsed if defined $parsed; |
129 |
} |
130 |
|
131 |
if(scalar(@prefetches)) { |
132 |
$attributes->{prefetch} = \@prefetches; |
133 |
} |
134 |
} |
135 |
); |
136 |
|
108 |
=head3 _build_query_params_from_api |
137 |
=head3 _build_query_params_from_api |
109 |
|
138 |
|
110 |
my $params = _build_query_params_from_api( $filtered_params, $reserved_params ); |
139 |
my $params = _build_query_params_from_api( $filtered_params, $reserved_params ); |
Lines 298-301
sub _merge_embed {
Link Here
|
298 |
} |
327 |
} |
299 |
} |
328 |
} |
300 |
|
329 |
|
|
|
330 |
sub _parse_prefetch { |
331 |
my ( $key, $embed, $result_set) = @_; |
332 |
|
333 |
return unless exists $result_set->prefetch_whitelist->{$key}; |
334 |
|
335 |
my $ko_class = $result_set->prefetch_whitelist->{$key}; |
336 |
return $key unless defined $embed->{$key}->{children} && defined $ko_class; |
337 |
|
338 |
my $prefetch = {}; |
339 |
foreach my $child (keys %{$embed->{$key}->{children}}) { |
340 |
my $parsed = _parse_prefetch($child, $embed->{$key}->{children}, $ko_class->new); |
341 |
$prefetch->{$key} = $parsed if defined $parsed; |
342 |
} |
343 |
|
344 |
return unless scalar(keys %{$prefetch}); |
345 |
|
346 |
return $prefetch; |
347 |
} |
348 |
|
301 |
1; |
349 |
1; |