From ad82f6dc55447fb41f206d2224865d31f374d40a Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Tue, 24 Jul 2012 11:12:53 +0200 Subject: [PATCH] Bug 8443: Suggestions publication year and copyright date Signed-off-by: Corinne HAYET http://bugs.koha-community.org/show_bug.cgi?id=5357 --- C4/Suggestions.pm | 79 +++++++++++-------- .../prog/en/modules/suggestion/suggestion.tt | 14 ++-- suggestion/suggestion.pl | 16 ++++- 3 files changed, 67 insertions(+), 42 deletions(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index 0cb484a..0d07c1f 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -93,7 +93,7 @@ sub SearchSuggestion { my $dbh = C4::Context->dbh; my @sql_params; my @query = ( - q{ SELECT suggestions.*, + q/SELECT suggestions.*, U1.branchcode AS branchcodesuggestedby, B1.branchname AS branchnamesuggestedby, U1.surname AS surnamesuggestedby, @@ -115,49 +115,61 @@ sub SearchSuggestion { LEFT JOIN borrowers AS U2 ON managedby=U2.borrowernumber LEFT JOIN branches AS B2 ON B2.branchcode=U2.branchcode LEFT JOIN categories AS C2 ON C2.categorycode = U2.categorycode - WHERE 1=1 - } , map { - if ( my $s = $suggestion->{$_} ) { - push @sql_params,'%'.$s.'%'; - " and suggestions.$_ like ? "; - } else { () } - } qw( title author isbn publishercode collectiontitle ) + WHERE 1=1/ ); + + # filter on biblio informations + foreach my $field ( + grep { + my $fieldname = $_; + any { $fieldname eq $_ } qw/title author isbn publishercode copyrightdate collectiontitle/ + } keys %$suggestion + ) + { + if ( $suggestion->{$field} ) { + push @sql_params, $suggestion->{$field}; + push @query, " AND suggestions.$field = ?"; + } + } + # filter on user branch my $userenv = C4::Context->userenv; if (C4::Context->preference('IndependantBranches')) { - if ($userenv) { - if (($userenv->{flags} % 2) != 1 && !$suggestion->{branchcode}){ - push @sql_params,$$userenv{branch}; - push @query,q{ and (suggestions.branchcode = ? or suggestions.branchcode ='')}; - } + if ($userenv) { + if (($userenv->{flags} % 2) != 1 && !$suggestion->{branchcode}){ + push @sql_params, $userenv->{branch}; + push @query, q/ AND (suggestions.branchcode = ? or suggestions.branchcode = '')/; } + } } - foreach my $field (grep { my $fieldname=$_; - any {$fieldname eq $_ } qw< - STATUS branchcode itemtype suggestedby managedby acceptedby - bookfundid biblionumber - >} keys %$suggestion - ) { - if ($$suggestion{$field}){ - push @sql_params,$suggestion->{$field}; - push @query, " and suggestions.$field=?"; - } + # filter on nillable fields + foreach my $field ( + grep { + my $fieldname = $_; + any { $fieldname eq $_ } qw/STATUS branchcode itemtype suggestedby managedby acceptedby bookfundid biblionumber/ + } keys %$suggestion + ) + { + if ( $suggestion->{$field} ) { + push @sql_params, $suggestion->{$field}; + push @query, " AND suggestions.$field = ?"; + } else { - push @query, " and (suggestions.$field='' OR suggestions.$field IS NULL)"; + push @query, " AND (suggestions.$field = '' OR suggestions.$field IS NULL)"; } } + # filter on date fields my $today = C4::Dates->today('iso'); - - foreach ( qw( suggesteddate manageddate accepteddate ) ) { - my $from = $_ . "_from"; - my $to = $_ . "_to"; - if ($$suggestion{$from} || $$suggestion{$to}) { - push @query, " AND suggestions.suggesteddate BETWEEN '" - . (format_date_in_iso($$suggestion{$from}) || 0000-00-00) . "' AND '" . (format_date_in_iso($$suggestion{$to}) || $today) . "'"; - } + foreach my $field ( qw/suggesteddate manageddate accepteddate/ ) { + my $from = $field."_from"; + my $to = $field."_to"; + if ($suggestion->{$from} || $suggestion->{$to}) { + push @query, " AND suggestions.$field BETWEEN ? AND ?"; + push @sql_params, format_date_in_iso($suggestion->{$from}) || '0000-00-00'; + push @sql_params, format_date_in_iso($suggestion->{$to}) || $today; + } } $debug && warn "@query"; @@ -165,7 +177,8 @@ sub SearchSuggestion { $sth->execute(@sql_params); my @results; while ( my $data=$sth->fetchrow_hashref ){ - $$data{$$data{STATUS}} = 1; + # add status as field + $data->{$data->{STATUS}} = 1; push(@results,$data); } return (\@results); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt index edaea79..aa026dc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -493,7 +493,7 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • -
  • +
  • Suggestion information

    @@ -514,10 +514,10 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • [% suggesteddate %] - + - +
  • @@ -527,10 +527,10 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • [% manageddate %] - + - +
  • @@ -540,10 +540,10 @@ $(document).ready(function() { calcNewsuggTotal(); });
  • [% accepteddate %] - + - +
  • diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index 99f38eb..aadf58f 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -188,12 +188,24 @@ elsif ( $op eq 'show' ) { if ($op=~/else/) { $op='else'; - $displayby||="STATUS"; + $displayby||="STATUS"; # by default, organize by status delete $$suggestion_ref{'branchcode'} if($displayby eq "branchcode"); my $criteria_list=GetDistinctValues("suggestions.".$displayby); + my %criteria_dv; + foreach (@$criteria_list) { + my $criteria_key; + if ($_->{value}) { + $criteria_key = $_->{value}; + } else { + # agregate null and empty values under empty value + $criteria_key = ''; + } + my $criteria_cnt = $criteria_dv{$criteria_key} || 0; + $criteria_dv{$criteria_key} = $criteria_cnt + $_->{cnt}; + } my @allsuggestions; my $reasonsloop = GetAuthorisedValues("SUGGEST"); - foreach my $criteriumvalue ( map { $$_{'value'} } @$criteria_list ) { + foreach my $criteriumvalue (keys %criteria_dv) { # By default, display suggestions from current working branch if(not defined $branchfilter) { $$suggestion_ref{'branchcode'} = C4::Context->userenv->{'branch'}; -- 1.7.2.5