|
Lines 538-543
sub prefetch_whitelist {
Link Here
|
| 538 |
... |
538 |
... |
| 539 |
} |
539 |
} |
| 540 |
}, |
540 |
}, |
|
|
541 |
public => 0|1, |
| 541 |
... |
542 |
... |
| 542 |
] |
543 |
] |
| 543 |
} |
544 |
} |
|
Lines 572-578
sub to_api {
Link Here
|
| 572 |
} |
573 |
} |
| 573 |
} |
574 |
} |
| 574 |
|
575 |
|
| 575 |
my $embeds = $params->{embed}; |
576 |
# Remove forbidden attributes if required |
|
|
577 |
if ( $params->{public} |
| 578 |
and $self->can('api_privileged_attrs') ) |
| 579 |
{ |
| 580 |
foreach my $privileged_attr ( @{ $self->api_privileged_attrs } ) { |
| 581 |
delete $json_object->{$privileged_attr}; |
| 582 |
} |
| 583 |
} |
| 584 |
|
| 585 |
# Make sure we duplicate the $params variable to avoid |
| 586 |
# breaking calls in a loop (Koha::Objects->to_api) |
| 587 |
$params = {%$params}; |
| 588 |
my $embeds = delete $params->{embed}; |
| 576 |
|
589 |
|
| 577 |
if ($embeds) { |
590 |
if ($embeds) { |
| 578 |
foreach my $embed ( keys %{$embeds} ) { |
591 |
foreach my $embed ( keys %{$embeds} ) { |
|
Lines 591-610
sub to_api {
Link Here
|
| 591 |
if ( defined $children and ref($children) eq 'ARRAY' ) { |
604 |
if ( defined $children and ref($children) eq 'ARRAY' ) { |
| 592 |
my @list = map { |
605 |
my @list = map { |
| 593 |
$self->_handle_to_api_child( |
606 |
$self->_handle_to_api_child( |
| 594 |
{ child => $_, next => $next, curr => $curr } ) |
607 |
{ |
|
|
608 |
child => $_, |
| 609 |
next => $next, |
| 610 |
curr => $curr, |
| 611 |
params => $params |
| 612 |
} |
| 613 |
) |
| 595 |
} @{$children}; |
614 |
} @{$children}; |
| 596 |
$json_object->{$curr} = \@list; |
615 |
$json_object->{$curr} = \@list; |
| 597 |
} |
616 |
} |
| 598 |
else { |
617 |
else { |
| 599 |
$json_object->{$curr} = $self->_handle_to_api_child( |
618 |
$json_object->{$curr} = $self->_handle_to_api_child( |
| 600 |
{ child => $children, next => $next, curr => $curr } ); |
619 |
{ |
|
|
620 |
child => $children, |
| 621 |
next => $next, |
| 622 |
curr => $curr, |
| 623 |
params => $params |
| 624 |
} |
| 625 |
); |
| 601 |
} |
626 |
} |
| 602 |
} |
627 |
} |
| 603 |
} |
628 |
} |
| 604 |
} |
629 |
} |
| 605 |
|
630 |
|
| 606 |
|
|
|
| 607 |
|
| 608 |
return $json_object; |
631 |
return $json_object; |
| 609 |
} |
632 |
} |
| 610 |
|
633 |
|
|
Lines 850-858
sub _type { }
Link Here
|
| 850 |
sub _handle_to_api_child { |
873 |
sub _handle_to_api_child { |
| 851 |
my ($self, $args ) = @_; |
874 |
my ($self, $args ) = @_; |
| 852 |
|
875 |
|
| 853 |
my $child = $args->{child}; |
876 |
my $child = $args->{child}; |
| 854 |
my $next = $args->{next}; |
877 |
my $next = $args->{next}; |
| 855 |
my $curr = $args->{curr}; |
878 |
my $curr = $args->{curr}; |
|
|
879 |
my $params = $args->{params}; |
| 856 |
|
880 |
|
| 857 |
my $res; |
881 |
my $res; |
| 858 |
|
882 |
|
|
Lines 862-868
sub _handle_to_api_child {
Link Here
|
| 862 |
if defined $next and blessed $child and !$child->can('to_api'); |
886 |
if defined $next and blessed $child and !$child->can('to_api'); |
| 863 |
|
887 |
|
| 864 |
if ( blessed $child ) { |
888 |
if ( blessed $child ) { |
| 865 |
$res = $child->to_api({ embed => $next }); |
889 |
$params->{embed} = $next; |
|
|
890 |
$res = $child->to_api($params); |
| 866 |
} |
891 |
} |
| 867 |
else { |
892 |
else { |
| 868 |
$res = $child; |
893 |
$res = $child; |