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

(-)a/Koha/Object/Mixin/AdditionalFields.pm (-2 / +2 lines)
Lines 232-238 REST API embed of additional_field_values Link Here
232
=cut
232
=cut
233
233
234
sub extended_attributes {
234
sub extended_attributes {
235
    my ($self, $extended_attributes) = @_;
235
    my ( $self, $extended_attributes ) = @_;
236
236
237
    if ($extended_attributes) {
237
    if ($extended_attributes) {
238
        $self->set_additional_fields($extended_attributes);
238
        $self->set_additional_fields($extended_attributes);
Lines 297-303 sub strings_map { Link Here
297
        );
297
        );
298
    }
298
    }
299
299
300
    my @sorted = sort { $a->{field_id} <=> $b->{field_id} } @{ $strings->{additional_field_values} };
300
    my @sorted    = sort { $a->{field_id} <=> $b->{field_id} } @{ $strings->{additional_field_values} };
301
    my @non_empty = grep { $_->{value_str} ne "" } @sorted;
301
    my @non_empty = grep { $_->{value_str} ne "" } @sorted;
302
    $strings->{additional_field_values} = \@non_empty;
302
    $strings->{additional_field_values} = \@non_empty;
303
303
(-)a/Koha/Objects/Mixin/AdditionalFields.pm (-5 / +11 lines)
Lines 60-79 sub filter_by_additional_fields { Link Here
60
60
61
=head3 extended_attributes_config
61
=head3 extended_attributes_config
62
62
63
    Returns a hash containing the configuration for extended attributes
64
63
=cut
65
=cut
64
66
65
sub extended_attributes_config {
67
sub extended_attributes_config {
66
    my ($self) = @_;
68
    my ($self) = @_;
67
69
68
    my $tablename_query = $self->extended_attributes_tablename_query;
69
70
    return {
70
    return {
71
        'id_field'        => { 'foreign' => 'record_id', 'self' => $self->_resultset->result_source->primary_columns },
71
        'id_field'     => { 'foreign' => 'record_id', 'self' => $self->_resultset->result_source->primary_columns },
72
        'key_field'       => 'field_id',
72
        'key_field'    => 'field_id',
73
        'schema_class'    => 'Koha::Schema::Result::AdditionalFieldValue',
73
        'schema_class' => 'Koha::Schema::Result::AdditionalFieldValue',
74
    };
74
    };
75
}
75
}
76
76
77
=head3 extended_attributes_tablename_query
78
79
    Returns a hash containing the tablename and operator for extended attributes.
80
81
=cut
82
77
sub extended_attributes_tablename_query {
83
sub extended_attributes_tablename_query {
78
    my ($self) = @_;
84
    my ($self) = @_;
79
85
(-)a/Koha/REST/V1/ERM/Licenses.pm (-6 / +8 lines)
Lines 85-99 sub add { Link Here
85
85
86
                my $body = $c->req->json;
86
                my $body = $c->req->json;
87
87
88
                my $user_roles = delete $body->{user_roles} // [];
88
                my $user_roles          = delete $body->{user_roles}          // [];
89
                my $documents = delete $body->{documents} // [];
89
                my $documents           = delete $body->{documents}           // [];
90
                my $extended_attributes = delete $body->{extended_attributes} // [];
90
                my $extended_attributes = delete $body->{extended_attributes} // [];
91
91
92
                my $license = Koha::ERM::License->new_from_api($body)->store;
92
                my $license = Koha::ERM::License->new_from_api($body)->store;
93
                $license->user_roles($user_roles);
93
                $license->user_roles($user_roles);
94
                $license->documents($documents);
94
                $license->documents($documents);
95
95
96
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
96
                my @extended_attributes =
97
                    map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
97
                $license->extended_attributes( \@extended_attributes );
98
                $license->extended_attributes( \@extended_attributes );
98
99
99
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
100
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
Lines 167-181 sub update { Link Here
167
168
168
                my $body = $c->req->json;
169
                my $body = $c->req->json;
169
170
170
                my $user_roles = delete $body->{user_roles} // [];
171
                my $user_roles          = delete $body->{user_roles}          // [];
171
                my $documents = delete $body->{documents} // [];
172
                my $documents           = delete $body->{documents}           // [];
172
                my $extended_attributes = delete $body->{extended_attributes} // [];
173
                my $extended_attributes = delete $body->{extended_attributes} // [];
173
174
174
                $license->set_from_api($body)->store;
175
                $license->set_from_api($body)->store;
175
                $license->user_roles($user_roles);
176
                $license->user_roles($user_roles);
176
                $license->documents($documents);
177
                $license->documents($documents);
177
178
178
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
179
                my @extended_attributes =
180
                    map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
179
                $license->extended_attributes( \@extended_attributes );
181
                $license->extended_attributes( \@extended_attributes );
180
182
181
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
183
                $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
(-)a/t/db_dependent/Koha/Object/Mixin/AdditionalFields.t (-16 / +15 lines)
Lines 285-293 subtest 'prepare_cgi_additional_field_values' => sub { Link Here
285
285
286
subtest 'strings_map() tests' => sub {
286
subtest 'strings_map() tests' => sub {
287
    plan tests => 1;
287
    plan tests => 1;
288
     $schema->txn_begin;
288
    $schema->txn_begin;
289
     Koha::AdditionalFields->search->delete;
289
    Koha::AdditionalFields->search->delete;
290
     my $license = Koha::ERM::License->new(
290
    my $license = Koha::ERM::License->new(
291
        {
291
        {
292
            name   => "license name",
292
            name   => "license name",
293
            type   => "national",
293
            type   => "national",
Lines 296-302 subtest 'strings_map() tests' => sub { Link Here
296
        }
296
        }
297
    );
297
    );
298
    $license->store()->discard_changes();
298
    $license->store()->discard_changes();
299
     my $field = Koha::AdditionalField->new(
299
    my $field = Koha::AdditionalField->new(
300
        {
300
        {
301
            tablename => 'erm_licenses',
301
            tablename => 'erm_licenses',
302
            name      => 'af_1',
302
            name      => 'af_1',
Lines 304-310 subtest 'strings_map() tests' => sub { Link Here
304
        }
304
        }
305
    );
305
    );
306
    $field->store()->discard_changes();
306
    $field->store()->discard_changes();
307
     my $field2 = Koha::AdditionalField->new(
307
    my $field2 = Koha::AdditionalField->new(
308
        {
308
        {
309
            tablename => 'erm_licenses',
309
            tablename => 'erm_licenses',
310
            name      => 'af_2',
310
            name      => 'af_2',
Lines 312-318 subtest 'strings_map() tests' => sub { Link Here
312
        }
312
        }
313
    );
313
    );
314
    $field2->store()->discard_changes();
314
    $field2->store()->discard_changes();
315
     my $value = 'some license value';
315
    my $value = 'some license value';
316
    $license->set_additional_fields(
316
    $license->set_additional_fields(
317
        [
317
        [
318
            {
318
            {
Lines 327-349 subtest 'strings_map() tests' => sub { Link Here
327
            }
327
            }
328
        ]
328
        ]
329
    );
329
    );
330
     $license->add_additional_fields(
330
    $license->add_additional_fields(
331
        {
331
        {
332
            $field2->id => ['second field'],
332
            $field2->id => ['second field'],
333
333
334
        },
334
        },
335
        'erm_licenses'
335
        'erm_licenses'
336
    );
336
    );
337
      my $av_category = Koha::AuthorisedValueCategory->new( { category_name => "AV_CAT_NAME" } );
337
    my $av_category = Koha::AuthorisedValueCategory->new( { category_name => "AV_CAT_NAME" } );
338
    $av_category->store()->discard_changes();
338
    $av_category->store()->discard_changes();
339
     my $av_value = Koha::AuthorisedValue->new(
339
    my $av_value = Koha::AuthorisedValue->new(
340
        {
340
        {
341
            category         => $av_category->category_name,
341
            category         => $av_category->category_name,
342
            authorised_value => 'BOB',
342
            authorised_value => 'BOB',
343
            lib              => "Robert"
343
            lib              => "Robert"
344
        }
344
        }
345
    );
345
    );
346
     my $av_field = Koha::AdditionalField->new(
346
    my $av_field = Koha::AdditionalField->new(
347
        {
347
        {
348
            tablename                 => "erm_licenses",
348
            tablename                 => "erm_licenses",
349
            name                      => "av_field",
349
            name                      => "av_field",
Lines 352-366 subtest 'strings_map() tests' => sub { Link Here
352
        }
352
        }
353
    );
353
    );
354
    $av_field->store()->discard_changes();
354
    $av_field->store()->discard_changes();
355
       $license->add_additional_fields(
355
    $license->add_additional_fields(
356
        {
356
        {
357
            $av_field->id => [ $av_value->authorised_value ],
357
            $av_field->id => [ $av_value->authorised_value ],
358
358
359
        },
359
        },
360
        'erm_licenses'
360
        'erm_licenses'
361
    );
361
    );
362
     my $values      = $license->get_additional_field_values_for_template;
362
    my $values      = $license->get_additional_field_values_for_template;
363
     my $strings_map = $license->strings_map;
363
    my $strings_map = $license->strings_map;
364
    is_deeply(
364
    is_deeply(
365
        $strings_map,
365
        $strings_map,
366
        {
366
        {
Lines 387-392 subtest 'strings_map() tests' => sub { Link Here
387
        },
387
        },
388
        'strings_map looks good'
388
        'strings_map looks good'
389
    );
389
    );
390
     $schema->txn_rollback;
390
    $schema->txn_rollback;
391
    ;
391
392
};
392
};
393
- 

Return to bug 35287