Lines 581-586
sub to_api {
Link Here
|
581 |
} |
581 |
} |
582 |
} |
582 |
} |
583 |
|
583 |
|
|
|
584 |
my $av_expand = $params->{av_expand}; |
585 |
|
584 |
# Make sure we duplicate the $params variable to avoid |
586 |
# Make sure we duplicate the $params variable to avoid |
585 |
# breaking calls in a loop (Koha::Objects->to_api) |
587 |
# breaking calls in a loop (Koha::Objects->to_api) |
586 |
$params = {%$params}; |
588 |
$params = {%$params}; |
Lines 627-632
sub to_api {
Link Here
|
627 |
} |
629 |
} |
628 |
} |
630 |
} |
629 |
|
631 |
|
|
|
632 |
if ( $av_expand && $self->can('_fetch_authorised_values') ) { |
633 |
|
634 |
# _fetch_authorised_values should return a hash as the following |
635 |
# { |
636 |
# column_name => <authorised_value>->unblessed |
637 |
# ... |
638 |
# } |
639 |
my $avs = $self->_fetch_authorised_values($av_expand); |
640 |
|
641 |
# Language selection will be implemented when lang overlay for av is ready |
642 |
# Now we will just fetch plain authorised values from the Koha::AuthorisedValues |
643 |
$avs = $self->_do_api_mapping($avs); |
644 |
|
645 |
$json_object->{_authorised_values} = $avs || {}; |
646 |
} |
647 |
|
648 |
return $json_object; |
649 |
} |
650 |
|
651 |
=head3 _do_api_mapping |
652 |
|
653 |
=cut |
654 |
|
655 |
sub _do_api_mapping { |
656 |
my ($self, $json_object) = @_; |
657 |
# Rename attributes if there's a mapping |
658 |
if ( $self->can('to_api_mapping') ) { |
659 |
foreach my $column ( keys %{ $self->to_api_mapping } ) { |
660 |
my $mapped_column = $self->to_api_mapping->{$column}; |
661 |
if ( exists $json_object->{$column} |
662 |
&& defined $mapped_column ) |
663 |
{ |
664 |
# key != undef |
665 |
$json_object->{$mapped_column} = delete $json_object->{$column}; |
666 |
} |
667 |
elsif ( exists $json_object->{$column} |
668 |
&& !defined $mapped_column ) |
669 |
{ |
670 |
# key == undef |
671 |
delete $json_object->{$column}; |
672 |
} |
673 |
} |
674 |
} |
630 |
return $json_object; |
675 |
return $json_object; |
631 |
} |
676 |
} |
632 |
|
677 |
|