From ae307f7a72a80a859982ff6c8e9d07f931e2aacb 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 Signed-off-by: Nicolas Legrand --- 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 | 223 +++++++++++++-------- .../en/modules/admin/preferences/acquisitions.pref | 7 + 8 files changed, 299 insertions(+), 109 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_19289.sql diff --git a/acqui/addorder.pl b/acqui/addorder.pl index 16fc89c1eb..17b50e6185 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -138,6 +138,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'); @@ -239,21 +240,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 '' @@ -308,8 +319,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 680be6ab45..fbfc187e68 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -88,8 +88,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! @@ -173,21 +177,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); @@ -205,6 +273,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; @@ -254,6 +353,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 27cb699026..71ac8861f6 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 0000000000..6cd328f5fa --- /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 76bb2cc03a..7be2797d99 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -577,6 +577,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 01027204c6..bef96284ff 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 f9b4a15dcb..9c5d689f2a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -115,95 +115,121 @@ [% END %] -
  1. - [% IF ( biblionumber ) %] - Title - [% title |html %] - [% ELSE %] - - - Required - [% END %] -
  2. -
  3. - [% IF ( biblionumber ) %] - Author: - [% author %] - [% ELSE %] - - - [% END %] -
  4. -
  5. - [% IF ( biblionumber ) %] - Publisher: - [% publishercode %] - [% ELSE %] - - - [% END %] -
  6. -
  7. - [% IF ( biblionumber ) %] - Edition: - [% editionstatement %] + [% IF NOT Koha.Preference('UseACQFrameworkForBiblioRecords') OR NoACQframework %] +
    1. + [% IF ( biblionumber ) %] + Title + [% title |html %] + [% ELSE %] + + + Required + [% END %] +
    2. +
    3. + [% IF ( biblionumber ) %] + Author: + [% author %] + [% ELSE %] + + + [% END %] +
    4. +
    5. + [% IF ( biblionumber ) %] + Publisher: + [% publishercode %] + [% ELSE %] + + + [% END %] +
    6. +
    7. + [% IF ( biblionumber ) %] + Edition: + [% editionstatement %] - [% ELSE %] - - - [% END %] -
    8. -
    9. - [% IF ( biblionumber ) %] - Publication year: - [% publicationyear %] - [% ELSE %] - - - [% END %] -
    10. -
    11. - [% IF ( biblionumber ) %] - ISBN: - [% isbn %] - [% ELSE %] - - - [% END %] -
    12. - [% IF (UNIMARC) %] -
    13. - [% IF ( biblionumber ) %] - EAN: - [% ean %] - [% ELSE %] - - - [% END %] -
    14. - [% END %] -
    15. - [% IF ( biblionumber ) %] - Series: - [% seriestitle %] - [% ELSE %] - - - [% END %] -
    16. - [% UNLESS ( biblionumber ) %] - [% IF ( itemtypeloop ) %] + [% ELSE %] + + + [% END %] +
    17. - Item type: - [% publicationyear %] + [% ELSE %] + + + [% END %] +
    18. +
    19. + [% IF ( biblionumber ) %] + ISBN: + [% isbn %] + [% ELSE %] + + + [% END %] +
    20. + [% IF (UNIMARC) %] +
    21. + [% IF ( biblionumber ) %] + EAN: + [% ean %] + [% ELSE %] + + [% END %] -
    22. [% END %] +
    23. + [% IF ( biblionumber ) %] + Series: + [% seriestitle %] + [% ELSE %] + + + [% END %] +
    24. + [% UNLESS ( biblionumber ) %] + [% IF ( itemtypeloop ) %] +
    25. + Item type: + +
    26. + [% END %] + [% END %] +
    + [% ELSE %] + + [% IF biblionumber %] +
      + [% FOREACH field IN catalog_details %] +
    1. +
      + + [% field.value %] +
      +
    2. + [% END %] +
    + [% ELSE %] +
      + [% FOREACH field IN catalog_details %] +
    1. +
      + [% PROCESS display_subfield field=field %] +
      +
    2. + [% END %] +
    [% END %] -
+ [% END %] [% IF ( suggestionid ) %] @@ -679,3 +705,34 @@ [% END %] [% INCLUDE 'intranet-bottom.inc' %] + +[% BLOCK display_subfield %] + [% IF field.mandatory %] + + [% ELSE %] + + [% END %] + [% IF field.authorised_value %] + [% SWITCH field.authorised_value %] + [% CASE 'branches' %] + + [% CASE 'itemtypes' %] + + [% CASE 'cn_source' %] + [% CASE %] + [% PROCESS 'av-build-dropbox.inc' name="bib_field_value", category=field.authorised_value, default="FIXME" %] + [% END %] + [% ELSE %] + + [% END %] + + + + [% IF field.mandatory %] Required[% END %] +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref index ac63e2c2f2..bf5d4bb6bd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref @@ -85,6 +85,13 @@ Acquisitions: - "
Example: [30] Sets purgation of suggestions for those older than 30 days." -
(Used when the cronjob purge_suggestions.pl is active and called without a specific number of days) + - + - pref: UseACQFrameworkForBiblioRecords + default: no + choices: + yes: "Use" + no: "Don't use" + - " the framework 'ACQ' for bibliographic records fields" Printing: - - Use the -- 2.11.0