The only file that you need to edit is: GmapsCustomer.pm After you edit the file you will need to re-run the cron tab. My complete code is coped in the below:
Key changes: 1.) add the logic to find the customer info associated with open tickets.
Let me know if you have questions.
Code: Select all
# --
# Kernel/System/GMapsCustomer.pm - a GMaps customer
# Copyright (C) 2001-2011 Martin Edenhofer, http://edenhofer.de/
# --
# $Id: $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::System::GMapsCustomer;
use strict;
use warnings;
use Kernel::System::CustomerUser;
use Kernel::System::GMaps;
use Kernel::System::Time;
use Kernel::System::Ticket;
use Kernel::System::JSON;
use Kernel::System::VirtualFS;
use vars qw(@ISA $VERSION);
$VERSION = qw($Revision: 1.1 $) [1];
=head1 NAME
Kernel::System::GMapsCustomer - a GMaps customer lib
=head1 SYNOPSIS
All GMaps customer functions.
=head1 PUBLIC INTERFACE
=over 4
=cut
=item new()
create an object
use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::GMapsCustomer;
my $ConfigObject = Kernel::Config->new();
my $EncodeObject = Kernel::System::Encode->new(
ConfigObject => $ConfigObject,
);
my $LogObject = Kernel::System::Log->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
);
my $MainObject = Kernel::System::Main->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
LogObject => $LogObject,
);
my $GMapsCustomerObject = Kernel::System::GMapsCustomer->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
LogObject => $LogObject,
MainObject => $MainObject,
);
=cut
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
# check needed objects
for my $Object (qw(DBObject ConfigObject LogObject MainObject EncodeObject)) {
$Self->{$Object} = $Param{$Object} || die "Got no $Object!";
}
$Self->{GMapsObject} = Kernel::System::GMaps->new( %{$Self} );
$Self->{CustomerUserObject} = Kernel::System::CustomerUser->new( %{$Self} );
$Self->{TimeObject} = Kernel::System::Time->new( %{$Self} );
$Self->{TicketObject} = Kernel::System::Ticket->new( %{$Self} );
$Self->{JSONObject} = Kernel::System::JSON->new( %{$Self} );
$Self->{VirtualFSObject} = Kernel::System::VirtualFS->new( %{$Self} );
# required attributes
$Self->{RequiredAttributes} = ['UserCity'];
# attribute map
$Self->{MapAttribtes} = {
'UserStreet' => 'UserStreet',
'UserCity' => 'UserCity',
'UserCountry' => 'UserCountry',
};
# open ticket state types
$Self->{StateType} = [ 'new', 'open', 'pending reminder', 'pending auto' ];
#$Self->{StateType} = [ 'Open'];
return $Self;
}
=item DataBuild()
return the content of requested URL
my $Success = $GMapsCustomerObject->DataBuild();
=cut
sub DataBuild {
my ( $Self, %Param ) = @_;
my %List = $Self->{CustomerUserObject}->CustomerUserList(
Valid => 1,
);
#Find tickets which meet my status requirements - as defined above
my @ArrayResults = $Self->{TicketObject}->TicketSearch(
Result => 'ARRAY',
StateType => $Self->{StateType},
UserID => 1,
);
my @Data;
my $Counter = 0;
my $CounterLimit = 100_000;
USER:
foreach my $MyTicketID(@ArrayResults){
#Get the ticketID associated with the selected tickets
my %TempTicketArray = $Self->{TicketObject}->TicketGet(
TicketID => $MyTicketID,
);
[color=#FF0000] #Find the customer info associated with the ticket[/color]
my %Customer1 = $Self->{CustomerUserObject}->CustomerUserDataGet(
User => $TempTicketArray{CustomerID},
);
# geo lookup
my $Query1;
for my $KeyOrig (qw(UserStreet UserCity UserCountry)) {
my $Key = $Self->{MapAttribtes}->{$KeyOrig};
next if !$Customer1{$Key};
chomp $Customer1{$Key};
if ($Query1) {
$Query1 .= ', ';
}
$Query1 .= $Customer1{$Key};
}
my %Response = $Self->{GMapsObject}->Geocoding(
Query => $Query1,
);
next if !%Response;
# required check
next if $Response{Status} !~ /200/;
next if $Response{Accuracy} < 6;
# counter check
$Counter++;
last USER if $Counter == $CounterLimit;
my $Count = $Self->{TicketObject}->TicketSearch(
Result => 'COUNT',
StateType => $Self->{StateType},
CustomerUserLogin => $TempTicketArray{CustomerID},
UserID => 1,
);
push @Data, [ $Response{Latitude}, $Response{Longitude}, $TempTicketArray{CustomerID}, $Count ];
}
if ( !@Data ) {
$Self->{LogObject}->Log(
Priority => 'error',
Message =>
"No Customer Data found with 'UserCity' attribute (UserStreet, UserCity and UserCountry is used in generel)!",
);
return;
}
my $Content = $Self->{JSONObject}->Encode(
Data => \@Data,
);
$Self->{VirtualFSObject}->Delete(
Filename => '/CMapsCustomerMap/Data.json',
DisableWarnings => 1,
);
my $Success = $Self->{VirtualFSObject}->Write(
Content => \$Content,
Filename => '/CMapsCustomerMap/Data.json',
Mode => 'utf8',
);
return if !$Success;
return scalar @Data;
}
=item DataRead()
read data and return json string
my $ContentJSONRef = $GMapsCustomerObject->DataRead();
=cut
sub DataRead {
my ( $Self, %Param ) = @_;
my %File = $Self->{VirtualFSObject}->Read(
Filename => '/CMapsCustomerMap/Data.json',
Mode => 'utf8',
DisableWarnings => 1,
);
return '{}' if !%File;
return $File{Content};
}
1;
=back
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (http://otrs.org/).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
=cut
=head1 VERSION
$Revision: 1.1 $ $Date: 2009/06/10 19:20:24 $
=cut