From ebe11f70e288ddd0d2f1b448fa09550483fce453 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Dec 2020 17:07:36 +0100 Subject: [PATCH] Bug 8976: Sort subfields for authority records Same patch for the authority frameworks/records Sponsored-by: Orex Digital Signed-off-by: Michal Denar Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- C4/AuthoritiesMarc.pm | 12 +++--- admin/auth_subfields_structure.pl | 15 ++++--- authorities/authorities.pl | 13 ++++--- .../data/mysql/atomicupdate/bug_8976.perl | 9 ++++- installer/data/mysql/kohastructure.sql | 1 + .../modules/admin/auth_subfields_structure.tt | 39 +++++++++++++++---- 6 files changed, 65 insertions(+), 24 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index b20293b56a..2d80c417a2 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -471,10 +471,10 @@ sub GetTagsLabels { $res->{$tag}->{repeatable} = $repeatable; } $sth= $dbh->prepare( -"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl,defaultvalue +"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl,defaultvalue, display_order FROM auth_subfield_structure WHERE authtypecode=? -ORDER BY tagfield,tagsubfield" +ORDER BY tagfield, display_order, tagsubfield" ); $sth->execute($authtypecode); @@ -485,17 +485,18 @@ ORDER BY tagfield,tagsubfield" my $seealso; my $hidden; my $isurl; - my $link; my $defaultvalue; + my $display_order; while ( ( $tag, $subfield, $liblibrarian, , $libopac, $tab, $mandatory, $repeatable, $authorised_value, $authtypecode, $value_builder, $kohafield, $seealso, $hidden, - $isurl, $defaultvalue, $link ) + $isurl, $defaultvalue, $display_order ) = $sth->fetchrow ) { + $res->{$tag}->{$subfield}->{subfield} = $subfield; $res->{$tag}->{$subfield}->{lib} = ($forlibrarian or !$libopac)?$liblibrarian:$libopac; $res->{$tag}->{$subfield}->{tab} = $tab; $res->{$tag}->{$subfield}->{mandatory} = $mandatory; @@ -507,9 +508,10 @@ ORDER BY tagfield,tagsubfield" $res->{$tag}->{$subfield}->{seealso} = $seealso; $res->{$tag}->{$subfield}->{hidden} = $hidden; $res->{$tag}->{$subfield}->{isurl} = $isurl; - $res->{$tag}->{$subfield}->{link} = $link; $res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue; + $res->{$tag}->{$subfield}->{display_order} = $display_order; } + return $res; } diff --git a/admin/auth_subfields_structure.pl b/admin/auth_subfields_structure.pl index c68a8aa28e..d7dba6c002 100755 --- a/admin/auth_subfields_structure.pl +++ b/admin/auth_subfields_structure.pl @@ -34,7 +34,7 @@ sub string_search { my $dbh = C4::Context->dbh; $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); - my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield"); + my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield, display_order"); $sth->execute("$searchstring%",$authtypecode); my $results = $sth->fetchall_arrayref({}); return (scalar(@$results), $results); @@ -124,7 +124,7 @@ if ($op eq 'add_form') { closedir DIR; # build values list - my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'"); + my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=? order by display_order"); # and tagsubfield='$tagsubfield'"); $sth->execute($tagfield,$authtypecode); my @loop_data = (); my $i=0; @@ -189,9 +189,9 @@ if ($op eq 'add_form') { $template->param(tagfield => "$input->param('tagfield')"); # my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl) # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl,defaultvalue) - values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?, defaultvalue=? + my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl,defaultvalue, display_order) + values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?, defaultvalue=?, display_order=? where authtypecode=? and tagfield=? and tagsubfield=?"); my @tagsubfield = $input->multi_param('tagsubfield'); my @liblibrarian = $input->multi_param('liblibrarian'); @@ -205,6 +205,8 @@ if ($op eq 'add_form') { my @frameworkcodes = $input->multi_param('frameworkcode'); my @value_builder =$input->multi_param('value_builder'); my @defaultvalue = $input->multi_param('defaultvalue'); + + my $display_order; for (my $i=0; $i<= $#tagsubfield ; $i++) { my $tagfield =$input->param('tagfield'); my $tagsubfield =$tagsubfield[$i]; @@ -241,6 +243,7 @@ if ($op eq 'add_form') { $hidden, $isurl, $defaultvalue, + $display_order->{$tagfield} || 0, ( $authtypecode, $tagfield, @@ -265,8 +268,10 @@ if ($op eq 'add_form') { $hidden, $isurl, $defaultvalue, + display_order => $display_order->{$tagfield} || 0, ); } + $display_order->{$tagfield}++; } } print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 7131254b65..103e10698a 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -477,14 +477,17 @@ sub build_tabs { } else { my @subfields_data; - foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) { - next if ( length $subfield != 1 ); - next if $tagslib->{$tag}->{$subfield}->{hidden} && $subfield ne '9'; - next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop ); + foreach my $subfield ( + sort { $a->{display_order} <=> $b->{display_order} || $a->{subfield} cmp $b->{subfield} } + grep { ref($_) && %$_ } # Not a subfield (values for "important", "lib", "mandatory", etc.) or empty + values %{ $tagslib->{$tag} } ) + { + next if $subfield->{hidden} && $subfield->{subfield} ne '9'; + next if ( $subfield->{tab} ne $tabloop ); push( @subfields_data, &create_input( - $tag, $subfield, '', $index_tag, $tabloop, $record, + $tag, $subfield->{subfield}, '', $index_tag, $tabloop, $record, $authorised_values_sth,$input ) ); diff --git a/installer/data/mysql/atomicupdate/bug_8976.perl b/installer/data/mysql/atomicupdate/bug_8976.perl index a16c555bc0..6c7a1426c4 100644 --- a/installer/data/mysql/atomicupdate/bug_8976.perl +++ b/installer/data/mysql/atomicupdate/bug_8976.perl @@ -8,6 +8,13 @@ if( CheckVersion( $DBversion ) ) { }); } + unless ( column_exists( 'auth_subfield_structure', 'display_order' ) ) { + $dbh->do(q{ + ALTER TABLE auth_subfield_structure + ADD COLUMN display_order INT(2) NOT NULL DEFAULT 0 AFTER defaultvalue + }); + } + # Always end with this (adjust the bug info) - NewVersion( $DBversion, XXXXX, "Description"); + NewVersion( $DBversion, 8976, "Description"); } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 033a6f505a..8a8529d08b 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -844,6 +844,7 @@ CREATE TABLE `auth_subfield_structure` ( `kohafield` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT '', `frameworkcode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', `defaultvalue` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `display_order` INT(2) NOT NULL DEFAULT 0, PRIMARY KEY (`authtypecode`,`tagfield`,`tagsubfield`), KEY `tab` (`authtypecode`,`tab`), CONSTRAINT `auth_subfield_structure_ibfk_1` FOREIGN KEY (`authtypecode`) REFERENCES `auth_types` (`authtypecode`) ON DELETE CASCADE ON UPDATE CASCADE diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt index e3638a24a8..653c3debb7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt @@ -44,13 +44,13 @@
@@ -350,13 +350,36 @@ [% Asset.js("js/admin-menu.js") | $raw %] [% END %] -- 2.39.5