how can I get the UserID of the agent who just run my static stat.
In OTRS 4 I used "$Self->{UserID}". But in Version 5.0.3 the following code no longer works:
Code: Select all
# get all valid system queues of the current user with permission type ro
my %Queues = $QueueObject->GetAllQueues(
UserID => $Self->{UserID},
Type => 'ro',
);
This is the entire static stat module:
Code: Select all
package Kernel::System::Stats::Static::AccountedTimeQueue;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::Language',
'Kernel::System::DB',
'Kernel::System::Queue',
'Kernel::System::Time',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub GetObjectBehaviours {
my ( $Self, %Param ) = @_;
my %Behaviours = (
ProvidesDashboardWidget => 0,
);
return %Behaviours;
}
sub Param {
my $Self = shift;
# get time object
my $TimeObject = $Kernel::OM->Get('Kernel::System::Time');
# get current time
my ( $s, $m, $h, $D, $M, $Y ) = $TimeObject->SystemTime2Date(
SystemTime => $TimeObject->SystemTime(),
);
# get one month before
my $SelectedYear = $M == 1 ? $Y - 1 : $Y;
my $SelectedMonth = $M == 1 ? 12 : $M - 1;
# create possible time selections
my %Year = map { $_ => $_; } ( $Y - 10 .. $Y );
my %Month = map { $_ => sprintf( "%02d", $_ ); } ( 1 .. 12 );
# get queue object
my $QueueObject = $Kernel::OM->Get('Kernel::System::Queue');
# get all valid system queues of the current user with permission type ro
my %Queues = $QueueObject->GetAllQueues(
UserID => $Self->{UserID},
Type => 'ro',
);
my @Params = (
{
Frontend => 'Year',
Name => 'Year',
Multiple => 0,
Size => 0,
SelectedID => $SelectedYear,
Data => \%Year,
},
{
Frontend => 'Month',
Name => 'Month',
Multiple => 0,
Size => 0,
SelectedID => $SelectedMonth,
Data => \%Month,
},
{
Frontend => 'Queue',
Name => 'QueueIDs',
Multiple => 0,
Size => 0,
InputType => 'SelectField',
Data => \%Queues,
},
);
return @Params;
}
sub Run {
my ( $Self, %Param ) = @_;
my $Year = $Param{Year};
my $Month = sprintf( "%02d", $Param{Month} );
my $QueueID = $Param{QueueIDs};
# get queue object
my $QueueObject = $Kernel::OM->Get('Kernel::System::Queue');
my %Queue = $QueueObject->QueueGet(
ID => $QueueID,
);
my $QueueName = $Queue{Name};
# set report title
my $Title = "- $Year-$Month $QueueName";
# table headlines
my @HeadData = (
'Ticket#',
'Title',
'Created',
'Customer ID',
'Customer',
'Customer user',
'Accounted time',
);
# get language object
my $LanguageObject = $Kernel::OM->Get('Kernel::Language');
# translating headlines
@HeadData = map { $LanguageObject->Translate( $_ ) } @HeadData;
my @Data;
my $SQL = "SELECT derived.TN, " .
" derived.TITLE, " .
" derived.CREATE_TIME, " .
" derived.CUSTOMER_ID, " .
" derived.NAME, " .
" derived.CUSTOMER_USER_ID, " .
" SUM(derived.TIME_UNIT) AS TIME_UNIT " .
"FROM ( " .
" SELECT ticket.TN, " .
" ticket.TITLE, " .
" DATE_FORMAT(ticket.CREATE_TIME,GET_FORMAT(DATE,'EUR')) AS CREATE_TIME, " .
" ticket.CUSTOMER_ID, " .
" COALESCE(customer_company.NAME, '') AS NAME, " .
" ticket.CUSTOMER_USER_ID, " .
" time_accounting.TIME_UNIT " .
" FROM ticket LEFT JOIN customer_company " .
" ON ticket.CUSTOMER_ID = customer_company.CUSTOMER_ID " .
" INNER JOIN time_accounting " .
" ON ticket.ID = time_accounting.TICKET_ID " .
" WHERE ticket.QUEUE_ID = ? " .
" AND YEAR(time_accounting.CREATE_TIME) = ? " .
" AND MONTH(time_accounting.CREATE_TIME) = ? " .
" ) AS derived " .
"GROUP BY derived.TN, derived.TITLE, derived.CUSTOMER_ID, " .
" derived.NAME, derived.CUSTOMER_USER_ID " .
"ORDER BY derived.TN";
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
$DBObject->Prepare(
SQL => $SQL,
Bind => [ \$QueueID, \$Year, \$Month ],
);
while ( my @Row = $DBObject->FetchrowArray() ) {
push (@Data, \@Row);
}
return ( [$Title], [@HeadData], @Data );
}
1;
Harald