Bug 33430: Add strings_map method
This patch adds a strings_map method to allow the API to return the required authorised values needed for table displays Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
244ce5396b
commit
31364ab898
|
|
@ -294,6 +294,42 @@ sub to_api_mapping {
|
|||
};
|
||||
}
|
||||
|
||||
=head3 strings_map
|
||||
|
||||
Returns a map of column name to string representations including the string.
|
||||
|
||||
=cut
|
||||
|
||||
sub strings_map {
|
||||
my ( $self, $params ) = @_;
|
||||
|
||||
my $strings = {};
|
||||
|
||||
my $required_strings = {
|
||||
STATUS => 'SUGGEST_STATUS',
|
||||
itemtype => 'SUGGEST_FORMAT',
|
||||
patronreason => 'OPAC_SUG',
|
||||
};
|
||||
|
||||
foreach my $key ( keys %$required_strings ) {
|
||||
my $av = Koha::AuthorisedValues->search(
|
||||
{ category => $required_strings->{$key}, authorised_value => $self->$key } );
|
||||
my $status_str =
|
||||
$av->count
|
||||
? $params->{public}
|
||||
? $av->next->opac_description
|
||||
: $av->next->lib
|
||||
: $self->$key;
|
||||
|
||||
$strings->{$key} = {
|
||||
category => $required_strings->{$key},
|
||||
str => $status_str,
|
||||
type => 'av',
|
||||
};
|
||||
}
|
||||
return $strings;
|
||||
}
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Kyle M Hall <kyle@bywatersolutions.com>
|
||||
|
|
|
|||
|
|
@ -191,4 +191,8 @@ properties:
|
|||
- boolean
|
||||
- "null"
|
||||
description: archived (processed) suggestion
|
||||
_strings:
|
||||
type:
|
||||
- object
|
||||
- "null"
|
||||
additionalProperties: false
|
||||
|
|
|
|||
|
|
@ -15,6 +15,16 @@
|
|||
- $ref: "../swagger.yaml#/parameters/q_param"
|
||||
- $ref: "../swagger.yaml#/parameters/q_body"
|
||||
- $ref: "../swagger.yaml#/parameters/request_id_header"
|
||||
- name: x-koha-embed
|
||||
in: header
|
||||
required: false
|
||||
description: Embed list sent as a request header
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
enum:
|
||||
- +strings
|
||||
collectionFormat: csv
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
use Modern::Perl;
|
||||
|
||||
use Test::NoWarnings;
|
||||
use Test::More tests => 2;
|
||||
use Test::More tests => 3;
|
||||
|
||||
use Koha::Database;
|
||||
use Koha::Suggestions;
|
||||
|
|
@ -49,3 +49,60 @@ subtest 'suggester() tests' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'strings_map() tests' => sub {
|
||||
plan tests => 2;
|
||||
|
||||
$schema->txn_begin;
|
||||
|
||||
my $av_value1 = Koha::AuthorisedValue->new(
|
||||
{
|
||||
category => "SUGGEST_FORMAT",
|
||||
authorised_value => 'RECORD',
|
||||
lib => "Test format"
|
||||
}
|
||||
)->store;
|
||||
my $av_value2 = Koha::AuthorisedValue->new(
|
||||
{
|
||||
category => "SUGGEST_STATUS",
|
||||
authorised_value => 'WANTED',
|
||||
lib => "Test status"
|
||||
}
|
||||
)->store;
|
||||
my $suggestion = $builder->build_object(
|
||||
{ class => 'Koha::Suggestions', value => { suggestedby => undef, STATUS => 'WANTED', itemtype => 'RECORD' } } );
|
||||
|
||||
my $strings_map = $suggestion->strings_map( { public => 0 } );
|
||||
is_deeply(
|
||||
$strings_map,
|
||||
{
|
||||
STATUS => { str => 'Test status', type => 'av', category => 'SUGGEST_STATUS' },
|
||||
itemtype => { str => 'Test format', type => 'av', category => 'SUGGEST_FORMAT' },
|
||||
patronreason => { str => $suggestion->patronreason, type => 'av', category => 'OPAC_SUG' },
|
||||
},
|
||||
'Strings map is correct'
|
||||
);
|
||||
|
||||
my $av_value3 = Koha::AuthorisedValue->new(
|
||||
{
|
||||
category => "OPAC_SUG",
|
||||
authorised_value => 'OPAC',
|
||||
lib => "An OPAC reason"
|
||||
}
|
||||
)->store;
|
||||
|
||||
$suggestion->patronreason('OPAC');
|
||||
$strings_map = $suggestion->strings_map( { public => 0 } );
|
||||
is_deeply(
|
||||
$strings_map,
|
||||
{
|
||||
STATUS => { str => 'Test status', type => 'av', category => 'SUGGEST_STATUS' },
|
||||
itemtype => { str => 'Test format', type => 'av', category => 'SUGGEST_FORMAT' },
|
||||
patronreason => { str => 'An OPAC reason', type => 'av', category => 'OPAC_SUG' },
|
||||
},
|
||||
'Strings map is correct'
|
||||
);
|
||||
|
||||
$schema->txn_rollback;
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue