From bd37f7a31687dc622b589af339a937d9f3eb7612 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 5 Nov 2013 17:20:04 +0100 Subject: [PATCH] Bug 11023: Add the ability to specify fields from biblioitems table. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test plan: Same as before but try with fields from the biblioitems table. Signed-off-by: juliette et rémy --- C4/Items.pm | 48 ++++++++++++++++++- .../prog/en/modules/tools/toggle_new_status.tt | 20 ++++---- tools/toggle_new_status.pl | 4 +- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 9b84d21..0209774 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -2906,6 +2906,39 @@ sub columns { return @data; } +=head2 biblioitems_columns + + my @columns = C4::Items::biblioitems_columns(); + +Returns an array of biblioitems' table columns on success, +and an empty array on failure. + +=cut + +sub biblioitems_columns { + # Pure ANSI SQL goodness. + my $sql = 'SELECT * FROM biblioitems WHERE 1=0;'; + + # Get the database handle. + my $dbh = C4::Context->dbh; + + # Run the SQL statement to load STH's readonly properties. + my $sth = $dbh->prepare($sql); + my $rv = $sth->execute(); + + # This only fails if the table doesn't exist. + # This will always be called AFTER an install or upgrade, + # so borrowers will exist! + my @data; + if ($sth->{NUM_OF_FIELDS}>0) { + @data = @{$sth->{NAME}}; + } + else { + @data = (); + } + return @data; +} + sub ToggleNewStatus { my ( $params ) = @_; my @rules = @{ $params->{rules} }; @@ -2913,7 +2946,8 @@ sub ToggleNewStatus { my $dbh = C4::Context->dbh; my @errors; - my @items_columns = C4::Items::columns; + my @item_columns = map { "items.$_" } C4::Items::columns; + my @biblioitem_columns = map { "biblioitems.$_" } C4::Items::biblioitems_columns; my $report; for my $rule ( @rules ) { my $duration = $rule->{duration}; @@ -2921,9 +2955,17 @@ sub ToggleNewStatus { my $substitutions = $rule->{substitutions}; my @params; - my $query = q|SELECT biblionumber, itemnumber FROM items WHERE 1 |; + my $query = q| + SELECT items.biblionumber, items.itemnumber + FROM items + LEFT JOIN biblioitems ON items.biblioitemnumber = items.itemnumber + WHERE 1 + |; for my $condition ( @$conditions ) { - if ( grep {/^$condition->{field}$/} @items_columns ) { + if ( + grep {/^$condition->{field}$/} @item_columns + or grep {/^$condition->{field}$/} @biblioitem_columns + ) { if ( $condition->{value} =~ /\|/ ) { my @values = split /\|/, $condition->{value}; $query .= qq| AND $condition->{field} IN (| diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt index d1a0d2e..8a0d5ae 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt @@ -155,11 +155,11 @@
@@ -176,11 +176,11 @@
@@ -217,8 +217,8 @@
= @@ -232,8 +232,8 @@
= diff --git a/tools/toggle_new_status.pl b/tools/toggle_new_status.pl index 9b7bf02..c7b88d4 100755 --- a/tools/toggle_new_status.pl +++ b/tools/toggle_new_status.pl @@ -106,10 +106,12 @@ if ( $@ ) { exit; } +my @item_fields = map { "items.$_" } C4::Items::columns; +my @biblioitem_fields = map { "biblioitems.$_" } C4::Items::biblioitems_columns; $template->param( op => $op, messages => \@messages, - item_fields => [ C4::Items::columns ], + fields => [ @item_fields, @biblioitem_fields ], rules => $rules, ); -- 1.7.2.5