- HTML Admin-Manual
- PDF Admin-Manual
- HTML ITSM-Manual
- PDF ITSM-Manual
- HTML Developer-Manual
- PDF Developer-Manual
- HTML Developer-API
7.9. Stats Module
A stats module is easy - you just need two functions. Param() to get all usable params for the stats and Run() to return the stats result.
Kernel/Config.pm:
$Self->{SystemStatsMap}->{"Ticket::SomeExampleStats1"} = {
Name => 'Some Example Stats',
Module => 'Kernel::System::Stats::SomeExampleStats',
Desc => 'New created tickets for each queue in selected month.',
SumCol => 1,
SumRow => 1,
UseResultCache => 0,
Output => ['Print', 'CSV', 'Graph'],
OutputDefault => 'Print',
};
Kernel/System/Stats/SomeExampleStats.pm:
# --
# Kernel/System/Stats/SomeExampleStats.pm - stats module
# Copyright (C) 2005 Hans Mueller mail@example.com
# --
# $Id: module-format.xml,v 1.17 2006/04/06 19:33:07 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --
package Kernel::System::Stats::SomeExampleStats;
use strict;
sub new {
my $Type = shift;
my %Param = @_;
# allocate new hash for object
my $Self = {};
bless ($Self, $Type);
# get common opjects
foreach (keys %Param) {
$Self->{$_} = $Param{$_};
}
# check all needed objects
foreach (qw(DBObject ConfigObject LogObject)) {
die "Got no $_" if (!$Self->{$_});
}
return $Self;
}
# --
sub Param {
my $Self = shift;
my @Params = ();
# get current time
my ($s,$m,$h, $D,$M,$Y) = $Self->{TimeObject}->SystemTime2Date(
SystemTime => $Self->{TimeObject}->SystemTime(),
);
# get one month bevore
if ($M == 1) {
$M = 12;
$Y = $Y - 1;
}
else {
$M = $M -1;
}
# create possible time selections
my %Year = ();
foreach ($Y-10..$Y+1) {
$Year{$_} = $_;
}
my %Month = ();
foreach (1..12) {
my $Tmp = sprintf("%02d", $_);
$Month{$_} = $Tmp;
}
push (@Params, {
Frontend => 'Year',
Name => 'Year',
Multiple => 0,
Size => 0,
SelectedID => $Y,
Data => {
%Year,
},
},
);
push (@Params, {
Frontend => 'Month',
Name => 'Month',
Multiple => 0,
Size => 0,
SelectedID => $M,
Data => {
%Month,
},
},
);
return @Params;
}
# --
sub Run {
my $Self = shift;
my %Param = @_;
my $Title = "$Param{Year}-$Param{Month}";
my @HeadData = ('Col A', 'Col B', 'Col C');
my @Data = (
[1, 4, 7],
[6, 1, 4],
[9, 4, 6],
);
return ([$Title],[@HeadData], @Data);
}
# --
1;

