From 0a1c90084e9978c8f51c7d58d3383fd44ab2a8ef Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Sat, 31 May 2014 00:30:32 -0300 Subject: [PATCH] Bug 12151: Remove uses of smartmatch operator in report scripts This patch removes the use of smartmatch operators in report scripts. Regards To+ Sponsored-by: Universidad Nacional de Cordoba Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer Passes QA script and tests. Acquisition and Patron statistics wizard tested, no regressions found. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Galen Charlton --- reports/acquisitions_stats.pl | 101 ++++++++++++++++++---------------- reports/borrowers_stats.pl | 60 ++++++++++---------- 2 files changed, 82 insertions(+), 79 deletions(-) diff --git a/reports/acquisitions_stats.pl b/reports/acquisitions_stats.pl index 8d5cb1d3e1..419959eb7c 100755 --- a/reports/acquisitions_stats.pl +++ b/reports/acquisitions_stats.pl @@ -301,51 +301,55 @@ sub calculate { foreach ($line, $column) { $filter{$_} = []; $field{$_} = $_; - given ($_) { - when (/closedate/) { - $filter{$_}->[0] = @$filters[0]; - $filter{$_}->[1] = @$filters[1]; - my $a = $_; - given ($podsp) { - when (1) { $field{$a} = "concat(hex(weekday($a)+1),'-',dayname($a))" } - when (2) { $field{$a} = "concat(hex(month($a)),'-',monthname($a))" } - when (3) { $field{$a} = "Year($a)" } - default { $field{$a} = $a } - } - } - when (/received/) { - $filter{$_}->[0] = @$filters[2]; - $filter{$_}->[1] = @$filters[3]; - my $a = $_; - given ($rodsp) { - when (1) { $field{$a} = "concat(hex(weekday($a)+1),'-',dayname($a))" } - when (2) { $field{$a} = "concat(hex(month($a)),'-',monthname($a))" } - when (3) { $field{$a} = "Year($a)" } - default { $field{$a} = $a } - } - } - when (/bookseller/) { - $filter{$_}->[0] = @$filters[4]; - } - when (/homebranch/) { - $filter{$_}->[0] = @$filters[5]; - } - when (/ccode/) { - $filter{$_}->[0] = @$filters[6]; - } - when (/itemtype/) { - $filter{$_}->[0] = @$filters[7]; - } - when (/budget/) { - $filter{$_}->[0] = @$filters[8]; - } - when (/sort1/) { - $filter{$_}->[0] = @$filters[9]; + if ( $_ =~ /closedate/ ) { + $filter{$_}->[0] = @$filters[0]; + $filter{$_}->[1] = @$filters[1]; + my $a = $_; + if ( $podsp == 1 ) { + $field{$a} = "concat(hex(weekday($a)+1),'-',dayname($a))"; + } elsif ( $podsp == 2 ) { + $field{$a} = "concat(hex(month($a)),'-',monthname($a))"; + } elsif ( $podsp == 3 ) { + $field{$a} = "Year($a)"; + } else { + $field{$a} = $a; } - when (/sort2/) { - $filter{$_}->[0] = @$filters[10]; + } + elsif ( $_ =~ /received/ ) { + $filter{$_}->[0] = @$filters[2]; + $filter{$_}->[1] = @$filters[3]; + my $a = $_; + if ( $rodsp == 1 ) { + $field{$a} = "concat(hex(weekday($a)+1),'-',dayname($a))"; + } elsif ( $rodsp == 2 ) { + $field{$a} = "concat(hex(month($a)),'-',monthname($a))"; + } elsif ( $rodsp == 3 ) { + $field{$a} = "Year($a)"; + } else { + field{$a} = $a; } } + elsif ( $_ =~ /bookseller/ ) { + $filter{$_}->[0] = @$filters[4]; + } + elsif ( $_ =~ /homebranch/ ) { + $filter{$_}->[0] = @$filters[5]; + } + elsif ( $_ =~ /ccode/ ) { + $filter{$_}->[0] = @$filters[6]; + } + elsif ( $_ =~ /itemtype/ ) { + $filter{$_}->[0] = @$filters[7]; + } + elsif ( $_ =~ /budget/ ) { + $filter{$_}->[0] = @$filters[8]; + } + elsif ( $_ =~ /sort1/ ) { + $filter{$_}->[0] = @$filters[9]; + } + elsif ( $_ =~ /sort2/ ) { + $filter{$_}->[0] = @$filters[10]; + } } my @linefilter = @{ $filter{$line} }; @@ -484,11 +488,14 @@ sub calculate { # preparing calculation my $strcalc; $strcalc .= "SELECT $linefield, $colfield, "; - given ($process) { - when (1) { $strcalc .= "COUNT(*) " } - when (2) { $strcalc .= "COUNT(DISTINCT(aqorders.biblionumber)) " } - when ([3,4,5]) { $strcalc .= "SUM(aqorders.listprice) " } - default { $strcalc .= "NULL " } + if ( $process == 1 ) { + $strcalc .= "COUNT(*) "; + } elsif ( $process == 2 ) { + $strcalc .= "COUNT(DISTINCT(aqorders.biblionumber)) "; + } elsif ( $process == 3 || $process == 4 || $process == 5 ) { + $strcalc .= "SUM(aqorders.listprice) "; + } else { + $strcalc .= "NULL "; } $strcalc .= " FROM aqorders diff --git a/reports/borrowers_stats.pl b/reports/borrowers_stats.pl index 8181285448..82b9002602 100755 --- a/reports/borrowers_stats.pl +++ b/reports/borrowers_stats.pl @@ -154,12 +154,12 @@ if ($do_it) { } output_html_with_http_headers $input, $cookie, $template->output; -sub catcode_aref() { +sub catcode_aref { my $req = C4::Context->dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description"); $req->execute; return $req->fetchall_arrayref({}); } -sub catcodes_hash() { +sub catcodes_hash { my %cathash; my $catcodes = &catcode_aref; foreach (@$catcodes) { @@ -202,28 +202,24 @@ sub calculate { # Filters my $linefilter; - given ($line) { - when (/categorycode/) { $linefilter = @$filters[0] } - when (/zipcode/) { $linefilter = @$filters[1] } - when (/branchcode/) { $linefilter = @$filters[2] } - when (/sex/) { $linefilter = @$filters[5] } - when (/sort1/) { $linefilter = @$filters[6] } - when (/sort2/) { $linefilter = @$filters[7] } - when (/^patron_attr\.(.*)$/) { $linefilter = $attr_filters->{$1} } - default { $linefilter = '' } - } + if ( $line =~ /categorycode/ ) { $linefilter = @$filters[0]; } + elsif ( $line =~ /zipcode/ ) { $linefilter = @$filters[1]; } + elsif ( $line =~ /branchcode/ ) { $linefilter = @$filters[2]; } + elsif ( $line =~ /sex/ ) { $linefilter = @$filters[5]; } + elsif ( $line =~ /sort1/ ) { $linefilter = @$filters[6]; } + elsif ( $line =~ /sort2/ ) { $linefilter = @$filters[7]; } + elsif ( $line =~ /^patron_attr\.(.*)$/ ) { $linefilter = $attr_filters->{$1}; } + else { $linefilter = ''; } my $colfilter; - given ($column) { - when (/categorycode/) { $colfilter = @$filters[0] } - when (/zipcode/) { $colfilter = @$filters[1] } - when (/branchcode/) { $colfilter = @$filters[2] } - when (/sex/) { $colfilter = @$filters[5] } - when (/sort1/) { $colfilter = @$filters[6] } - when (/sort2/) { $colfilter = @$filters[7] } - when (/^patron_attr\.(.*)$/) { $colfilter = $attr_filters->{$1} } - default { $colfilter = '' } - } + if ( $column =~ /categorycode/ ) { $colfilter = @$filters[0]; } + elsif ( $column =~ /zipcode/ ) { $colfilter = @$filters[1]; } + elsif ( $column =~ /branchcode/) { $colfilter = @$filters[2]; } + elsif ( $column =~ /sex/) { $colfilter = @$filters[5]; } + elsif ( $column =~ /sort1/) { $colfilter = @$filters[6]; } + elsif ( $column =~ /sort2/) { $colfilter = @$filters[7]; } + elsif ( $column =~ /^patron_attr\.(.*)$/) { $colfilter = $attr_filters->{$1}; } + else { $colfilter = ''; } my @loopfilter; foreach my $i (0 .. scalar @$filters) { @@ -235,16 +231,16 @@ sub calculate { $cell{filter} = @$filters[$i]; } - given ($i) { - when (0) { $cell{crit} = "Cat code" } - when (1) { $cell{crit} = "Zip code" } - when (2) { $cell{crit} = "Branch code" } - when ([3,4]) { $cell{crit} = "Date of birth" } - when (5) { $cell{crit} = "Sex" } - when (6) { $cell{crit} = "Sort1" } - when (7) { $cell{crit} = "Sort2" } - default { $cell{crit} = "Unknown" } - } + if ( $i == 0) { $cell{crit} = "Cat code"; } + elsif ( $i == 1 ) { $cell{crit} = "Zip code"; } + elsif ( $i == 2 ) { $cell{crit} = "Branch code"; } + elsif ( $i == 3 || + $i == 4 ) { $cell{crit} = "Date of birth"; } + elsif ( $i == 5 ) { $cell{crit} = "Sex"; } + elsif ( $i == 6 ) { $cell{crit} = "Sort1"; } + elsif ( $i == 7 ) { $cell{crit} = "Sort2"; } + else { $cell{crit} = "Unknown"; } + push @loopfilter, \%cell; } } -- 2.39.5