X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FHelper%2FSorted.pm;h=2bdc51b6b6ec067031552363acdcb50dafe0fb63;hb=9efca844f6b8086d64589b4cecbf5b76a120afd0;hp=57fb5e0bcf23c7b077045a524b24dc542bcea546;hpb=28cda5b67bc9cef793911fa4e65b6aa9b81903e3;p=kivitendo-erp.git diff --git a/SL/Controller/Helper/Sorted.pm b/SL/Controller/Helper/Sorted.pm index 57fb5e0bc..2bdc51b6b 100644 --- a/SL/Controller/Helper/Sorted.pm +++ b/SL/Controller/Helper/Sorted.pm @@ -3,6 +3,7 @@ package SL::Controller::Helper::Sorted; use strict; use Carp; +use List::MoreUtils qw(uniq); use Exporter qw(import); our @EXPORT = qw(make_sorted get_sort_spec get_current_sort_params set_report_generator_sort_options @@ -10,7 +11,7 @@ our @EXPORT = qw(make_sorted get_sort_spec get_current_sort_params set_report_ge use constant PRIV => '__sortedhelperpriv'; -my $controller_sort_spec; +my %controller_sort_spec; sub make_sorted { my ($class, %specs) = @_; @@ -21,7 +22,7 @@ sub make_sorted { while (my ($column, $spec) = each %specs) { next if $column =~ m/^[A-Z_]+$/; - $spec = $specs{$column} = { title => $spec } if !ref $spec; + $spec = $specs{$column} = { title => $spec } if (ref($spec) || '') ne 'HASH'; $spec->{model} ||= $specs{MODEL}; $spec->{model_column} ||= $column; @@ -34,7 +35,7 @@ sub make_sorted { $specs{ONLY} ||= []; $specs{ONLY} = [ $specs{ONLY} ] if !ref $specs{ONLY}; - $controller_sort_spec = \%specs; + $controller_sort_spec{$class} = \%specs; my %hook_params = @{ $specs{ONLY} } ? ( only => $specs{ONLY} ) : (); $class->run_before('_save_current_sort_params', %hook_params); @@ -52,7 +53,7 @@ sub make_sorted { sub get_sort_spec { my ($class_or_self) = @_; - return $controller_sort_spec; + return $controller_sort_spec{ref($class_or_self) || $class_or_self}; } sub get_current_sort_params { @@ -90,6 +91,13 @@ sub set_report_generator_sort_options { } $params{report}->set_sort_indicator($current_sort_params{by}, 1 - $current_sort_params{dir}); + + if ($params{report}->{export}) { + $params{report}->{export}->{variable_list} = [ uniq( + @{ $params{report}->{export}->{variable_list} }, + @{ $self->get_sort_spec->{FORM_PARAMS} } + )]; + } } # @@ -100,9 +108,10 @@ sub _save_current_sort_params { my ($self) = @_; my $sort_spec = $self->get_sort_spec; + my $dir_idx = $sort_spec->{FORM_PARAMS}->[1]; $self->{PRIV()} = { by => $::form->{ $sort_spec->{FORM_PARAMS}->[0] }, - dir => !!$::form->{ $sort_spec->{FORM_PARAMS}->[1] } * 1, + dir => defined($::form->{$dir_idx}) ? $::form->{$dir_idx} * 1 : undef, }; # $::lxdebug->message(0, "saving current sort params to " . $self->{PRIV()}->{by} . ' / ' . $self->{PRIV()}->{dir}); @@ -342,16 +351,28 @@ applying default parameters etc). =item C -This function sets two things in an instance of -L: the sort indicator and the links for those -column headers that are sortable. +This function does three things with an instance of +L: + +=over 4 + +=item 1. it sets the sort indicator, + +=item 2. it sets the the links for those column headers that are +sortable and + +=item 3. it adds the C fields to the list of variables in +the report generator's export options. + +=back The report generator instance must be passed as the parameter C. The parameter C must be an array reference of column names that are sortable. -The report generator instance must already have its columns set via a -call to its L function. +The report generator instance must already have its columns and export +options set via calls to its L and +L functions. =back