|
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 |
my $ko_class = $result_set->prefetch_whitelist->{$key}; |
| 323 |
|
| 324 |
return undef unless defined $ko_class; |
| 325 |
|
| 326 |
return $key unless defined $embed->{$key}->{children}; |
| 327 |
|
| 328 |
my $prefetch = {}; |
| 329 |
foreach my $child (keys %{$embed->{$key}->{children}}) { |
| 330 |
my $parsed = _parse_prefetch($child, $embed->{$key}->{children}, $ko_class->new); |
| 331 |
$prefetch->{$child} = $parsed if defined $parsed; |
| 332 |
} |
| 333 |
|
| 334 |
return undef unless scalar(keys %{$prefetch}); |
| 335 |
|
| 336 |
return $prefetch; |
| 337 |
} |
| 338 |
|
| 290 |
1; |
339 |
1; |
| 291 |
- |
|
|