From db4dec821ac14fa77699549fc632c88d1e05f75e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 13 Oct 2017 17:35:11 -0300 Subject: [PATCH] Bug 19289: Use the ACQ framework to display bibliographic details MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ACQ MARC framework is only used for the ‘Item’ block. This patch add the ability to define biblio fields (!= 995 or 952) to customize the display of the bibliographic details when ordering. This new feature is controlled by a new pref: UseACQFrameworkForBiblioRecords Test plan: - Create a new installation to populate the ACQ framework correctly - Set the pref UseACQFrameworkForBiblioRecords to "Use" - Create a new order => You will see the lib from the ACQ framework - Add/remove/update biblio subfields in the ACQ framework - Create a new order => You should see the new subfields displayed Note for QA: I though I would be able to refactor existing code to make it more flexible, but it is a bit messy and lost a lot of time. I finally decided to copy/paste the existing code. I simplified it as, I think, we do not want the plugin, etc. like in the full biblio editor. Signed-off-by: Josef Moravec --- acqui/addorder.pl | 43 ++-- acqui/neworderempty.pl | 118 ++++++++++- catalogue/ISBDdetail.pl | 2 +- installer/data/mysql/atomicupdate/bug_19289.sql | 2 + installer/data/mysql/sysprefs.sql | 1 + .../prog/en/includes/html_helpers.inc | 12 ++ .../prog/en/modules/acqui/neworderempty.tt | 224 +++++++++++++-------- .../en/modules/admin/preferences/acquisitions.pref | 8 +- 8 files changed, 300 insertions(+), 110 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_19289.sql diff --git a/acqui/addorder.pl b/acqui/addorder.pl index c102779..fad6df7 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -139,6 +139,7 @@ use C4::Barcodes; # not just blindly call C4 functions and print a redirect. my $input = new CGI; +my $use_ACQ_framework = $input->param('use_ACQ_framework'); # Check if order total amount exceed allowed budget my $confirm_budget_exceeding = $input->param('confirm_budget_exceeding'); @@ -240,21 +241,31 @@ my $basket = Koha::Acquisition::Baskets->find($basketno); if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { #TODO:check to see if biblio exists unless ( $$orderinfo{biblionumber} ) { - #if it doesn't create it - my $record = TransformKohaToMarc( - { - "biblio.title" => "$$orderinfo{title}", - "biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "", - "biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "", - "biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "", - "biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "", - "biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "", - "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", - "biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", - "biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "", - "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "", - }); + my $record; + if ( $use_ACQ_framework ) { + my @tags = $input->multi_param('bib_tag'); + my @subfields = $input->multi_param('bib_subfield'); + my @field_values = $input->multi_param('bib_field_value'); + my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values ); + $record=MARC::Record::new_from_xml($xml, 'UTF-8'); + } else { + #if it doesn't create it + $record = TransformKohaToMarc( + { + "biblio.title" => "$$orderinfo{title}", + "biblio.author" => $$orderinfo{author} ? $$orderinfo{author} : "", + "biblio.seriestitle" => $$orderinfo{series} ? $$orderinfo{series} : "", + "biblioitems.isbn" => $$orderinfo{isbn} ? $$orderinfo{isbn} : "", + "biblioitems.ean" => $$orderinfo{ean} ? $$orderinfo{ean} : "", + "biblioitems.publishercode" => $$orderinfo{publishercode} ? $$orderinfo{publishercode} : "", + "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", + "biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", + "biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "", + "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "", + }); + + } C4::Acquisition::FillWithDefaultValues( $record ); # create the record in catalogue, with framework '' @@ -309,8 +320,8 @@ if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { unless ($itemhash{$itemid[$i]}){ $countdistinct++; } - push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i]; - push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i]; + push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i]; + push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i]; push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i]; push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i]; push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i]; diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index ab92985..b9d626e 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -89,8 +89,12 @@ use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; +use Koha::BiblioFrameworks; +use Koha::DateUtils qw( dt_from_string ); +use Koha::MarcSubfieldStructures; use Koha::ItemTypes; use Koha::Patrons; +use Koha::RecordProcessor; our $input = new CGI; my $booksellerid = $input->param('booksellerid'); # FIXME: else ERROR! @@ -174,21 +178,85 @@ if ( $ordernumber eq '' and defined $params->{'breedingid'}){ -my ( @order_user_ids, @order_users ); -if ( $ordernumber eq '' ) { # create order +my ( @order_user_ids, @order_users, @catalog_details ); +our $tagslib = GetMarcStructure(1, 'ACQ', { unsafe => 1 } ); +my ( $itemnumber_tag, $itemnumber_subtag ) = GetMarcFromKohaField( 'items.itemnumber', 'ACQ' ); +if ( not $ordernumber ) { # create order $new = 'yes'; - # $ordernumber=newordernum; - if ( $biblionumber && !$suggestionid ) { + if ( $biblionumber ) { $data = GetBiblioData($biblionumber); } - -# get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists -# otherwise, retrieve suggestion information. - if ($suggestionid) { - $data = ($biblionumber) ? GetBiblioData($biblionumber) : GetSuggestion($suggestionid); + # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists + # otherwise, retrieve suggestion information. + elsif ($suggestionid) { + $data = GetSuggestion($suggestionid); $budget_id ||= $data->{'budgetid'} // 0; } + + if ( not $biblionumber and Koha::BiblioFrameworks->find('ACQ') ) { + #my $acq_mss = Koha::MarcSubfieldStructures->search({ frameworkcode => 'ACQ', tagfield => { '!=' => $itemnumber_tag } }); + foreach my $tag ( sort keys %{$tagslib} ) { + next if $tag eq ''; + next if $tag eq $itemnumber_tag; # skip items fields + foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) { + my $mss = $tagslib->{$tag}{$subfield}; + next if IsMarcStructureInternal($mss); + next if $mss->{tab} == -1; + my $value = $mss->{defaultvalue}; + + if ($suggestionid and $mss->{kohafield}) { + # Reading suggestion info if ordering from a suggestion + if ( $mss->{kohafield} eq 'biblio.title' ) { + $value = $data->{title}; + } + elsif ( $mss->{kohafield} eq 'biblio.author' ) { + $value = $data->{author}; + } + elsif ( $mss->{kohafield} eq 'biblioitems.publishercode' ) { + $value = $data->{publishercode}; + } + elsif ( $mss->{kohafield} eq 'biblioitems.editionstatement' ) { + $value = $data->{editionstatement}; + } + elsif ( $mss->{kohafield} eq 'biblioitems.publicationyear' ) { + $value = $data->{publicationyear}; + } + elsif ( $mss->{kohafield} eq 'biblioitems.isbn' ) { + $value = $data->{isbn}; + } + elsif ( $mss->{kohafield} eq 'biblio.seriestitle' ) { + $value = $data->{seriestitle}; + } + } + + if ( $value eq '' ) { + + # get today date & replace <>, <>, <
> if provided in the default value + my $today_dt = dt_from_string; + my $year = $today_dt->strftime('%Y'); + my $month = $today_dt->strftime('%m'); + my $day = $today_dt->strftime('%d'); + $value =~ s/<>/$year/g; + $value =~ s/<>/$month/g; + $value =~ s/<
>/$day/g; + + # And <> with surname (?) + my $username = + ( C4::Context->userenv + ? C4::Context->userenv->{'surname'} + : "superlibrarian" ); + $value =~ s/<>/$username/g; + } + push @catalog_details, { + tag => $tag, + subfield => $subfield, + %$mss, # Do we need plugins support (?) + value => $value, + }; + } + } + } } else { #modify order $data = GetOrder($ordernumber); @@ -206,6 +274,37 @@ else { #modify order } } +# We can have: +# - no ordernumber but a biblionumber: from a subscription, from an existing record +# - no ordernumber, no biblionumber: from a suggestion, from a new order +if ( not $ordernumber or $biblionumber ) { + if ( C4::Context->preference('UseACQFrameworkForBiblioRecords') ) { + my $record = $biblionumber ? GetMarcBiblio({ biblionumber => $biblionumber }) : undef; + foreach my $tag ( sort keys %{$tagslib} ) { + next if $tag eq ''; + next if $tag eq $itemnumber_tag; # skip items fields + my @fields = $biblionumber ? $record->field($tag) : (); + foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) { + my $mss = $tagslib->{$tag}{$subfield}; + next if IsMarcStructureInternal($mss); + next if $mss->{tab} == -1; + # We only need to display the values + my $value = join '; ', map { $_->subfield( $subfield ) } @fields; + if ( $value ) { + push @catalog_details, { + tag => $tag, + subfield => $subfield, + %$mss, + value => $value, + }; + } + } + } + } +} + +$template->param( catalog_details => \@catalog_details, ); + my $suggestion; $suggestion = GetSuggestionInfo($suggestionid) if $suggestionid; @@ -255,6 +354,7 @@ if ($basketobj->effective_create_items eq 'ordering' && !$ordernumber) { UniqueItemFields => C4::Context->preference('UniqueItemFields'), ); } + # Get the item types list, but only if item_level_itype is YES. Otherwise, it will be in the item, no need to display it in the biblio my @itemtypes; @itemtypes = Koha::ItemTypes->search unless C4::Context->preference('item-level_itypes'); diff --git a/catalogue/ISBDdetail.pl b/catalogue/ISBDdetail.pl index 27cb699..71ac886 100755 --- a/catalogue/ISBDdetail.pl +++ b/catalogue/ISBDdetail.pl @@ -97,7 +97,7 @@ my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy', options => { interface => 'intranet', - frameworkcode => $framework + frameworkcode => 'ACQ' }, }); $record_processor->process($record); diff --git a/installer/data/mysql/atomicupdate/bug_19289.sql b/installer/data/mysql/atomicupdate/bug_19289.sql new file mode 100644 index 0000000..6cd328f --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_19289.sql @@ -0,0 +1,2 @@ +INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) +VALUES ('UseACQFrameworkForBiblioRecords','0','','Use the ACQ framework for the catalog details','YesNo'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index f6e666b..05e1c13 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -570,6 +570,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('UsageStatsLibraryType', '', 'public|school|academic|research|private|societyAssociation|corporate|government|religiousOrg|subscription', 'The library type to be shown on the Hea Koha community website', 'Choice'), ('UsageStatsLibraryUrl', '', NULL, 'The library URL to be shown on Hea Koha community website', 'Free'), ('UsageStatsPublicID', '', NULL, 'Public ID for Hea website', 'Free'), +('UseACQFrameworkForBiblioRecords','0','','Use the ACQ framework for the catalog details','YesNo'), ('UseAuthoritiesForTracings','1','0','Use authority record numbers for subject tracings instead of heading strings.','YesNo'), ('UseBranchTransferLimits','0','','If ON, Koha will will use the rules defined in branch_transfer_limits to decide if an item transfer should be allowed.','YesNo'), ('UseControlNumber','0','','If ON, record control number (w subfields) and control number (001) are used for linking of bibliographic records.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc index 0102720..bef9628 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -17,3 +17,15 @@ [% END %] [% END %] [% END %] + +[% BLOCK options_for_item_types %] + [% FOREACH itemtype IN itemtypes %] + [% IF itemtype.itemtype == selected_itemtype %] + + [% END %] +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index faa2db4..c2a3cc5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -7,6 +7,7 @@ [% INCLUDE 'additem.js.inc' %] +