lib/Kernel/Modules/TicketAutoAssignment.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« script/otrs.AutoAllocation.pl ↑ Summary
1 # --
2 # Kernel/Modules/TicketAutoAssignment.pm - all ticket functions
3 # Copyright (C) 2001-2011 OTRS AG, http://otrs.org/
4 # --
5 # $Id: TicketAutoAssignment.pm,v 1.0.0.1 2011/02/05 00:05:20 en Exp $
6 # --
7 # This software comes with ABSOLUTELY NO WARRANTY. For details, see
8 # the enclosed file COPYING for license information (AGPL). If you
9 # did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
10 # --
11
12 package Kernel::Modules::TicketAutoAssignment;
13
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16
17 0 ▶use Kernel::Config;
Subroutine BEGIN: called CC=1 SCAR=2.6
18 use Kernel::System::Encode;
19 use Kernel::System::Main;
20 use Kernel::System::Log;
21 use Kernel::System::Time;
22 use Kernel::System::DB;
23 use Kernel::System::Ticket;
24
25 use vars qw($VERSION);
26 $VERSION = qw($Revision: 1.28 $) [1];
27
28 sub new {
29 my ( $Type, %Param ) = @_;
30
31 # allocate new hash for object
32 my $Self = {%Param};
33 bless( $Self, $Type );
34
35 # create common objects
36 $Self->{ConfigObject} = Kernel::Config->new();
37 $Self->{LogObject} = Kernel::System::Log->new(
38 LogPrefix => 'OTRS-otrs.TicketAutoAllocation.pl',
39 %{$Self},
40 );
41 $Self->{EncodeObject} = Kernel::System::Encode->new(%{$Self});
42 $Self->{MainObject} = Kernel::System::Main->new(%{$Self});
43 $Self->{TimeObject} = Kernel::System::Time->new(%{$Self});
44 $Self->{DBObject} = Kernel::System::DB->new(%{$Self});
45 $Self->{TicketObject} = Kernel::System::Ticket->new(%{$Self});
46
47
48 # check all needed objects
49 for (qw(DBObject TicketObject ConfigObject LogObject)) {
50 if ( !$Self->{$_} ) {
51 die "Got no $_!\n";
52 }
53 }
54
55 return $Self;
56 }
57
58
59 sub Run {
60 my ( $Self, %Param ) = @_;
61
62 # declar variables and get passed arguments
63 my %TotalTickets = ();
64 my $SutableAgent;
65 my @Users;
66 my $OnlineAgents = $Param{UserIds};
67
68 # get matched users
69 if(ref $OnlineAgents eq 'ARRAY' ) {
70 @Users = @{$OnlineAgents};
71 }
72
73 # get current time
74 my ($Sec, $Min, $Hour, $Day, $Month, $Year) = $Self->{TimeObject}->SystemTime2Date(
75 SystemTime => $Self->{TimeObject}->SystemTime()-1*86400
76 );
77 my $LastDay = sprintf( "%04d-%02d-%02d",$Year,$Month,$Day);
78
79 ($Sec, $Min, $Hour, $Day, $Month, $Year) = $Self->{TimeObject}->SystemTime2Date(
80 SystemTime => $Self->{TimeObject}->SystemTime()
81 );
82
83 my $CurDay = sprintf( "%04d-%02d-%02d",$Year,$Month,$Day);
84
85 if( !@Users ) {
86 $Self->{LogObject}->Log(
87 Priority => 'notice',
88 Message => "No suitable Agent found.",
89 );
90 }
91
92 my %TicketSearchSummary = (
93 CurClosedTickets => {
94 StateType => [ 'closed', ],
95 TicketCloseTimeNewerDate => $CurDay.' 00:00:00',
96 },
97 CurOpenTickets => {
98 StateType => [ 'open', 'new' ],
99 },
100 );
101
102 # for each user get total ticket count
103 foreach my $user ( @Users ) {
104 foreach my $type (keys %TicketSearchSummary) {
105 my @TotalTicket = $Self->{TicketObject}->TicketSearch(
106 Result => 'ARRAY',
107 %{ $TicketSearchSummary{ $type } },
108 UserID => '1',
109 OwnerIDs => [ "$user"],
110 );
111
112 $TotalTickets{"$user"}{"$type"} = scalar @TotalTicket;
113 }
114 $TotalTickets{"$user"}{'TotalTickets'} = $TotalTickets{"$user"}{'CurClosedTickets'} + $TotalTickets{"$user"}{'CurOpenTickets'};
115 }
116
117 ## get userid having lowest tickets
118 ## sort above builded hash by value
119 foreach (sort { ($TotalTickets{$a}{'TotalTickets'} <=> $TotalTickets{$b}{'TotalTickets'}) } keys %TotalTickets ) {
120 $SutableAgent = $_;
121 last ;
122 }
123
124 return $SutableAgent;
125 }
126
127 1;
128
129 __END__
« script/otrs.AutoAllocation.pl ↑ Summary