$params = defined $params ? {%$params} : {};
# children should be able to handle without
- my $embeds = delete $params->{embed};
- my $av_expand = delete $params->{av_expand};
+ my $embeds = delete $params->{embed};
+ my $strings = delete $params->{strings};
# coded values handling
my $avs = {};
- if ( $av_expand and $self->can('api_av_mapping') ) {
- $avs = $self->api_av_mapping($params);
+ if ( $strings and $self->can('api_strings_mapping') ) {
+ $avs = $self->api_strings_mapping($params);
}
# Remove forbidden attributes if required (including their coded values)
delete $json_object->{$field} unless any { $_ eq $field } @{ $self->public_read_list };
}
- if ( $av_expand ) {
+ if ( $strings ) {
foreach my $field (keys %{$avs}) {
delete $avs->{$field}
unless any { $_ eq $field } @{ $self->public_read_list };
}
$json_object->{_strings} = $avs
- if $av_expand;
+ if $strings;
if ($embeds) {
foreach my $embed ( keys %{$embeds} ) {
my $curr = $embed;
my $next = $embeds->{$curr}->{children};
- $params->{av_expand} = 1
- if $embeds->{$embed}->{av_expand};
+ $params->{strings} = 1
+ if $embeds->{$embed}->{strings};
my $children = $self->$curr;
my $attributes = {};
# Look for embeds
- my $embed = $c->stash('koha.embed');
- my $av_expand = $c->stash('koha.av_expand');
+ my $embed = $c->stash('koha.embed');
+ my $strings = $c->stash('koha.strings');
# Generate prefetches for embedded stuff
$c->dbic_merge_prefetch(
return unless $object;
- return $object->to_api({ embed => $embed, av_expand => $av_expand });
+ return $object->to_api({ embed => $embed, strings => $strings });
}
);
# Privileged reques?
my $is_public = $c->stash('is_public');
# Look for embeds
- my $embed = $c->stash('koha.embed');
- my $av_expand = $c->stash('koha.av_expand');
+ my $embed = $c->stash('koha.embed');
+ my $strings = $c->stash('koha.strings');
# Merge sorting into query attributes
$c->dbic_merge_sorting(
}
);
- return $objects->to_api({ embed => $embed, public => $is_public, av_expand => $av_expand });
+ return $objects->to_api({ embed => $embed, public => $is_public, strings => $strings });
}
);
}
if ($embed_header) {
my $THE_embed = {};
foreach my $embed_req ( split /\s*,\s*/, $embed_header ) {
- if ( $embed_req eq '+av_expand' ) { # special case
- $c->stash( 'koha.av_expand' => 1 );
+ if ( $embed_req eq '+strings' ) { # special case
+ $c->stash( 'koha.strings' => 1 );
} else {
_merge_embed( _parse_embed($embed_req), $THE_embed );
}
my $key = $+{relation} . "_count";
$result->{$key} = { is_count => 1 };
}
- elsif ( $curr =~ m/^(?<relation>.*)\+av_expand/ ) {
+ elsif ( $curr =~ m/^(?<relation>.*)\+strings/ ) {
my $key = $+{relation};
- $result->{$key} = { av_expand => 1 };
+ $result->{$key} = { strings => 1 };
}
else {
$result->{$curr} = {};
my $c = shift;
$c->stash_embed();
- my $embed = $c->stash('koha.embed');
- my $av_expand = $c->stash('koha.av_expand');
+ my $embed = $c->stash('koha.embed');
+ my $strings = $c->stash('koha.strings');
$c->render(
status => 200,
json => {
- av_expand => $av_expand,
- embed => $embed,
+ strings => $strings,
+ embed => $embed,
}
);
};
patron => {}
});
- $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item+av_expand,patron+av_expand' } )
+ $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item+strings,patron+strings' } )
->json_is( '/embed' => {
- checkouts => { children => { item => { av_expand => 1 } } },
- patron => { av_expand => 1 }
+ checkouts => { children => { item => { strings => 1 } } },
+ patron => { strings => 1 }
})
- ->json_is( '/av_expand' => undef );
+ ->json_is( '/strings' => undef );
- $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts+av_expand,checkouts.item,patron,+av_expand' } )
+ $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts+strings,checkouts.item,patron,+strings' } )
->json_is( '/embed' => {
- checkouts => { children => { item => { } }, av_expand => 1 },
+ checkouts => { children => { item => { } }, strings => 1 },
patron => { }
})
- ->json_is( '/av_expand' => 1 );
+ ->json_is( '/strings' => 1 );
};
subtest 'stash_overrides() tests' => sub {
is($biblio_api->{items}->[0]->{holds}->[0]->{hold_id}, $hold->reserve_id, 'Hold matches');
is_deeply($biblio_api->{biblioitem}, $biblio->biblioitem->to_api, 'More than one root');
- my $_str = {
+ my $_strings = {
location => {
category => 'ASD',
str => 'Estante alto',
}
};
- # mock Koha::Item so it implements 'api_av_mapping'
+ # mock Koha::Item so it implements 'api_strings_mapping'
my $item_mock = Test::MockModule->new('Koha::Item');
$item_mock->mock(
- 'api_av_mapping',
+ 'api_strings_mapping',
sub {
- return $_str;
+ return $_strings;
}
);
my $hold_api = $hold->to_api(
{
- embed => { 'item' => { av_expand => 1 } }
+ embed => { 'item' => { strings => 1 } }
}
);
is( $hold_api->{item}->{item_id}, $item->itemnumber, 'Object embedded correctly' );
is_deeply(
$hold_api->{item}->{_strings},
- $_str,
- '_str correctly added to nested embed'
+ $_strings,
+ '_strings correctly added to nested embed'
);
# biblio with no items
my $city_mock = Test::MockModule->new('Koha::City');
$city_mock->mock(
- 'api_av_mapping',
+ 'api_strings_mapping',
sub {
my ( $self, $params ) = @_;
}
);
- my $mobj = $marseille->to_api( { av_expand => 1, public => 1 } );
- my $cobj = $cordoba->to_api( { av_expand => 1, public => 0 } );
+ my $mobj = $marseille->to_api( { strings => 1, public => 1 } );
+ my $cobj = $cordoba->to_api( { strings => 1, public => 0 } );
- ok( exists $mobj->{_strings}, '_str exists for Marseille' );
- ok( exists $cobj->{_strings}, '_str exists for Córdoba' );
+ ok( exists $mobj->{_strings}, '_strings exists for Marseille' );
+ ok( exists $cobj->{_strings}, '_strings exists for Córdoba' );
is_deeply(
$mobj->{_strings}->{country},
my $city_class = Test::MockModule->new('Koha::City');
$city_class->mock(
- 'api_av_mapping',
+ 'api_strings_mapping',
sub {
my ($self, $params) = @_;
use Koha::AuthorisedValues;
}
);
- $t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '+av_expand' } )
+ $t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '+strings' } )
->status_is(200)->json_is( '/name' => 'Manuel' )
->json_has('/_strings')
->json_is( '/_strings/country/type' => 'av' )
->status_is(200)->json_is( '/name' => 'Manuel' )
->json_hasnt('/_strings');
- $t->get_ok( '/cities/' . $manuela->id => { 'x-koha-embed' => '+av_expand' } )
+ $t->get_ok( '/cities/' . $manuela->id => { 'x-koha-embed' => '+strings' } )
->status_is(200)->json_is( '/name' => 'Manuela' )
->json_has('/_strings')
->json_is( '/_strings/country/type' => 'av' )
my $city_class = Test::MockModule->new('Koha::City');
$city_class->mock(
- 'api_av_mapping',
+ 'api_strings_mapping',
sub {
my ($self, $params) = @_;
use Koha::AuthorisedValues;
);
$t->get_ok( '/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' =>
- { 'x-koha-embed' => '+av_expand' } )->status_is(200)
+ { 'x-koha-embed' => '+strings' } )->status_is(200)
->json_has('/0')->json_has('/1')->json_hasnt('/2')
->json_is( '/0/name' => 'Manuel' )
->json_has('/0/_strings')