From 8f978a3d7628056e86c6ee598502385b19355973 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 10 Jun 2019 03:09:55 +0000 Subject: [PATCH] Bug 23111: Set custom bibliographic framework as default This patch adds a new system preference (DefaultBibliographicFramework). Using this a librarian can select the bibliographic framework code to set the the bibliographic framework that will be displayed as default when: * Importing batch of biblio records * Editing a biblio record with no mapped biblio framework Test plan: 1. Apply patch 2. Run ./updatedatabase.pl (in installer/data/mysql) from the Koha shell to implement db changes 3. Search for the syspref DefaultBibliographicFramework in Administration module 4. Notice the syspref has the value 'Default' 5. Locate and edit the record of a bibliographic record not mapped to a framework and notice 'Default' is ticked when you click on 'Settings' 6. Click 'Save' and confirm the frameworkcode of the bibliorecord is Default (stored in the database as empty). You can do this by running the SQL: SELECT frameworkcode FROM biblio WHERE biblionumber=; 7. Import a batch of biblio records and notice that 'Default' is displayed as the framework to be used 8. Confirm the frameworkcode of one of the imported biblio records is default. Do this by running the SQL: SELECT frameworkcode FROM biblio WHERE biblionumber=; 9. Select a different frameworkcode (such as Acquisitions) in the DefaultBibliographicFramework syspref 10. Repeat step 5 but notice the DefaultBibliographicFramework framework as shown as the framework 11. Confirm the biblio has the new frameworkcode. You can do this by running the SQL: SELECT frameworkcode FROM biblio WHERE biblionumber=; 12. Repeat step 7 and notice the DefaultBibliographicFramework is shown as the framework to be used 13. Confirm the biblios imported in step 12 have the correct frameworkcode by running the following SQL: SELECT frameworkcode FROM biblio WHERE biblionumber=; Authored-by: Alex Buckley Sponsored-by: Brimbank Library, Australia --- Koha/BiblioFramework.pm | 18 ++++++++++++++++ admin/preferences.pl | 9 ++++++++ cataloguing/addbiblio.pl | 8 +++++++- ...r290627_set_default_bibliographic_framework.sql | 1 + .../en/modules/admin/preferences/cataloguing.pref | 5 +++++ .../prog/en/modules/tools/manage-marc-import.tt | 24 +++++++++++++++------- tools/manage-marc-import.pl | 6 ++++++ 7 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/wr290627_set_default_bibliographic_framework.sql diff --git a/Koha/BiblioFramework.pm b/Koha/BiblioFramework.pm index d9ade57b2b..418af028de 100644 --- a/Koha/BiblioFramework.pm +++ b/Koha/BiblioFramework.pm @@ -41,4 +41,22 @@ sub _type { return 'BiblioFramework'; } +=head2 GetFrameworkSources + my $sources = GetFrameworkSources(); + + Returns reference to hash of references to + the framework sources, keyed on frameworkcode. +=cut + +sub GetFrameworkSources { + my %framework_sources = (); + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT * FROM `biblio_framework`"); + $sth->execute(); + while (my $source = $sth->fetchrow_hashref) { + $framework_sources{ $source->{'frameworkcode'} } = $source; + } + return \%framework_sources; + } + 1; diff --git a/admin/preferences.pl b/admin/preferences.pl index 92c5bbee72..70a3ca6405 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -29,6 +29,7 @@ use C4::Log; use C4::Output; use C4::Templates; use Koha::Acquisition::Currencies; +use Koha::BiblioFramework; use File::Spec; use IO::File; use YAML::Syck qw(); @@ -89,6 +90,14 @@ sub _get_chunk { if ( $options{'choices'} eq 'class-sources' ) { my $sources = GetClassSources(); $options{'choices'} = { map { $_ => $sources->{$_}->{'description'} } keys %$sources }; + } elsif ( $options{'choices'} eq 'framework-sources' ) { + my $sources = Koha::BiblioFramework::GetFrameworkSources(); + + #Add framework to syspref dropdown with a frameworkcode of 'Default' so users can choose to not use + #custom bibliographic frameworks as default bib framework + $sources->{'Default'}->{'frameworkcode'} = 'Default'; + + $options{'choices'} = { map { $_ => $sources->{$_}->{'frameworkcode'} } keys %$sources }; } elsif ( $options{'choices'} eq 'opac-templates' ) { $options{'choices'} = { map { $_ => $_ } getallthemes( 'opac' ) } } elsif ( $options{'choices'} eq 'staff-templates' ) { diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 6478bb2dfe..cab930adfa 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -35,6 +35,7 @@ use C4::ClassSource; use C4::ImportBatch; use C4::Charset; use Koha::BiblioFrameworks; +use Koha::BiblioFramework; use Koha::DateUtils; use Koha::ItemTypes; @@ -709,7 +710,12 @@ if ($frameworkcode eq 'FA'){ $userflags = 'fast_cataloging'; } -$frameworkcode = '' if ( $frameworkcode eq 'Default' ); +if (( C4::Context->preference("DefaultBibliographicFramework") && C4::Context->preference("DefaultBibliographicFramework") ne 'Default' )) { + $frameworkcode = C4::Context->preference("DefaultBibliographicFramework"); +} else { + $frameworkcode = '' if ( $frameworkcode eq 'Default' ); +} + my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "cataloguing/addbiblio.tt", diff --git a/installer/data/mysql/atomicupdate/wr290627_set_default_bibliographic_framework.sql b/installer/data/mysql/atomicupdate/wr290627_set_default_bibliographic_framework.sql new file mode 100644 index 0000000000..2a7adcc69c --- /dev/null +++ b/installer/data/mysql/atomicupdate/wr290627_set_default_bibliographic_framework.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('DefaultBibliographicFramework','Default',NULL,'Default bibliographic framework used by the Cataloging framework','FrameworkSources'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref index dbfd788c66..9e866fd08d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -7,6 +7,11 @@ Cataloging: choices: class-sources - as the default classification source. - + - Use + - pref: DefaultBibliographicFramework + choices: framework-sources + - as the default bibliographic framework to be used by cataloging module. + - - pref: advancedMARCeditor choices: yes: "Don't display" diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt index e384b13fdb..dbf973af49 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE Koha %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Tools › Manage staged MARC records @@ -203,15 +204,24 @@ <input type="hidden" name="import_batch_id" value="[% import_batch_id | html %]" /> <fieldset class="action"> [% IF ( record_type != 'auth' ) %] - Add new bibliographic records into this framework: - <select name="framework" id="frameworks"> - <option value="">Default</option> - [% FOREACH framework IN frameworks %] - <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> - [% END %] - </select> + Add new bibliographic records into this framework: + <select name="framework" id="frameworks"> + + [% IF defaultframework %] + <option value="[% defaultframework.frameworkcode | html %]" selected="selected">[% defaultframework.frameworktext | html %]</option> + [% ELSE %] + <option value="" selected="selected">Default</option> + [% END %] + + [% FOREACH framework IN frameworks %] + [% IF defaultframework.frameworkcode != framework.frameworkcode %] + <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> + [% END %] + [% END %] + </select> [% END %] <br/> + <input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" /> </fieldset> </form> diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl index 4fea4005d7..446a15cd0b 100755 --- a/tools/manage-marc-import.pl +++ b/tools/manage-marc-import.pl @@ -63,7 +63,13 @@ our $sessionID = $cookies{'CGISESSID'}->value; our $dbh = C4::Context->dbh; my $frameworks = Koha::BiblioFrameworks->search({ tagfield => { 'not' => undef } }, { join => 'marc_tag_structure', distinct => 'frameworkcode', order_by => ['frameworktext'] }); + $template->param( frameworks => $frameworks ); +if ( (C4::Context->preference('DefaultBibliographicFramework') && C4::Context->preference('DefaultBibliographicFramework') ne 'Default')) { + my $frameworkcode = C4::Context->preference('DefaultBibliographicFramework'); + my $defaultframework = Koha::BiblioFrameworks->find($frameworkcode); + $template->param( defaultframework => $defaultframework ); +} if ($op eq "create_labels") { #create a batch of labels, then lose $op & $import_batch_id so we get back to import batch list. -- 2.11.0