From efc13e424133a93fa1563efc75b0ed1a0462e9d3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 10 Feb 2016 16:56:01 +0000 Subject: [PATCH] [SIGNED-OFF] Bug 15801: Koha::BiblioFrameworks - Remove C4::Koha::getframeworks C4::Koha::getframeworks returned a hashref of biblio frameworks. It was mainly used to generate the dropdown list of frameworks. The scripts modified in this patch did not necessary order the element by description (frameworktext), the displays were not consistent from one screen to another. Using the same search method everywhere: Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); We will know always get the framework in the same order. Test plan: Following the different pages modified by this patch, and make sure the frameworks are displayed correctly in the dropdown list: 1/ acqui/z3950_search.pl - Create an order from an external source. 2/ admin/fieldmapping.pl - Define some mappings keyword / MARC field 3/ admin/marctagstructure.pl - On the MARC frameworks admin page, select another framework than the default one and click on the 'Search' button 4/ catalogue/MARCdetail.pl - On the MARC defail page, change the framework you want to use to display the record 5/ cataloguing/addbiblio.pl - Add or edit a biblio record, change its framework. When editing, the framework of the record should be selected by default 6/ cataloguing/addbooks.pl - Go on the cataloguing home page and click on the "New record" button. You should see all the frameworks 7/ cataloguing/merge.pl - Select 2 biblio records to merge. On the first step (select the merge reference), you should be allowed to select the framework to use. 8/ tools/inventory.pl - On the inventory page, the "Item statuses" part should be populated as before this patch 9/ tools/manage-marc-import.pl - Stage records for import. Before importing them into the catalog, you should see the framework dropdown list. Signed-off-by: Bernardo Gonzalez Kriegel Works Ok. No errors --- C4/Koha.pm | 57 +--------------------- acqui/z3950_search.pl | 18 ++----- admin/fieldmapping.pl | 42 +++++----------- admin/marctagstructure.pl | 17 ++----- catalogue/MARCdetail.pl | 21 +++----- cataloguing/addbiblio.pl | 24 +++------ cataloguing/addbooks.pl | 15 ++---- cataloguing/merge.pl | 16 ++---- .../prog/en/modules/acqui/z3950_search.tt | 8 +-- .../prog/en/modules/admin/fieldmapping.tt | 26 +++++----- .../prog/en/modules/admin/marctagstructure.tt | 8 +-- .../prog/en/modules/catalogue/MARCdetail.tt | 8 ++- .../prog/en/modules/cataloguing/addbooks.tt | 8 +-- .../prog/en/modules/cataloguing/merge.tt | 12 +---- .../prog/en/modules/tools/manage-marc-import.tt | 2 +- tools/inventory.pl | 9 ++-- tools/manage-marc-import.pl | 12 ++--- 17 files changed, 82 insertions(+), 221 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 8cfb9bf..8b6b220 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -42,7 +42,7 @@ BEGIN { &GetItemTypes &getitemtypeinfo &GetItemTypesCategorized &GetItemTypesByCategory &GetSupportName &GetSupportList - &getframeworks &getframeworkinfo + &getframeworkinfo &getallthemes &getFacets &getnbpages @@ -302,61 +302,6 @@ sub GetItemTypesByCategory { return @$tmp; } -=head2 getframework - - $frameworks = &getframework(); - -Returns information about existing frameworks - -build a HTML select with the following code : - -=head3 in PERL SCRIPT - - my $frameworks = getframeworks(); - my @frameworkloop; - foreach my $thisframework (keys %$frameworks) { - my $selected = 1 if $thisframework eq $frameworkcode; - my %row =( - value => $thisframework, - selected => $selected, - description => $frameworks->{$thisframework}->{'frameworktext'}, - ); - push @frameworksloop, \%row; - } - $template->param(frameworkloop => \@frameworksloop); - -=head3 in TEMPLATE - -
- - [% FOREACH framework IN frameworkloop %] - [% IF ( framework.selected ) %] - - [% ELSE %] - - [% END %] - [% END %] - - - -
- -=cut - -sub getframeworks { - - # returns a reference to a hash of references to branches... - my %itemtypes; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("select * from biblio_framework"); - $sth->execute; - while ( my $IT = $sth->fetchrow_hashref ) { - $itemtypes{ $IT->{'frameworkcode'} } = $IT; - } - return ( \%itemtypes ); -} - =head2 getframeworkinfo $frameworkinfo = &getframeworkinfo($frameworkcode); diff --git a/acqui/z3950_search.pl b/acqui/z3950_search.pl index b2b5124..061bd46 100755 --- a/acqui/z3950_search.pl +++ b/acqui/z3950_search.pl @@ -30,10 +30,10 @@ use C4::Breeding; use C4::Koha; use Koha::Acquisition::Bookseller; +use Koha::BiblioFrameworks; my $input = new CGI; my $biblionumber = $input->param('biblionumber')||0; -my $frameworkcode = $input->param('frameworkcode')||''; my $title = $input->param('title'); my $author = $input->param('author'); my $isbn = $input->param('isbn'); @@ -50,18 +50,7 @@ my $page = $input->param('current_page') || 1; $page = $input->param('goto_page') if $input->param('changepage_goto'); # get framework list -my $frameworks = getframeworks; -my @frameworkcodeloop; -foreach my $thisframeworkcode ( keys %$frameworks ) { - my %row = ( - value => $thisframeworkcode, - frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, - ); - if ( $row{'value'} eq $frameworkcode){ - $row{'active'} = 'true'; - } - push @frameworkcodeloop, \%row; -} +my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); my $vendor = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); @@ -74,8 +63,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); $template->param( - frameworkcode => $frameworkcode, - frameworkcodeloop => \@frameworkcodeloop, + frameworks => $frameworks, booksellerid => $booksellerid, basketno => $basketno, name => $vendor->{'name'}, diff --git a/admin/fieldmapping.pl b/admin/fieldmapping.pl index 05b5202..75fd892 100755 --- a/admin/fieldmapping.pl +++ b/admin/fieldmapping.pl @@ -24,10 +24,11 @@ use C4::Biblio; use C4::Koha; use C4::Output; -my $query = new CGI; +use Koha::BiblioFrameworks; -my $framework = $query->param('framework') || ""; +my $query = new CGI; +my $frameworkcode = $query->param('framework') || ""; my $field = $query->param('fieldname'); my $fieldcode = $query->param('marcfield'); my $subfieldcode = $query->param('marcsubfield'); @@ -43,42 +44,25 @@ my ($template, $loggedinuser, $cookie) debug => 1, }); -# get framework list -my $frameworks = getframeworks(); -my @frameworkloop; -my $selected; -my $frameworktext; -foreach my $thisframeworkcode (keys %$frameworks) { - if ($thisframeworkcode eq $framework){ - $selected = 1; - $frameworktext = $frameworks->{$thisframeworkcode}->{'frameworktext'}; - } else { - $selected = 0; - } - my %row =(value => $thisframeworkcode, - selected => $selected, - frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, - ); - push @frameworkloop, \%row; -} - if($op eq "delete" and $id){ DeleteFieldMapping($id); - print $query->redirect("/cgi-bin/koha/admin/fieldmapping.pl?framework=".$framework); + print $query->redirect("/cgi-bin/koha/admin/fieldmapping.pl?framework=".$frameworkcode); exit; } # insert operation if($field and $fieldcode){ - SetFieldMapping($framework, $field, $fieldcode, $subfieldcode); + SetFieldMapping($frameworkcode, $field, $fieldcode, $subfieldcode); } -my $fieldloop = GetFieldMapping($framework); +my $fieldloop = GetFieldMapping($frameworkcode); -$template->param( frameworkloop => \@frameworkloop, - framework => $framework, - frameworktext => $frameworktext, - fields => $fieldloop, - ); +my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); +my $framework = $frameworks->search( { frameworkcode => $frameworkcode } )->next; +$template->param( + frameworks => $frameworks, + framework => $framework, + fields => $fieldloop, +); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl index 7728687..b7ee972 100755 --- a/admin/marctagstructure.pl +++ b/admin/marctagstructure.pl @@ -28,6 +28,7 @@ use C4::Output; use C4::Context; use Koha::Cache; +use Koha::BiblioFrameworks; # retrieve parameters my $input = new CGI; @@ -58,16 +59,7 @@ my ($template, $loggedinuser, $cookie) debug => 1, }); -# get framework list -my $frameworks = getframeworks(); -my @frameworkloop; -foreach my $thisframeworkcode (keys %$frameworks) { - push @frameworkloop, { - value => $thisframeworkcode, - selected => ($thisframeworkcode eq $frameworkcode) ? 1 : 0, - frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, - }; -} +my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); # check that framework is defined in marc_tag_structure my $sth=$dbh->prepare("select count(*) from marc_tag_structure where frameworkcode=?"); @@ -83,12 +75,13 @@ unless ($frameworkexist) { $op = "framework_create"; } } + $template->param( - frameworkloop => \@frameworkloop, + frameworks => $frameworks, frameworkcode => $frameworkcode, frameworktext => $frameworkinfo->{frameworktext}, script_name => $script_name, - ($op||'else') => 1, + ( $op || 'else' ) => 1, ); diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl index ccf178e..52f027d 100755 --- a/catalogue/MARCdetail.pl +++ b/catalogue/MARCdetail.pl @@ -58,6 +58,7 @@ use C4::Acquisition; use C4::Members; # to use GetMember use C4::Serials; #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber use C4::Search; # enabled_staff_search_views +use Koha::BiblioFrameworks; use List::MoreUtils qw( uniq ); @@ -113,21 +114,11 @@ my $itemcount = GetItemsCount($biblionumber); $template->param( count => $itemcount, bibliotitle => $biblio->{title}, ); -# Getting the list of all frameworks -# get framework list -my $frameworks = getframeworks; -my @frameworkcodeloop; -foreach my $thisframeworkcode ( keys %$frameworks ) { - my %row = ( - value => $thisframeworkcode, - frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, - ); - if ($frameworkcode eq $thisframeworkcode){ - $row{'selected'}= 1; - } - push @frameworkcodeloop, \%row; -} -$template->param( frameworkcodeloop => \@frameworkcodeloop, ); +my $frameworks = Koha::BiblioFrameworks->search( {}, { order_by => ['frameworktext'] } ); +$template->param( + frameworks => $frameworks, + frameworkcode => $frameworkcode, +); # fill arrays my @loop_data = (); diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index f0263ef..4aa7824 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -36,6 +36,8 @@ use C4::ClassSource; use C4::ImportBatch; use C4::Charset; +use Koha::BiblioFrameworks; + use Date::Calc qw(Today); use MARC::File::USMARC; use MARC::File::XML; @@ -745,23 +747,11 @@ if ($frameworkcode eq 'FA'){ print $input->redirect( '/cgi-bin/koha/cataloguing/editor.pl' . ( $biblionumber ? ( '#catalog/' . $biblionumber ) : '' ) ); } - -# Getting the list of all frameworks -# get framework list -my $frameworks = getframeworks; -my @frameworkcodeloop; -foreach my $thisframeworkcode ( keys %$frameworks ) { - my %row = ( - value => $thisframeworkcode, - frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, - ); - if ($frameworkcode eq $thisframeworkcode){ - $row{'selected'} = 1; - } - push @frameworkcodeloop, \%row; -} -$template->param( frameworkcodeloop => \@frameworkcodeloop, - breedingid => $breedingid ); +my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); +$template->param( + frameworks => $frameworks, + breedingid => $breedingid, +); # ++ Global $tagslib = &GetMarcStructure( 1, $frameworkcode ); diff --git a/cataloguing/addbooks.pl b/cataloguing/addbooks.pl index 672a070..1d52bb8 100755 --- a/cataloguing/addbooks.pl +++ b/cataloguing/addbooks.pl @@ -34,6 +34,7 @@ use C4::Output; use C4::Koha; use C4::Search; +use Koha::BiblioFrameworks; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; @@ -57,17 +58,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -# get framework list -my $frameworks = getframeworks; -my @frameworkcodeloop; -foreach my $thisframeworkcode ( sort { uc($frameworks->{$a}->{'frameworktext'}) cmp uc($frameworks->{$b}->{'frameworktext'}) } keys %{$frameworks} ) { - push @frameworkcodeloop, { - value => $thisframeworkcode, - frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, - }; -} - - # Searching the catalog. if ($query) { @@ -143,8 +133,9 @@ for my $resultsbr (@resultsbr) { }; } +my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); $template->param( - frameworkcodeloop => \@frameworkcodeloop, + frameworks => $frameworks, breeding_count => $countbr, breeding_loop => $breeding_loop, z3950_search_params => C4::Search::z3950_search_args($query), diff --git a/cataloguing/merge.pl b/cataloguing/merge.pl index 09517ed..ee9f1fa 100755 --- a/cataloguing/merge.pl +++ b/cataloguing/merge.pl @@ -29,6 +29,8 @@ use C4::Serials; use C4::Koha; use C4::Reserves qw/MergeHolds/; use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/; + +use Koha::BiblioFrameworks; use Koha::MetadataRecord; my $input = new CGI; @@ -245,18 +247,8 @@ if ($merge) { records => \@records, ); - my $frameworks = getframeworks; - my @frameworkselect; - foreach my $thisframeworkcode ( keys %$frameworks ) { - my %row = ( - value => $thisframeworkcode, - frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, - ); - push @frameworkselect, \%row; - } - $template->param( - frameworkselect => \@frameworkselect, - ); + my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); + $template->param( frameworks => $frameworks ); } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt index ebb18df..56ab046 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tt @@ -119,12 +119,8 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color :
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt index 295299b..fbb2756 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt @@ -25,26 +25,26 @@ $(document).ready(function() {

    Keyword to MARC mapping

    [% UNLESS ( fields ) %] -

    There are no mappings for the [% IF ( frameworktext ) %][% frameworktext %][% ELSE %]default[% END %] framework.

    +

    There are no mappings for the [% IF framework.frameworktext %][% framework.frameworktext %][% ELSE %]default[% END %] framework.

    [% END %]
    - +
    - +
    Add a mapping
      @@ -59,7 +59,7 @@ $(document).ready(function() { [% IF ( fields ) %] - + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt index 1f0a5d8..2ff5822 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt @@ -163,11 +163,11 @@ $(document).ready(function() { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt index 992bd0a..4950519 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt @@ -60,8 +60,12 @@ function Changefwk(FwkList) {

      With framework :

      [% IF ( ocoins ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt index c189583..1313ba1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt @@ -100,8 +100,8 @@ @@ -112,8 +112,8 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt index 2805661..d23c34b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt @@ -219,23 +219,15 @@ $(document).ready(function(){ [% END %] - [% IF frameworkselect.size %]
    1. - [% END %] [% FOREACH record IN records %] 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 3a786e9..29129af 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 @@ -349,7 +349,7 @@ $(document).ready(function(){ [% END %] diff --git a/tools/inventory.pl b/tools/inventory.pl index 990855f..797008c 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -37,6 +37,7 @@ use C4::Circulation; use C4::Reports::Guided; #_get_column_defs use C4::Charset; use Koha::DateUtils; +use Koha::BiblioFrameworks; use List::MoreUtils qw( none ); @@ -77,11 +78,11 @@ for my $branch_hash (keys %$branches) { my @authorised_value_list; my $authorisedvalue_categories = ''; -my $frameworks = getframeworks(); -$frameworks->{''} = {frameworkcode => ''}; # Add the default framework +my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] })->unblessed; +unshift @$frameworks, { frameworkcode => '' }; -for my $fwk (keys %$frameworks){ - my $fwkcode = $frameworks->{$fwk}->{'frameworkcode'}; +for my $fwk ( @$frameworks ){ + my $fwkcode = $fwk->{frameworkcode}; my $authcode = GetAuthValCode('items.location', $fwkcode); if ($authcode && $authorisedvalue_categories!~/\b$authcode\W/){ $authorisedvalue_categories.="$authcode "; diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl index b0d4f88..16cda7a 100755 --- a/tools/manage-marc-import.pl +++ b/tools/manage-marc-import.pl @@ -36,6 +36,7 @@ use C4::ImportBatch; use C4::Matcher; use C4::BackgroundJob; use C4::Labels::Batch; +use Koha::BiblioFrameworks; my $script_name = "/cgi-bin/koha/tools/manage-marc-import.pl"; @@ -62,15 +63,8 @@ my %cookies = parse CGI::Cookie($cookie); our $sessionID = $cookies{'CGISESSID'}->value; our $dbh = C4::Context->dbh; -# Frameworks selection loop -{ - my $frameworks = getframeworks; - my $arrayref = []; - while ( my ($key, $value) = each %$frameworks ) { - push @$arrayref, { value => $key, label => $value->{frameworktext} }; - } - $template->param( frameworks => $arrayref ); -} +my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); +$template->param( frameworks => $frameworks ); if ($op eq "create_labels") { #create a batch of labels, then lose $op & $import_batch_id so we get back to import batch list. -- 1.9.1
      Mappings for the [% IF ( frameworktext ) %][% frameworktext %][% ELSE %]default[% END %] frameworkMappings for the [% IF framework.frameworktext %][% framework.frameworktext %][% ELSE %]default[% END %] framework
      Field MARC field