Lines 539-544
sub prefetch_whitelist {
Link Here
|
539 |
... |
539 |
... |
540 |
} |
540 |
} |
541 |
}, |
541 |
}, |
|
|
542 |
public => 0|1, |
542 |
... |
543 |
... |
543 |
] |
544 |
] |
544 |
} |
545 |
} |
Lines 573-579
sub to_api {
Link Here
|
573 |
} |
574 |
} |
574 |
} |
575 |
} |
575 |
|
576 |
|
576 |
my $embeds = $params->{embed}; |
577 |
# Remove forbidden attributes if required |
|
|
578 |
if ( $params->{public} |
579 |
and $self->can('api_privileged_attrs') ) |
580 |
{ |
581 |
foreach my $privileged_attr ( @{ $self->api_privileged_attrs } ) { |
582 |
delete $json_object->{$privileged_attr}; |
583 |
} |
584 |
} |
585 |
|
586 |
# Make sure we duplicate the $params variable to avoid |
587 |
# breaking calls in a loop (Koha::Objects->to_api) |
588 |
$params = {%$params}; |
589 |
my $embeds = delete $params->{embed}; |
577 |
|
590 |
|
578 |
if ($embeds) { |
591 |
if ($embeds) { |
579 |
foreach my $embed ( keys %{$embeds} ) { |
592 |
foreach my $embed ( keys %{$embeds} ) { |
Lines 592-611
sub to_api {
Link Here
|
592 |
if ( defined $children and ref($children) eq 'ARRAY' ) { |
605 |
if ( defined $children and ref($children) eq 'ARRAY' ) { |
593 |
my @list = map { |
606 |
my @list = map { |
594 |
$self->_handle_to_api_child( |
607 |
$self->_handle_to_api_child( |
595 |
{ child => $_, next => $next, curr => $curr } ) |
608 |
{ |
|
|
609 |
child => $_, |
610 |
next => $next, |
611 |
curr => $curr, |
612 |
params => $params |
613 |
} |
614 |
) |
596 |
} @{$children}; |
615 |
} @{$children}; |
597 |
$json_object->{$curr} = \@list; |
616 |
$json_object->{$curr} = \@list; |
598 |
} |
617 |
} |
599 |
else { |
618 |
else { |
600 |
$json_object->{$curr} = $self->_handle_to_api_child( |
619 |
$json_object->{$curr} = $self->_handle_to_api_child( |
601 |
{ child => $children, next => $next, curr => $curr } ); |
620 |
{ |
|
|
621 |
child => $children, |
622 |
next => $next, |
623 |
curr => $curr, |
624 |
params => $params |
625 |
} |
626 |
); |
602 |
} |
627 |
} |
603 |
} |
628 |
} |
604 |
} |
629 |
} |
605 |
} |
630 |
} |
606 |
|
631 |
|
607 |
|
|
|
608 |
|
609 |
return $json_object; |
632 |
return $json_object; |
610 |
} |
633 |
} |
611 |
|
634 |
|
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; |