Lines 570-582
sub to_api {
Link Here
|
570 |
# Remove forbidden attributes if required (including their coded values) |
570 |
# Remove forbidden attributes if required (including their coded values) |
571 |
if ( $params->{public} ) { |
571 |
if ( $params->{public} ) { |
572 |
for my $field ( keys %{$json_object} ) { |
572 |
for my $field ( keys %{$json_object} ) { |
573 |
delete $json_object->{$field} unless any { $_ eq $field } @{ $self->public_read_list }; |
573 |
delete $json_object->{$field} |
|
|
574 |
unless any { $_ eq $field } @{ $self->public_read_list }; |
574 |
} |
575 |
} |
575 |
|
576 |
|
576 |
if ( $strings ) { |
577 |
if ($strings) { |
577 |
foreach my $field (keys %{$avs}) { |
578 |
foreach my $field ( keys %{$avs} ) { |
578 |
delete $avs->{$field} |
579 |
delete $avs->{$field} |
579 |
unless any { $_ eq $field } @{ $self->public_read_list }; |
580 |
unless any { $_ eq $field } @{ $self->public_read_list }; |
580 |
} |
581 |
} |
581 |
} |
582 |
} |
582 |
} |
583 |
} |
Lines 588-602
sub to_api {
Link Here
|
588 |
foreach my $column ( keys %{ $self->to_api_mapping } ) { |
589 |
foreach my $column ( keys %{ $self->to_api_mapping } ) { |
589 |
my $mapped_column = $self->to_api_mapping->{$column}; |
590 |
my $mapped_column = $self->to_api_mapping->{$column}; |
590 |
if ( exists $json_object->{$column} |
591 |
if ( exists $json_object->{$column} |
591 |
&& defined $mapped_column ) { |
592 |
&& defined $mapped_column ) |
|
|
593 |
{ |
592 |
|
594 |
|
593 |
# key != undef |
595 |
# key != undef |
594 |
$json_object->{$mapped_column} = delete $json_object->{$column}; |
596 |
$json_object->{$mapped_column} = delete $json_object->{$column}; |
595 |
$avs->{$mapped_column} = delete $avs->{$column} |
597 |
$avs->{$mapped_column} = delete $avs->{$column} |
596 |
if exists $avs->{$column}; |
598 |
if exists $avs->{$column}; |
597 |
|
599 |
|
598 |
} elsif ( exists $json_object->{$column} |
600 |
} |
599 |
&& !defined $mapped_column ) { |
601 |
elsif ( exists $json_object->{$column} |
|
|
602 |
&& !defined $mapped_column ) |
603 |
{ |
600 |
|
604 |
|
601 |
# key == undef |
605 |
# key == undef |
602 |
delete $json_object->{$column}; |
606 |
delete $json_object->{$column}; |
Lines 610-617
sub to_api {
Link Here
|
610 |
|
614 |
|
611 |
if ($embeds) { |
615 |
if ($embeds) { |
612 |
foreach my $embed ( keys %{$embeds} ) { |
616 |
foreach my $embed ( keys %{$embeds} ) { |
613 |
if ( $embed =~ m/^(?<relation>.*)_count$/ |
617 |
if ( $embed =~ m/^(?<relation>.*)_count$/ |
614 |
and $embeds->{$embed}->{is_count} ) { |
618 |
and $embeds->{$embed}->{is_count} ) |
|
|
619 |
{ |
615 |
|
620 |
|
616 |
my $relation = $+{relation}; |
621 |
my $relation = $+{relation}; |
617 |
$json_object->{$embed} = $self->$relation->count; |
622 |
$json_object->{$embed} = $self->$relation->count; |
Lines 671-676
sub to_api_mapping {
Link Here
|
671 |
return {}; |
676 |
return {}; |
672 |
} |
677 |
} |
673 |
|
678 |
|
|
|
679 |
=head3 api_strings_mapping |
680 |
|
681 |
my $params = { is_public => 1 }; |
682 |
my $string_map = $object->api_strings_mapping($params); |
683 |
|
684 |
Generic method that returns the string map for coded attributes. |
685 |
|
686 |
Return should be a hashref keyed on database field name with the values |
687 |
being hashrefs containing 'str', 'type' and optionally 'category'. |
688 |
|
689 |
This is then use in to_api to render the _strings embed when requested. |
690 |
|
691 |
Note: this only returns an empty I<hashref>. Each class should have its |
692 |
own mapping returned. |
693 |
|
694 |
=cut |
695 |
|
696 |
sub api_strings_mapping { |
697 |
return {}; |
698 |
} |
699 |
|
674 |
=head3 public_read_list |
700 |
=head3 public_read_list |
675 |
|
701 |
|
676 |
|
702 |
|
677 |
- |
|
|