From b5bb5ba527ee7eeec38a9cecc1126486ac676399 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Thu, 1 Sep 2011 16:18:14 +0100 Subject: [PATCH] [SIGNED-OFF] Bug 6831: Add ability to enter adding child record from parent Simplifies the adding of analytical records and ensures that the data populating the 773 tag is correct. From the host record add child record is selected and create bib is entered to generate a new record with host item tag populated from the parent Caveat: currently prepare_host_field only returns a field for MARC21. Values for UNIMARC and NORMARC can easily be added but should be done by someone familar with those formats and conventions Signed-off-by: Katrin Fischer To test: - create a new record --> if you enter a value in 001 anaytics will use that in $w for linking later --> if you set 000/LDR 19 - Multipart resource record level to 'a' there will be a link from the parent record to the child record later - save your record and go to the staff detail page - in toolbar select 'New' > 'New child record' - check field 773, 245 and 001 from the parent record should have been copied there - check links between child and parent in staff Signed-off-by: Katrin Fischer Fixed conflicts in all 3 files. --- C4/Biblio.pm | 57 ++++++++++++++++++++ cataloguing/addbiblio.pl | 34 ++++++++++-- .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 20 +++++-- 3 files changed, 100 insertions(+), 11 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 81da91b..424a296 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -131,6 +131,7 @@ BEGIN { &TransformHtmlToMarc &TransformHtmlToXml &GetNoZebraIndexes + prepare_host_field ); } @@ -3628,9 +3629,65 @@ sub GetHolds { return ($holds); } +=head2 prepare_host_field + +$marcfield = prepare_host_field( $hostbiblioitem, $marcflavour ); +Generate the host item entry for an analytic child entry + +=cut + +sub prepare_host_field { + my ( $hostbiblio, $marcflavour ) = @_; + $marcflavour ||= 'MARC21'; + my $host = GetMarcBiblio($hostbiblio); + if ( $marcflavour eq 'MARC21' ) { + + # unfortunately as_string does not 'do the right thing' + # if field returns undef + my %sfd; + my $field; + if ( $field = $host->author() ) { + $sfd{a} = $field; + } + if ( $field = $host->title() ) { + $sfd{t} = $field; + } + if ( $field = $host->field('260') ) { + my $s = $field->as_string('abc'); + if ($s) { + $sfd{d} = $s; + } + } + if ( $field = $host->field('240') ) { + my $s = $field->as_string(); + if ($s) { + $sfd{b} = $s; + } + } + if ( $field = $host->field('022') ) { + my $s = $field->as_string('a'); + if ($s) { + $sfd{x} = $s; + } + } + if ( $field = $host->field('020') ) { + my $s = $field->as_string('a'); + if ($s) { + $sfd{x} = $s; + } + } + if ( $field = $host->field('001') ) { + $sfd{w} = $field->data(),; + } + my $host_field = MARC::Field->new( 773, '0', ' ', %sfd ); + return $host_field; + } + return; +} 1; + __END__ =head1 AUTHOR diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 7fabb77..22d1b8d 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -729,6 +729,7 @@ sub build_tabs { my $input = new CGI; my $error = $input->param('error'); my $biblionumber = $input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio. +my $parentbiblio = $input->param('parentbiblionumber'); my $breedingid = $input->param('breedingid'); my $z3950 = $input->param('z3950'); my $op = $input->param('op'); @@ -808,13 +809,25 @@ if (($biblionumber) && !($breedingid)){ if ($breedingid) { ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ; } + #populate hostfield if hostbiblionumber is available -if ($hostbiblionumber){ - my $marcflavour = C4::Context->preference("marcflavour"); - $record=MARC::Record->new(); - $record->leader(''); - my $field = PrepHostMarcField($hostbiblionumber, $hostitemnumber,$marcflavour); - $record->append_fields($field); +if ($hostbiblionumber) { + my $marcflavour = C4::Context->preference("marcflavour"); + $record = MARC::Record->new(); + $record->leader(''); + my $field = + PrepHostMarcField( $hostbiblionumber, $hostitemnumber, $marcflavour ); + $record->append_fields($field); +} + +# This is a child record +if ($parentbiblio) { + my $marcflavour = C4::Context->preference('marcflavour'); + $record = MARC::Record->new(); + my $hostfield = prepare_host_field($parentbiblio,$marcflavour); + if ($hostfield) { + $record->append_fields($hostfield); + } } $is_a_modif = 0; @@ -982,3 +995,12 @@ $template->param( ); output_html_with_http_headers $input, $cookie, $template->output; + +sub get_host_control_num { + my $host_biblio_nr = shift; + my $host = GetMarcBiblio($host_biblio_nr); + my $control_num = GetMarcControlnumber($host, C4::Context->preference('marcflavour')); + $host = GetBiblioData($host_biblio_nr); + $host->{control_number} = $control_num; + return $host; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc index 5159d2a..be2f74f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -81,11 +81,21 @@ function confirm_items_deletion() { YAHOO.util.Event.onContentReady("cattoolbar", function () { // Menu for new record, new item, new subscription var newmenu = [ - [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{text: _("New Record"), url: "/cgi-bin/koha/cataloguing/addbiblio.pl" },[% END %] - [% IF ( CAN_user_editcatalogue_edit_items ) %]{text: _("New Item"), url: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber %]#additema" },[% END %] - [% IF ( CAN_user_serials_create_subscription ) %] - {text: _("New Subscription"), url: "/cgi-bin/koha/serials/subscription-add.pl?biblionumber_for_new_subscription=[% biblionumber %]"},[% END %] - [% IF ( EasyAnalyticalRecords ) %][% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{text: _("Analyze items"), url: "/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber %]&analyze=1" },[% END %][% END %] + [% IF CAN_user_editcatalogue_edit_catalogue %] + {text: _("New Record"), url: "/cgi-bin/koha/cataloguing/addbiblio.pl" }, + [% END %] + [% IF ( CAN_user_editcatalogue_edit_items ) %] + {text: _("New Item"), url: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber %]#additema" }, + [% END %] + [% IF ( CAN_user_serials_create_subscription ) %] + {text: _("New Subscription"), url: "/cgi-bin/koha/serials/subscription-add.pl?biblionumber_for_new_subscription=[% biblionumber %]"}, + [% END %] + [% IF ( EasyAnalyticalRecords && CAN_user_editcatalogue_edit_catalogue ) %] + {text: _("Analyze Items"), url: "/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber %]&analyze=1" }, + [% END %] + [% IF CAN_user_editcatalogue_edit_catalogue %] + {text: _("New Child Record"), url: "/cgi-bin/koha/cataloguing/addbiblio.pl?parentbiblionumber=[% biblionumber %]" }, + [% END %] ]; if(newmenu.length){ new YAHOO.widget.Button({ -- 1.7.5.4