From 98e69d987ef018a8b4e398d2cadc500c3561e70e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Dec 2020 18:51:56 +0100 Subject: [PATCH] Bug 8976: Code cleaning It was tricky to write the previous patch so I decided to clean the ground (a bit) for later, taking advantage of having people who are going to test the whole area. We can move it to its own bug report if QA wants to. Sponsored-by: Orex Digital --- C4/Biblio.pm | 56 +---- Koha/MarcSubfieldStructures.pm | 6 +- admin/auth_subfields_structure.pl | 236 ++++++------------ admin/marc_subfields_structure.pl | 193 ++++---------- .../modules/admin/auth_subfields_structure.tt | 27 +- .../modules/admin/marc_subfields_structure.tt | 42 +--- 6 files changed, 167 insertions(+), 393 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index db67ebdc64..326d55b4e8 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -934,7 +934,7 @@ sub GetMarcStructure { ORDER BY tagfield" ); $sth->execute($frameworkcode); - my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable, $important, $ind1_defaultvalue, $ind2_defaultvalue ); + my ( $liblibrarian, $libopac, $tag, $res, $mandatory, $repeatable, $important, $ind1_defaultvalue, $ind2_defaultvalue ); while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable, $important, $ind1_defaultvalue, $ind2_defaultvalue ) = $sth->fetchrow ) { $res->{$tag}->{lib} = ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac; @@ -946,53 +946,13 @@ sub GetMarcStructure { $res->{$tag}->{ind2_defaultvalue} = $ind2_defaultvalue; } - $sth = $dbh->prepare( - "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue,maxlength,important, display_order - FROM marc_subfield_structure - WHERE frameworkcode=? - ORDER BY tagfield, tagsubfield - " - ); - - $sth->execute($frameworkcode); - - my $subfield; - my $authorised_value; - my $authtypecode; - my $value_builder; - my $kohafield; - my $seealso; - my $hidden; - my $isurl; - my $link; - my $defaultvalue; - my $maxlength; - my $display_order; - - while ( - ( $tag, $subfield, $liblibrarian, $libopac, $tab, $mandatory, $repeatable, $authorised_value, - $authtypecode, $value_builder, $kohafield, $seealso, $hidden, $isurl, $link, $defaultvalue, - $maxlength, $important, $display_order - ) - = $sth->fetchrow - ) { - $res->{$tag}->{$subfield}->{lib} = ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac; - $res->{$tag}->{$subfield}->{tab} = $tab; - $res->{$tag}->{$subfield}->{subfield} = $subfield; - $res->{$tag}->{$subfield}->{mandatory} = $mandatory; - $res->{$tag}->{$subfield}->{important} = $important; - $res->{$tag}->{$subfield}->{repeatable} = $repeatable; - $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value; - $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode; - $res->{$tag}->{$subfield}->{value_builder} = $value_builder; - $res->{$tag}->{$subfield}->{kohafield} = $kohafield; - $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}->{maxlength} = $maxlength; - $res->{$tag}->{$subfield}->{display_order} = $display_order; + my $mss = Koha::MarcSubfieldStructures->search( { frameworkcode => $frameworkcode } )->unblessed; + for my $m (@$mss) { + $res->{ $m->{tagfield} }->{ $m->{tagsubfield} } = { + lib => ( $forlibrarian or !$m->{libopac} ) ? $m->{liblibrarian} : $m->{libopac}, + subfield => $m->{tagsubfield}, + %$m + }; } $cache->set_in_cache($cache_key, $res); diff --git a/Koha/MarcSubfieldStructures.pm b/Koha/MarcSubfieldStructures.pm index 79c79987e2..b7f4b76a79 100644 --- a/Koha/MarcSubfieldStructures.pm +++ b/Koha/MarcSubfieldStructures.pm @@ -35,7 +35,7 @@ Koha::MarcSubfieldStructures - Koha MarcSubfieldStructure Object set class =cut -=head3 type +=head3 _type =cut @@ -43,6 +43,10 @@ sub _type { return 'MarcSubfieldStructure'; } +=head3 object_class + +=cut + sub object_class { return 'Koha::MarcSubfieldStructure'; } diff --git a/admin/auth_subfields_structure.pl b/admin/auth_subfields_structure.pl index 4595494587..502132c643 100755 --- a/admin/auth_subfields_structure.pl +++ b/admin/auth_subfields_structure.pl @@ -26,34 +26,14 @@ use C4::Koha; use Koha::Authority::Types; use Koha::AuthorisedValues; +use Koha::AuthSubfieldStructures; use List::MoreUtils qw( uniq ); -sub string_search { - my ($searchstring,$authtypecode)=@_; - 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, display_order"); - $sth->execute("$searchstring%",$authtypecode); - my $results = $sth->fetchall_arrayref({}); - return (scalar(@$results), $results); -} - -sub auth_subfield_structure_exists { - my ($authtypecode, $tagfield, $tagsubfield) = @_; - my $dbh = C4::Context->dbh; - my $sql = "select tagfield from auth_subfield_structure where authtypecode = ? and tagfield = ? and tagsubfield = ?"; - my $rows = $dbh->selectall_arrayref($sql, {}, $authtypecode, $tagfield, $tagsubfield); - return @$rows > 0; -} - my $input = CGI->new; my $tagfield = $input->param('tagfield'); my $tagsubfield = $input->param('tagsubfield'); my $authtypecode = $input->param('authtypecode'); -my $offset = $input->param('offset'); -$offset = 0 if not defined $offset or $offset < 0; my $op = $input->param('op') || ''; my $script_name = "/cgi-bin/koha/admin/auth_subfields_structure.pl"; @@ -123,35 +103,17 @@ if ($op eq 'add_form') { @value_builder= sort {$a cmp $b} @value_builder; closedir DIR; - # build values list - 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; - while ( my $data = $sth->fetchrow_hashref ) { - my %row_data; # get a fresh hash for the row data - $row_data{defaultvalue} = $data->{defaultvalue}; - $row_data{tab} = $data->{tab}; - $row_data{ohidden} = $data->{'hidden'}; - $row_data{tagsubfield} = $data->{'tagsubfield'}; - $row_data{liblibrarian} = $data->{'liblibrarian'}; - $row_data{libopac} = $data->{'libopac'}; - $row_data{seealso} = $data->{'seealso'}; + my @loop_data; + my $asses = Koha::AuthSubfieldStructures->search({ tagfield => $tagfield, authtypecode => $authtypecode}, {order_by => 'display_order'})->unblessed; + my $i; + for my $ass ( @$asses ) { + my %row_data = %$ass; $row_data{kohafields} = \@kohafields; - $row_data{kohafield} = $data->{'kohafield'}; $row_data{authorised_values} = \@authorised_value_categories; - $row_data{authorised_value} = $data->{'authorised_value'}; $row_data{frameworkcodes} = \@authtypes; - $row_data{frameworkcode} = $data->{'frameworkcode'}; $row_data{value_builders} = \@value_builder; - $row_data{value_builder} = $data->{'value_builder'}; - $row_data{repeatable} = $data->{repeatable}; - $row_data{mandatory} = $data->{mandatory}; - $row_data{hidden} = $data->{hidden}; - $row_data{isurl} = $data->{isurl}; - $row_data{row} = $i; + $row_data{row} = $i++; push( @loop_data, \%row_data ); - $i++; } # Add a new row for the "New" tab @@ -187,12 +149,6 @@ if ($op eq 'add_form') { # called by add_form, used to insert/modify data in DB } elsif ($op eq 'add_validate') { $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, 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'); my @libopac = $input->multi_param('libopac'); @@ -224,55 +180,46 @@ if ($op eq 'add_form') { my $defaultvalue = $defaultvalue[$i]; my $hidden = $ohidden[$i]; #collate from 3 hiddens; my $isurl = $input->param("isurl$i")?1:0; - if ($liblibrarian) { - if (auth_subfield_structure_exists($authtypecode, $tagfield, $tagsubfield)) { - $sth_update->execute( - $authtypecode, - $tagfield, - $tagsubfield, - $liblibrarian, - $libopac, - $repeatable, - $mandatory, - $kohafield, - $tab, - $seealso, - $authorised_value, - $frameworkcode, - $value_builder, - $hidden, - $isurl, - $defaultvalue, - $display_order->{$tagfield} || 0, - ( - $authtypecode, - $tagfield, - $tagsubfield - ), - ); - } else { - $sth_insert->execute( - $authtypecode, - $tagfield, - $tagsubfield, - $liblibrarian, - $libopac, - $repeatable, - $mandatory, - $kohafield, - $tab, - $seealso, - $authorised_value, - $frameworkcode, - $value_builder, - $hidden, - $isurl, - $defaultvalue, - display_order => $display_order->{$tagfield} || 0, - ); - } + if ($liblibrarian) { + my $ass = Koha::AuthSubfieldStructures->find( + { + authtypecode => $authtypecode, + tagfield => $tagfield, + tagsubfield => $tagsubfield + } + ); + my $attributes = { + liblibrarian => $liblibrarian, + libopac => $libopac, + repeatable => $repeatable, + mandatory => $mandatory, + kohafield => $kohafield, + tab => $tab, + seealso => $seealso, + authorised_value => $authorised_value, + frameworkcode => $frameworkcode, + value_builder => $value_builder, + hidden => $hidden, + isurl => $isurl, + defaultvalue => $defaultvalue, + display_order => $display_order->{$tagfield} || 0, + }; + + if ($ass) { + $ass->update($attributes); + } + else { + Koha::AuthSubfieldStructure->new( + { + authtypecode => $authtypecode, + tagfield => $tagfield, + tagsubfield => $tagsubfield, + %$attributes + } + )->store; + } $display_order->{$tagfield}++; - } + } } use Data::Printer colored => 1; warn p $display_order; print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); @@ -281,62 +228,45 @@ if ($op eq 'add_form') { # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB -} elsif ($op eq 'delete_confirm') { - my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?"); - $sth->execute($tagfield,$tagsubfield,$authtypecode); - my $data=$sth->fetchrow_hashref; - $template->param(liblibrarian => $data->{'liblibrarian'}, - tagsubfield => $data->{'tagsubfield'}, - delete_link => $script_name, - tagfield =>$tagfield, - tagsubfield => $tagsubfield, - authtypecode => $authtypecode, - ); - # END $OP eq DELETE_CONFIRM -################## DELETE_CONFIRMED ################################## -# called by delete_confirm, used to effectively confirm deletion of data in DB -} elsif ($op eq 'delete_confirmed') { - my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?"); - $sth->execute($tagfield,$tagsubfield,$authtypecode); +} +elsif ( $op eq 'delete_confirm' ) { + my $ass = Koha::AuthSubfieldStructures->find( + { + authtypecode => $authtypecode, + tagfield => $tagfield, + tagsubfield => $tagsubfield + } + ); + $template->param( + ass => $ass, + delete_link => $script_name, + ); +} +elsif ( $op eq 'delete_confirmed' ) { + Koha::AuthSubfieldStructures->find( + { + authtypecode => $authtypecode, + tagfield => $tagfield, + tagsubfield => $tagsubfield + } + )->delete; print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode"); exit; - # END $OP eq DELETE_CONFIRMED -################## DEFAULT ################################## -} else { # DEFAULT - my ($count,$results)=string_search($tagfield,$authtypecode); - my @loop_data = (); - for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ - my %row_data; # get a fresh hash for the row data - $row_data{tagfield} = $results->[$i]{'tagfield'}; - $row_data{tagsubfield} = $results->[$i]{'tagsubfield'}; - $row_data{liblibrarian} = $results->[$i]{'liblibrarian'}; - $row_data{kohafield} = $results->[$i]{'kohafield'}; - $row_data{repeatable} = $results->[$i]{'repeatable'}; - $row_data{mandatory} = $results->[$i]{'mandatory'}; - $row_data{tab} = $results->[$i]{'tab'}; - $row_data{seealso} = $results->[$i]{'seealso'}; - $row_data{authorised_value} = $results->[$i]{'authorised_value'}; - $row_data{authtypecode} = $results->[$i]{'authtypecode'}; - $row_data{value_builder} = $results->[$i]{'value_builder'}; - $row_data{hidden} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ; - $row_data{isurl} = $results->[$i]{'isurl'}; - if ($row_data{tab} eq -1) { - $row_data{subfield_ignored} = 1; - } +} +else { # DEFAULT + my $ass = Koha::AuthSubfieldStructures->search( + { + tagfield => { -like => "$tagfield%" }, + authtypecode => $authtypecode, + }, + { order_by => [ 'tagfield', 'display_order' ] } + )->unblessed; + + $template->param( loop => $ass ); + $template->param( + edit_tagfield => $tagfield, + edit_authtypecode => $authtypecode, + ); - push(@loop_data, \%row_data); - } - $template->param(loop => \@loop_data); - $template->param(edit_tagfield => $tagfield, - edit_authtypecode => $authtypecode); - - if ($offset>0) { - my $prevpage = $offset-$pagesize; - $template->param(prev =>""); - } - if ($offset+$pagesize<$count) { - my $nextpage =$offset+$pagesize; - $template->param(next => ""); - } } #---- END $OP eq DEFAULT output_html_with_http_headers $input, $cookie, $template->output; diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index 22ebcce0a3..908b77d13b 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -29,38 +29,6 @@ use Koha::Filter::MARC::ViewPolicy; use List::MoreUtils qw( uniq ); -sub string_search { - my ( $searchstring, $frameworkcode ) = @_; - my $dbh = C4::Context->dbh; - $searchstring =~ s/\'/\\\'/g; - my @data = split( ' ', $searchstring ); - my $count = @data; - my $sth = - $dbh->prepare( -"Select * from marc_subfield_structure where (tagfield like ? and frameworkcode=?) order by tagfield, display_order" - ); - $sth->execute( "$searchstring%", $frameworkcode ); - my @results; - my $cnt = 0; - my $u = 1; - - while ( my $data = $sth->fetchrow_hashref ) { - push( @results, $data ); - $cnt++; - $u++; - } - $sth->finish; - return ( $cnt, \@results ); -} - -sub marc_subfield_structure_exists { - my ($tagfield, $tagsubfield, $frameworkcode) = @_; - my $dbh = C4::Context->dbh; - my $sql = "select tagfield from marc_subfield_structure where tagfield = ? and tagsubfield = ? and frameworkcode = ?"; - my $rows = $dbh->selectall_arrayref($sql, {}, $tagfield, $tagsubfield, $frameworkcode); - return @$rows > 0; -} - my $input = CGI->new; my $tagfield = $input->param('tagfield'); my $tagsubfield = $input->param('tagsubfield'); @@ -159,42 +127,24 @@ if ( $op eq 'add_form' ) { closedir DIR; # build values list - my $sth = - $dbh->prepare( -"select * from marc_subfield_structure where tagfield=? and frameworkcode=? order by display_order" - ); # and tagsubfield='$tagsubfield'"); - $sth->execute( $tagfield, $frameworkcode ); + my $mss = Koha::MarcSubfieldStructures->search( + { tagfield => $tagfield, frameworkcode => $frameworkcode }, + { order_by => 'display_order' } + )->unblessed; my @loop_data = (); my $i = 0; - while ( my $data = $sth->fetchrow_hashref ) { - my %row_data; # get a fresh hash for the row data - $row_data{defaultvalue} = $data->{defaultvalue}; - $row_data{maxlength} = $data->{maxlength}; - $row_data{tab} = $data->{tab}; - $row_data{tagsubfield} = $data->{tagsubfield}; - $row_data{subfieldcode} = $data->{'tagsubfield'}; + for my $m ( @$mss ) { + my %row_data = %$m; # get a fresh hash for the row data + $row_data{subfieldcode} = $m->{tagsubfield}; $row_data{urisubfieldcode} = $row_data{subfieldcode} eq '%' ? 'pct' : $row_data{subfieldcode}; - $row_data{liblibrarian} = $data->{'liblibrarian'}; - $row_data{libopac} = $data->{'libopac'}; - $row_data{seealso} = $data->{'seealso'}; $row_data{kohafields} = \@kohafields; - $row_data{kohafield} = $data->{kohafield}; $row_data{authorised_values} = \@authorised_values; - $row_data{authorised_value} = $data->{authorised_value}; $row_data{value_builders} = \@value_builder; - $row_data{value_builder} = $data->{'value_builder'}; $row_data{authtypes} = \@authtypes; - $row_data{authtypecode} = $data->{'authtypecode'}; - $row_data{repeatable} = $data->{repeatable}; - $row_data{mandatory} = $data->{mandatory}; - $row_data{important} = $data->{important}; - $row_data{hidden} = $data->{hidden}; - $row_data{isurl} = $data->{isurl}; $row_data{row} = $i; - $row_data{link} = $data->{'link'}; - if ( defined $data->{kohafield} - and $data->{kohafield} eq 'biblio.biblionumber' ) + if ( defined $m->{kohafield} + and $m->{kohafield} eq 'biblio.biblionumber' ) { my $hidden_opac = Koha::Filter::MARC::ViewPolicy->should_hide_marc( { @@ -262,10 +212,6 @@ if ( $op eq 'add_form' ) { elsif ( $op eq 'add_validate' ) { my $dbh = C4::Context->dbh; $template->param( tagfield => "$input->param('tagfield')" ); - my $sth_update = $dbh->prepare(qq{ - update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, important=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?, link=?, defaultvalue=?, maxlength=?, display_order=? - where tagfield=? and tagsubfield=? and frameworkcode=? - }); my @tagsubfield = $input->multi_param('tagsubfield'); my @liblibrarian = $input->multi_param('liblibrarian'); my @libopac = $input->multi_param('libopac'); @@ -303,33 +249,28 @@ elsif ( $op eq 'add_validate' ) { my $maxlength = $maxlength[$i] ? $maxlength[$i] : 9999; if (defined($liblibrarian) && $liblibrarian ne "") { - if (marc_subfield_structure_exists($tagfield, $tagsubfield, $frameworkcode)) { - $sth_update->execute( - $tagfield, - $tagsubfield, - $liblibrarian, - $libopac, - $repeatable, - $mandatory, - $important, - $kohafield, - $tab, - $seealso, - $authorised_value, - $authtypecode, - $value_builder, - $hidden, - $isurl, - $frameworkcode, - $link, - $defaultvalue, - $maxlength, - $display_order->{$tagfield} || 0, - ( - $tagfield, - $tagsubfield, - $frameworkcode, - ) + my $mss = Koha::MarcSubfieldStructures->find({tagfield => $tagfield, tagsubfield => $tagsubfield, frameworkcode => $frameworkcode }); + if ($mss) { + $mss->update( + { + liblibrarian => $liblibrarian, + libopac => $libopac, + repeatable => $repeatable, + mandatory => $mandatory, + important => $important, + kohafield => $kohafield, + tab => $tab, + seealso => $seealso, + authorised_value => $authorised_value, + authtypecode => $authtypecode, + value_builder => $value_builder, + hidden => $hidden, + isurl => $isurl, + link => $link, + defaultvalue => $defaultvalue, + maxlength => $maxlength, + display_order => $display_order->{$tagfield} || 0 + } ); } else { if( $frameworkcode ne q{} ) { @@ -365,7 +306,6 @@ elsif ( $op eq 'add_validate' ) { $display_order->{$tagfield}++; } } - $sth_update->finish; $cache->clear_from_cache("MarcStructure-0-$frameworkcode"); $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-"); @@ -379,22 +319,16 @@ elsif ( $op eq 'add_validate' ) { # called by default form, used to confirm deletion of data in DB } elsif ( $op eq 'delete_confirm' ) { - my $dbh = C4::Context->dbh; - my $sth = - $dbh->prepare( -"select * from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?" - ); - - $sth->execute( $tagfield, $tagsubfield, $frameworkcode ); - my $data = $sth->fetchrow_hashref; - $sth->finish; + my $mss = Koha::MarcSubfieldStructures->find( + { + tagfield => $tagfield, + tagsubfield => $tagsubfield, + frameworkcode => $frameworkcode + } + ); $template->param( - liblibrarian => $data->{'liblibrarian'}, - tagsubfield => $data->{'tagsubfield'}, + mss => $mss, delete_link => $script_name, - tagfield => $tagfield, - tagsubfield => $tagsubfield, - frameworkcode => $frameworkcode, ); # END $OP eq DELETE_CONFIRM @@ -402,13 +336,14 @@ elsif ( $op eq 'delete_confirm' ) { # called by delete_confirm, used to effectively confirm deletion of data in DB } elsif ( $op eq 'delete_confirmed' ) { - my $dbh = C4::Context->dbh; - my $sth = - $dbh->prepare( -"delete from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?" - ); - $sth->execute( $tagfield, $tagsubfield, $frameworkcode ); - $sth->finish; + Koha::MarcSubfieldStructures->find( + { + tagfield => $tagfield, + tagsubfield => $tagsubfield, + frameworkcode => $frameworkcode + } + )->delete; + $cache->clear_from_cache("MarcStructure-0-$frameworkcode"); $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-"); @@ -420,33 +355,15 @@ elsif ( $op eq 'delete_confirmed' ) { ################## DEFAULT ################################## } else { # DEFAULT - my ( $count, $results ) = string_search( $tagfield, $frameworkcode ); - my @loop_data = (); - for ( my $i = 0; $i < $count; $i++ ) { - my %row_data; # get a fresh hash for the row data - $row_data{tagfield} = $results->[$i]{'tagfield'}; - $row_data{tagsubfield} = $results->[$i]{'tagsubfield'}; - $row_data{liblibrarian} = $results->[$i]{'liblibrarian'}; - $row_data{kohafield} = $results->[$i]{'kohafield'}; - $row_data{repeatable} = $results->[$i]{'repeatable'}; - $row_data{mandatory} = $results->[$i]{'mandatory'}; - $row_data{important} = $results->[$i]{'important'}; - $row_data{tab} = $results->[$i]{'tab'}; - $row_data{seealso} = $results->[$i]{'seealso'}; - $row_data{authorised_value} = $results->[$i]{'authorised_value'}; - $row_data{authtypecode} = $results->[$i]{'authtypecode'}; - $row_data{value_builder} = $results->[$i]{'value_builder'}; - $row_data{hidden} = $results->[$i]{'hidden'}; - $row_data{isurl} = $results->[$i]{'isurl'}; - $row_data{link} = $results->[$i]{'link'}; - - if ( $row_data{tab} eq -1 ) { - $row_data{subfield_ignored} = 1; - } + my $mss = Koha::MarcSubfieldStructures->search( + { + tagfield => { -like => "$tagfield%" }, + frameworkcode => $frameworkcode + }, + { order_by => [ 'tagfield', 'display_order' ] } + )->unblessed; - push( @loop_data, \%row_data ); - } - $template->param( loop => \@loop_data ); + $template->param( loop => $mss ); $template->param( edit_tagfield => $tagfield, edit_frameworkcode => $frameworkcode 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 653c3debb7..ee507e0fda 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 @@ -18,7 +18,6 @@ [% ELSE %]Authority MARC subfield structure for [% tagfield | html %] › [% END %] [% IF ( delete_confirm ) %]Confirm deletion of subfield [% tagsubfield | html %]?[% END %] - [% IF ( delete_confirmed ) %]Data deleted[% END %] [% IF ( add_form ) %] [% IF ( use_heading_flags_p ) %] [% IF ( heading_edit_subfields_p ) %]Edit MARC subfields constraints[% END %] @@ -111,7 +110,7 @@
  1. - - -[% END %] - - [% IF ( else ) %]

    Authority MARC subfield structure admin for [% tagfield | html %] (authority: [% authtypecode | html %])

    This screen shows the subfields associated with the selected tag. You can edit subfields or add a new one by clicking on edit.

    @@ -279,14 +268,14 @@ [% loo.tagsubfield | html %] - [% IF ( loo.subfield_ignored ) %] + [% IF loo.tab == -1 %] [% loo.liblibrarian | html_entity %] [% ELSE %] [% loo.liblibrarian | html_entity %] [% END %] - [% IF ( loo.subfield_ignored ) %] + [% IF loo.subfield_ignored == -1 %] subfield ignored [% ELSE %] Tab:[% loo.tab | html %], @@ -323,16 +312,6 @@ Cancel - [% IF ( previous ) %] - - - [% END %] - [% IF ( next ) %] - [% next | html %] - - - [% END %] - [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt index 7c88825c85..243193f0a9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt @@ -14,10 +14,7 @@ [%- END -%] [%- END -%] [%- IF ( delete_confirm ) -%] - MARC subfield structure › Confirm deletion of subfield [%- tagsubfield | html -%] - [%- END -%] - [%- IF ( delete_confirmed ) -%] - MARC subfield structure › Subfield deleted + MARC subfield structure › Confirm deletion of subfield [%- mss.tagsubfield | html -%] [%- END -%] [%- IF ( else ) -%] MARC subfield structure @@ -48,10 +45,7 @@ [% END %] [% END %] [% IF ( delete_confirm ) %] - Tag [% tagfield | html %] Subfield structure › Confirm deletion of subfield [% tagsubfield | html %] - [% END %] - [% IF ( delete_confirmed ) %] - Tag [% tagfield | html %] subfield structure › Subfield deleted + Tag [% mss.tagfield | html %] Subfield structure › Confirm deletion of subfield [% mss.tagsubfield | html %] [% END %] [% IF ( else ) %] Tag [% tagfield | html %] Subfield structure @@ -286,37 +280,27 @@ [% IF ( delete_confirm ) %]
    -

    Confirm deletion of subfield [% tagsubfield | html %]?

    -

    Subfield: [% tagsubfield | html %]

    -

    Description: [% liblibrarian | html_entity %]

    +

    Confirm deletion of subfield [% mss.tagsubfield | html %]?

    +

    Subfield: [% mss.tagsubfield | html %]

    +

    Description: [% mss.liblibrarian | html_entity %]

    - - - - + + +
    - - - - + + +
    [% END # /IF ( delete_confirm ) %] - [% IF ( delete_confirmed ) %] -

    Data deleted

    -
    - - -
    - [% END %] - [% IF ( else ) %]

    MARC subfield structure admin for [% tagfield | html %] [% IF ( frameworkcode ) %](framework [% frameworkcode | html %])[% ELSE %](default framework)[% END %]

    @@ -337,14 +321,14 @@ [% loo.tagsubfield | html %] - [% IF ( loo.subfield_ignored ) %] + [% IF loo.tab == -1 %] [% loo.liblibrarian | html_entity %] [% ELSE %] [% loo.liblibrarian | html_entity %] [% END %] - [% IF ( loo.subfield_ignored ) %] + [% IF loo.tab == -1 %] subfield ignored [% ELSE %] Tab:[% loo.tab | html %], -- 2.20.1