Commit d0c44c6f authored by Timmer, Marius's avatar Timmer, Marius

Bugfix: Rewritten

parent 8b61e10d
This diff is collapsed.
package Kernel::System::TicketExport;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::Modules::AgentTicketPrintIntern',
'Kernel::System::DB',
'Kernel::System::Encode',
'Kernel::System::Group',
'Kernel::System::Log',
'Kernel::System::Queue',
'Kernel::System::Ticket',
'Kernel::System::User'
);
sub new {
my ($Type, %Param) = @_;
my $Self = {
DBObject => $Kernel::OM->Get('Kernel::System::DB'),
EncodeObject => $Kernel::OM->Get('Kernel::System::Encode'),
GroupObject => $Kernel::OM->Get('Kernel::System::Group'),
LogObject => $Kernel::OM->Get('Kernel::System::Log'),
QueueObject => $Kernel::OM->Get('Kernel::System::Queue'),
TicketObject => $Kernel::OM->Get('Kernel::System::Ticket'),
UserObject => $Kernel::OM->Get('Kernel::System::User')
};
bless($Self, $Type);
return $Self;
}
=item Run()
Exports all tickets and writes them into files.
my $NumberOfWrittenTickets = $TicketExportObject->Run(
QueueID => 1,
Filepath => './',
Print => 1
);
=cut;
sub Run {
my ($Self, %Param) = @_;
# Check the needed stuff
for my $Key (qw( QueueID Filepath Print )) {
if (!$Param{$Key}) {
return 0;
}
}
my $QueueID = $Param{QueueID};
my $Filepath = $Param{Filepath};
$Self->{UserID} = $Param{UserID} || 1;
my $QueueName = $Self->{QueueObject}->QueueLookup(
QueueID => $QueueID
);
# Fetch the ids of all tickets which belong to the requested queue.
# Remember that we do that using our own method which uses SQL.
my @TicketList = $Self->GetTicketList(
QueueID => $QueueID
);
for my $TicketID (@TicketList) {
my %TicketData = $Self->{TicketObject}->TicketGet(
TicketID => $TicketID,
UserID => $Self->{UserID}
);
my $Filename = sprintf('%s%s_%d_%d.pdf', $Filepath, $QueueName, $TicketID, $TicketData{TicketNumber});
print "Writing \"". $Filename ."\"\n";
# Create the PDF data string
my $PDFString = $Self->CreatePDF(
TicketID => $TicketID
);
}
}
sub CreatePDF {
my ($Self, %Param) = @_;
if (!$Param{TicketID}) {
# There is no ticket id given
return;
}
my %RootUserData = $Self->{UserObject}->GetUserData(
UserID => $Self->{UserID}
);
# Just call a new instance of our modified version of the pdf printer
my $TicketPrinter = $Kernel::OM->Get('Kernel::Modules::AgentTicketPrintIntern');
$TicketPrinter->{GroupObject} = $Self->{GroupObject};
$TicketPrinter->{UserObject} = $Self->{UserObject};
$TicketPrinter->{TicketID} = $Param{TicketID};
$TicketPrinter->{UserID} = $RootUserData{UserID};
$TicketPrinter->{UserFirstname} = $RootUserData{UserFirstname};
$TicketPrinter->{UserLastname} = $RootUserData{UserLastname};
$TicketPrinter->{UserEmail} = $RootUserData{UserEmail};
return $TicketPrinter->Run();
}
sub GetTicketList {
my ($Self, %Param) = @_;
if (!$Param{QueueID}) {
return;
}
my $Query = 'SELECT id FROM ticket WHERE queue_id = ?;';
my @TicketIDs;
$Self->{DBObject}->Prepare(
SQL => $Query,
Bind => [ \$Param{QueueID} ]
);
while (my ($ID) = $Self->{DBObject}->FetchrowArray()) {
push(@TicketIDs, $ID);
}
return @TicketIDs;
}
1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment