Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ee5d63a6

Von Sven Schöling vor fast 17 Jahren hinzugefügt

  • ID ee5d63a6e2b3ba0d962d64376623c26eacd393a5
  • Vorgänger 58a1b54b
  • Nachfolger cfbcb233

Einfachere sort_column und viiiel Doku.

Unterschiede anzeigen:

SL/ReportGenerator.pm
78 78

  
79 79
sub set_column_order {
80 80
  my $self    = shift;
81

  
82
  my $order   = 0;
83
  my %columns = map { $order++; ($_, $order) } @_;
84

  
85
  foreach my $column (sort keys %{ $self->{columns} }) {
86
    next if $columns{$column};
87

  
88
    $order++;
89
    $columns{$column} = $order;
90
  }
91

  
92
  $self->{column_order} = [ sort { $columns{$a} <=> $columns{$b} } keys %columns ];
81
  my %seen;
82
  $self->{column_order} = [ grep { !$seen{$_}++ } @_, sort keys %{ $self->{columns} } ];
93 83
}
94 84

  
95 85
sub set_sort_indicator {
......
793 783
}
794 784

  
795 785
1;
786

  
787
__END__
788

  
789
=head1 NAME
790

  
791
SL::ReportGenerator.pm: the Lx-Office way of getting data in shape
792

  
793
=head1 SYNOPSIS
794

  
795
  my $report = SL::ReportGenerator->new(\%myconfig, $form);
796
     $report->set_options(%options);                         # optional
797
     $report->set_columns(%column_defs);
798
     $report->set_sort_indicator($column, $direction);       # optional
799
     $report->add_data($row1, $row2, @more_rows);
800
     $report->generate_with_headers();
801

  
802
This creates a report object, sets a few columns, adds some data and generates a standard report. 
803
Sorting of columns will be alphabetic, and options will be set to their defaults.
804
The report will be printed including table headers, html headers and http headers.
805

  
806
=head1 DESCRIPTION
807

  
808
Imagine the following scenario:
809
There's a simple form, which loads some data from the database, and needs to print it out. You write a template for it.
810
Then there may be more than one line. You add a loop in the template.
811
Then there are some options made by the user, such as hidden columns. You add more to the template.
812
Then it lacks usability. You want it to be able to sort the data. You add code for that.
813
Then there are too many results, you need pagination, you want to print or export that data..... and so on.
814

  
815
The ReportGenerator class was designed because this exact scenario happened about half a dozen times in Lx-Office. 
816
It's purpose is to manage all those formating, culling, sorting, and templating. 
817
Which makes it almost as complicated to use as doing the work for yourself.
818

  
819
=head1 FUNCTIONS
820

  
821
=over 4
822

  
823
=item new \%myconfig,$form,%options
824

  
825
Creates a new ReportGenerator object, sets all given options, and returns it.
826

  
827
=item set_columns @columns
828

  
829
Sets the columns available to this report.
830

  
831
=item set_column_order @columns
832

  
833
Sets the order of columns. Any columns not present here are appended in alphabetic order.
834

  
835
=item set_sort_indicator $column,$direction
836

  
837
Sets sorting ot the table by specifying a column and a direction, where the direction will be evaluated to ascending if true.
838
Note that this is only for displaying. The data has to be presented already sorted.
839

  
840
=item add_data \@data
841

  
842
=item add_data \%data
843

  
844
Adds data to the report. A given hash_ref is interpreted as a single line of data, every array_ref as a collection of lines. 
845
Every line will be expected to be in a kay => value format. Note that this data has to be already sorted. 
846
ReportGenerator does no sorting on its own, only provides links to sorting and visual cue as to which column was sorted by.
847

  
848
=item add_separator
849

  
850
Adds a separator line to the report.
851

  
852
=item add_control \%data
853

  
854
Adds a control element to the data. Control elements are an experimental feature to add functionality to a report the regular data cannot.
855
Every control element needs to set IS_CONTROL_DATA, in order to be recongnized by the template. 
856
Currently the only control element is a colspan element, which can be used as a mini header further down the report.
857

  
858
=item clear_data
859

  
860
Deletes all data filled into the report, but keeps options set.
861

  
862
=item set_options %options
863

  
864
Sets options. For an incomplete list of options, see section configuration.
865

  
866
=item set_options_from_form
867

  
868
Tries to import options from the $form object given at creation
869

  
870
=item set_export_options $next_sub,@variable_list
871

  
872
Sets next_sub and additional variables needed for export.
873

  
874
=item get_attachment_basename
875

  
876
Returns the set attachment_basename option, or 'report' if nothing was set. See configuration for the option.
877

  
878
=item generate_with_headers
879

  
880
Parses the report, adds headers and prints it out. Headers depend on the option 'output_format', 
881
for example 'HTML' will add proper table headers, html headers and http headers. See configuration for this option.
882

  
883
=item get_visible_columns $format
884

  
885
Returns a list of columns that will be visible in the report after considering all options or match the given format.
886

  
887
=item html_format $value
888

  
889
Escapes HTML characters in $value and substitutes newlines with '<br>'. Returns the escaped $value.
890

  
891
=item prepare_html_content $column,$name,@column_headers
892

  
893
Parses the data, and sets internal data needed for certain output format. Must be called once before the template is invoked. 
894
Should not be called extrenally, since all render and generate functions invoke it anyway.
895
 
896
=item generate_html_content
897

  
898
The html generation function. Is invoked by generate_with_headers.
899

  
900
=item generate_pdf_content
901

  
902
The PDF generation function. Is invoked by the pdf render functions.
903

  
904
=item generate_csv_content
905

  
906
The CSV generation function. Uses XS_CSV to parse the information into csv.
907

  
908
=item render_pdf_with_pdf_api2
909

  
910
PDF render function. Uses PDF module.
911

  
912
=item render_pdf_with_html2ps
913

  
914
PDF render function. Uses html2ps to render.
915

  
916
=back
917

  
918
=head1 CONFIGURATION
919

  
920
These are known options and their defaults. Options for pdf export and csv export need to be set as a hashref inside the export option.
921

  
922
=head2 General Options
923

  
924
=over 4
925

  
926
=item std_column_visibility
927

  
928
Standard column visibility. Used if no visibility is set. Use this to save the trouble of enabling every column. Default is no.
929

  
930
=item output_format
931

  
932
Output format. Used by generate_with_headers to determine the format. Supported options are HTML, CSV, and PDF. Default is HTML.
933

  
934
=item allow_pdf_export
935

  
936
Used to determine if a button for PDF export should be displayed. Default is yes.
937

  
938
=item allow_csv_export
939

  
940
Used to determine if a button for CSV export should be displayed. Default is yes.
941

  
942
=item html_template
943

  
944
The template to be used for HTML reports. Default is 'report_generator/html_report'.
945

  
946
=item pdf_template
947

  
948
The template to be used for PDF reports. Default is 'report_generator/pdf_report'.
949

  
950
=back
951

  
952
=head2 PDF Options
953

  
954
=over 4
955

  
956
=item paper_size
957

  
958
Paper size. Default is a4.
959

  
960
=item orientation (landscape)
961

  
962
Landscape or portrait. Default is landscape.
963

  
964
=item font_name 
965

  
966
Default is Verdana.
967

  
968
=item font_size
969

  
970
Default is 7.
971

  
972
=item margin_top
973

  
974
=item margin_left
975

  
976
=item margin_bottom
977

  
978
=item margin_right
979

  
980
Default all to 1.5.
981

  
982
=item number
983

  
984
Default is 1.
985

  
986
=item print
987

  
988
Print or not? Default is no.
989

  
990
=item printer_id
991

  
992
Default 0.
993

  
994
=item copies
995

  
996
Default 1.
997

  
998
=back
999

  
1000
=head2 CSV Options
1001

  
1002
=over 4
1003

  
1004
=item quote_char
1005

  
1006
Character to enclose entries. Default is double quote (").
1007

  
1008
=item sep_char
1009

  
1010
Character to separate entries. Default is semicolon (;).
1011

  
1012
=item escape_char
1013

  
1014
Character to escape the quote_char. Default is souble quote (").
1015

  
1016
=item eol_style
1017

  
1018
End of line style. Default is Unix.
1019

  
1020
=item headers
1021

  
1022
Include headers? Default is yes.
1023

  
1024
=back
1025

  
1026
=head1 SEE ALO
1027

  
1028
C<Template.pm>
1029

  
1030
=head1 MODULE AUTHORS
1031

  
1032
Moritz Bunkus E<lt>mbunkus@linet-services.deE<gt>
1033

  
1034
L<http://linet-services.de>

Auch abrufbar als: Unified diff