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:
Matt Blenkinsop 2025-05-08 11:02:29 +01:00 committed by Katrin Fischer
parent 244ce5396b
commit 31364ab898
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
4 changed files with 108 additions and 1 deletions

View File

@ -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>

View File

@ -191,4 +191,8 @@ properties:
- boolean
- "null"
description: archived (processed) suggestion
_strings:
type:
- object
- "null"
additionalProperties: false

View File

@ -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:

View File

@ -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;
};