View | Details | Raw Unified | Return to bug 33430
Collapse All | Expand All

(-)a/Koha/Suggestion.pm (+36 lines)
Lines 294-299 sub to_api_mapping { Link Here
294
    };
294
    };
295
}
295
}
296
296
297
=head3 strings_map
298
299
Returns a map of column name to string representations including the string.
300
301
=cut
302
303
sub strings_map {
304
    my ( $self, $params ) = @_;
305
306
    my $strings = {};
307
308
    my $required_strings = {
309
        STATUS       => 'SUGGEST_STATUS',
310
        itemtype     => 'SUGGEST_FORMAT',
311
        patronreason => 'OPAC_SUG',
312
    };
313
314
    foreach my $key ( keys %$required_strings ) {
315
        my $av = Koha::AuthorisedValues->search(
316
            { category => $required_strings->{$key}, authorised_value => $self->$key } );
317
        my $status_str =
318
              $av->count
319
            ? $params->{public}
320
                ? $av->next->opac_description
321
                : $av->next->lib
322
            : $self->$key;
323
324
        $strings->{$key} = {
325
            category => $required_strings->{$key},
326
            str      => $status_str,
327
            type     => 'av',
328
        };
329
    }
330
    return $strings;
331
}
332
297
=head1 AUTHOR
333
=head1 AUTHOR
298
334
299
Kyle M Hall <kyle@bywatersolutions.com>
335
Kyle M Hall <kyle@bywatersolutions.com>
(-)a/api/v1/swagger/definitions/suggestion.yaml (+4 lines)
Lines 191-194 properties: Link Here
191
      - boolean
191
      - boolean
192
      - "null"
192
      - "null"
193
    description: archived (processed) suggestion
193
    description: archived (processed) suggestion
194
  _strings:
195
    type:
196
      - object
197
      - "null"
194
additionalProperties: false
198
additionalProperties: false
(-)a/api/v1/swagger/paths/suggestions.yaml (+10 lines)
Lines 15-20 Link Here
15
      - $ref: "../swagger.yaml#/parameters/q_param"
15
      - $ref: "../swagger.yaml#/parameters/q_param"
16
      - $ref: "../swagger.yaml#/parameters/q_body"
16
      - $ref: "../swagger.yaml#/parameters/q_body"
17
      - $ref: "../swagger.yaml#/parameters/request_id_header"
17
      - $ref: "../swagger.yaml#/parameters/request_id_header"
18
      - name: x-koha-embed
19
        in: header
20
        required: false
21
        description: Embed list sent as a request header
22
        type: array
23
        items:
24
          type: string
25
          enum:
26
            - +strings
27
        collectionFormat: csv
18
    produces:
28
    produces:
19
      - application/json
29
      - application/json
20
    responses:
30
    responses:
(-)a/t/db_dependent/Koha/Suggestion.t (-2 / +58 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 2;
23
use Test::More tests => 3;
24
24
25
use Koha::Database;
25
use Koha::Database;
26
use Koha::Suggestions;
26
use Koha::Suggestions;
Lines 49-51 subtest 'suggester() tests' => sub { Link Here
49
49
50
    $schema->storage->txn_rollback;
50
    $schema->storage->txn_rollback;
51
};
51
};
52
- 
52
53
subtest 'strings_map() tests' => sub {
54
    plan tests => 2;
55
56
    $schema->txn_begin;
57
58
    my $av_value1 = Koha::AuthorisedValue->new(
59
        {
60
            category         => "SUGGEST_FORMAT",
61
            authorised_value => 'RECORD',
62
            lib              => "Test format"
63
        }
64
    )->store;
65
    my $av_value2 = Koha::AuthorisedValue->new(
66
        {
67
            category         => "SUGGEST_STATUS",
68
            authorised_value => 'WANTED',
69
            lib              => "Test status"
70
        }
71
    )->store;
72
    my $suggestion = $builder->build_object(
73
        { class => 'Koha::Suggestions', value => { suggestedby => undef, STATUS => 'WANTED', itemtype => 'RECORD' } } );
74
75
    my $strings_map = $suggestion->strings_map( { public => 0 } );
76
    is_deeply(
77
        $strings_map,
78
        {
79
            STATUS       => { str => 'Test status',             type => 'av', category => 'SUGGEST_STATUS' },
80
            itemtype     => { str => 'Test format',             type => 'av', category => 'SUGGEST_FORMAT' },
81
            patronreason => { str => $suggestion->patronreason, type => 'av', category => 'OPAC_SUG' },
82
        },
83
        'Strings map is correct'
84
    );
85
86
    my $av_value3 = Koha::AuthorisedValue->new(
87
        {
88
            category         => "OPAC_SUG",
89
            authorised_value => 'OPAC',
90
            lib              => "An OPAC reason"
91
        }
92
    )->store;
93
94
    $suggestion->patronreason('OPAC');
95
    $strings_map = $suggestion->strings_map( { public => 0 } );
96
    is_deeply(
97
        $strings_map,
98
        {
99
            STATUS       => { str => 'Test status',    type => 'av', category => 'SUGGEST_STATUS' },
100
            itemtype     => { str => 'Test format',    type => 'av', category => 'SUGGEST_FORMAT' },
101
            patronreason => { str => 'An OPAC reason', type => 'av', category => 'OPAC_SUG' },
102
        },
103
        'Strings map is correct'
104
    );
105
106
    $schema->txn_rollback;
107
108
};

Return to bug 33430