1# -- 2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/ 3# -- 4# This software comes with ABSOLUTELY NO WARRANTY. For details, see 5# the enclosed file COPYING for license information (GPL). If you 6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. 7# -- 8 9package Kernel::Output::PDF::Statistics; 10 11## nofilter(TidyAll::Plugin::OTRS::Perl::PodChecker) 12 13use strict; 14use warnings; 15 16use List::Util qw( first ); 17 18our @ObjectDependencies = ( 19 'Kernel::Config', 20 'Kernel::Output::HTML::Layout', 21 'Kernel::System::Log', 22 'Kernel::System::PDF', 23 'Kernel::System::User', 24); 25 26sub new { 27 my ( $Type, %Param ) = @_; 28 29 # allocate new hash for object 30 my $Self = {}; 31 bless( $Self, $Type ); 32 33 return $Self; 34} 35 36sub GeneratePDF { 37 my ( $Self, %Param ) = @_; 38 39 for my $Needed (qw(Stat Title HeadArrayRef StatArray)) { 40 if ( !$Param{$Needed} ) { 41 $Kernel::OM->Get('Kernel::System::Log')->Log( 42 Priority => "error", 43 Message => "Need $Needed!" 44 ); 45 return; 46 } 47 } 48 49 my $Title = $Param{Title}; 50 my $HeadArrayRef = $Param{HeadArrayRef}; 51 my $Stat = $Param{Stat}; 52 my @StatArray = @{ $Param{StatArray} // [] }; 53 54 my $PDFObject = $Kernel::OM->Get('Kernel::System::PDF'); 55 my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout'); 56 my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); 57 58 my $Page = $LayoutObject->{LanguageObject}->Translate('Page'); 59 my $Time = $LayoutObject->{Time}; 60 61 # get maximum number of pages 62 my $MaxPages = $ConfigObject->Get('PDF::MaxPages'); 63 if ( !$MaxPages || $MaxPages < 1 || $MaxPages > 1000 ) { 64 $MaxPages = 100; 65 } 66 67 # create the header 68 my $CellData; 69 my $CounterRow = 0; 70 my $CounterHead = 0; 71 for my $Content ( @{$HeadArrayRef} ) { 72 $CellData->[$CounterRow]->[$CounterHead]->{Content} = $Content; 73 $CellData->[$CounterRow]->[$CounterHead]->{Font} = 'ProportionalBold'; 74 $CounterHead++; 75 } 76 if ( $CounterHead > 0 ) { 77 $CounterRow++; 78 } 79 80 # create the content array 81 for my $Row (@StatArray) { 82 my $CounterColumn = 0; 83 for my $Content ( @{$Row} ) { 84 $CellData->[$CounterRow]->[$CounterColumn]->{Content} = $Content; 85 $CounterColumn++; 86 } 87 $CounterRow++; 88 } 89 90 # output 'No matches found', if no content was given 91 if ( !$CellData->[0]->[0] ) { 92 $CellData->[0]->[0]->{Content} = $LayoutObject->{LanguageObject}->Translate('No matches found.'); 93 } 94 95 my $TranslateTimeZone = $LayoutObject->{LanguageObject}->Translate('Time Zone'); 96 97 # if a time zone was selected 98 if ( $Param{TimeZone} ) { 99 $Title .= " ($TranslateTimeZone $Param{TimeZone})"; 100 } 101 102 # page params 103 my %PageParam; 104 $PageParam{PageOrientation} = 'landscape'; 105 $PageParam{MarginTop} = 30; 106 $PageParam{MarginRight} = 40; 107 $PageParam{MarginBottom} = 40; 108 $PageParam{MarginLeft} = 40; 109 110 $PageParam{HeaderRight} = $ConfigObject->Get('Stats::StatsHook') . $Stat->{StatNumber}; 111 $PageParam{HeadlineLeft} = $Title; 112 113 # table params 114 my %TableParam; 115 $TableParam{CellData} = $CellData; 116 $TableParam{Type} = 'Cut'; 117 $TableParam{FontSize} = 6; 118 $TableParam{Border} = 0; 119 $TableParam{BackgroundColorEven} = '#DDDDDD'; 120 $TableParam{Padding} = 4; 121 122 # create new pdf document 123 $PDFObject->DocumentNew( 124 Title => $ConfigObject->Get('Product') . ': ' . $Title, 125 Encode => $LayoutObject->{UserCharset}, 126 ); 127 128 # start table output 129 $PDFObject->PageNew( 130 %PageParam, 131 FooterRight => $Page . ' 1', 132 ); 133 134 $PDFObject->PositionSet( 135 Move => 'relativ', 136 Y => -6, 137 ); 138 139 # output title 140 $PDFObject->Text( 141 Text => $Title, 142 FontSize => 13, 143 ); 144 145 $PDFObject->PositionSet( 146 Move => 'relativ', 147 Y => -6, 148 ); 149 150 # output "printed by" 151 $PDFObject->Text( 152 Text => $Time, 153 FontSize => 9, 154 ); 155 156 $PDFObject->PositionSet( 157 Move => 'relativ', 158 Y => -14, 159 ); 160 161 COUNT: 162 for ( 2 .. $MaxPages ) { 163 164 # output table (or a fragment of it) 165 %TableParam = $PDFObject->Table( %TableParam, ); 166 167 # stop output or output next page 168 last COUNT if $TableParam{State}; 169 170 $PDFObject->PageNew( 171 %PageParam, 172 FooterRight => $Page . ' ' . $_, 173 ); 174 } 175 176 return $PDFObject->DocumentOutput(); 177} 178 1791; 180