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

(-)a/Koha/ERM/EHoldings/Title.pm (-19 / +21 lines)
Lines 38-67 Koha::ERM::EHoldings::Title - Koha ERM Title Object class Link Here
38
=cut
38
=cut
39
39
40
sub store {
40
sub store {
41
    my ($self) = @_;
41
    my ($self, $args) = @_;
42
42
43
    my $create_linked_biblio = $args->{create_linked_biblio} || 0;
43
    # FIXME This is terrible and ugly, we need to:
44
    # FIXME This is terrible and ugly, we need to:
44
    # * Provide a mapping for each attribute of title
45
    # * Provide a mapping for each attribute of title
45
    # * Create a txn
46
    # * Create a txn
46
47
47
    # If the 'title' is already linked to a biblio, then we update the title subfield only
48
    if($create_linked_biblio) {
48
    if ( $self->biblio_id ) {
49
        # If the 'title' is already linked to a biblio, then we update the title subfield only
49
        my $biblio = Koha::Biblios->find( $self->biblio_id );
50
        if ( $self->biblio_id ) {
50
        my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title');
51
            my $biblio = Koha::Biblios->find( $self->biblio_id );
51
        my $record      = $biblio->metadata->record();
52
            my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title');
52
        my $title_field = $record->field($title_tag);
53
            my $record      = $biblio->metadata->record();
53
        $title_field->update( $title_subfield => $self->publication_title );
54
            my $title_field = $record->field($title_tag);
54
        C4::Biblio::ModBiblio( $record, $self->biblio_id, '' );
55
            $title_field->update( $title_subfield => $self->publication_title );
55
    } else {
56
            C4::Biblio::ModBiblio( $record, $self->biblio_id, '' );
56
57
        } else {
57
        # If it's not linked, we create a simple biblio and save the biblio id to the 'title'
58
            # If it's not linked, we create a simple biblio and save the biblio id to the 'title'
58
        my $marc_record = TransformKohaToMarc(
59
            my $marc_record = TransformKohaToMarc(
59
            {
60
                {
60
                'biblio.title' => $self->publication_title,
61
                    'biblio.title' => $self->publication_title,
61
            }
62
                }
62
        );
63
            );
63
        my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '' );
64
            my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '' );
64
        $self->biblio_id($biblio_id);
65
            $self->biblio_id($biblio_id);
66
        }
65
    }
67
    }
66
68
67
    $self = $self->SUPER::store;
69
    $self = $self->SUPER::store;
(-)a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm (-3 / +5 lines)
Lines 87-95 sub add { Link Here
87
87
88
                my $body = $c->req->json;
88
                my $body = $c->req->json;
89
89
90
                my $resources = delete $body->{resources} // [];
90
                my $resources            = delete $body->{resources}            // [];
91
                my $create_linked_biblio = delete $body->{create_linked_biblio} // 0;
91
92
92
                my $title = Koha::ERM::EHoldings::Title->new_from_api($body)->store;
93
                my $title = Koha::ERM::EHoldings::Title->new_from_api($body)->store({ create_linked_biblio => $create_linked_biblio});
93
94
94
                $title->resources($resources);
95
                $title->resources($resources);
95
96
Lines 159-166 sub update { Link Here
159
                my $body = $c->req->json;
160
                my $body = $c->req->json;
160
161
161
                my $resources = delete $body->{resources} // [];
162
                my $resources = delete $body->{resources} // [];
163
                my $create_linked_biblio = delete $body->{create_linked_biblio} // 0;
162
164
163
                $title->set_from_api($body)->store;
165
                $title->set_from_api($body)->store( { create_linked_biblio => $create_linked_biblio } );
164
166
165
                $title->resources($resources);
167
                $title->resources($resources);
166
168
(-)a/api/v1/swagger/definitions/erm_eholdings_title.yaml (+5 lines)
Lines 144-149 properties: Link Here
144
    description: Resource containing this title
144
    description: Resource containing this title
145
    items:
145
    items:
146
      $ref: erm_eholdings_resource.yaml
146
      $ref: erm_eholdings_resource.yaml
147
  create_linked_biblio:
148
    description: should a linked biblio be created
149
    type:
150
      - boolean
151
      - "null"
147
152
148
additionalProperties: false
153
additionalProperties: false
149
required:
154
required:
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue (-1 / +22 lines)
Lines 366-371 Link Here
366
                        </li>
366
                        </li>
367
                    </ol>
367
                    </ol>
368
                </fieldset>
368
                </fieldset>
369
                <fieldset class="rows">
370
                    <legend>
371
                        {{
372
                            $__("%s linked biblio record").format(
373
                                title.title_id ? "Update" : "Create"
374
                            )
375
                        }}:
376
                    </legend>
377
                    <label for="create_linked_biblio"
378
                        >{{
379
                            $__("%s record").format(
380
                                title.title_id ? "Update" : "Create"
381
                            )
382
                        }}:</label
383
                    >
384
                    <input
385
                        type="checkbox"
386
                        id="create_linked_biblio"
387
                        v-model="title.create_linked_biblio"
388
                    />
389
                </fieldset>
369
                <EHoldingsTitlesFormAddResources :resources="title.resources" />
390
                <EHoldingsTitlesFormAddResources :resources="title.resources" />
370
                <fieldset class="action">
391
                <fieldset class="action">
371
                    <input type="submit" :value="$__('Submit')" />
392
                    <input type="submit" :value="$__('Submit')" />
Lines 429-434 export default { Link Here
429
                preceding_publication_title_id: "",
450
                preceding_publication_title_id: "",
430
                access_type: "",
451
                access_type: "",
431
                resources: [],
452
                resources: [],
453
                create_linked_biblio: false,
432
            },
454
            },
433
            initialized: false,
455
            initialized: false,
434
        }
456
        }
435
- 

Return to bug 36618