AgentsPerQueue.pm
3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# --
# Kernel/Modules/AgentsPerQueue.pm - frontend module for displaying the agents per queue matrix panel
#
# Copyright (C) 2014 SeTIC - UFSC - http://setic.ufsc.br/
# Rodrigo Goncalves - rodrigo.g@ufsc.br
#
# Version 2015-01-15 - Adjustments for OTRS 4
# Version 2018-01-25 - Refactoring for OTRS 6
#
# --
# 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::Modules::AgentsPerQueue;
use strict;
use warnings;
use Kernel::System::VariableCheck qw(:all);
our @ObjectDependencies = (
"Kernel::System::Web::Request", # OLD ParamObject
"Kernel::System::DB",
"Kernel::Output::HTML::Layout",
"Kernel::System::Log",
"Kernel::Config"
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {%Param};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
my %Data = ();
my $layoutObject = $Kernel::OM->Get("Kernel::Output::HTML::Layout");
my $languageObject = $Kernel::OM->Get("Kernel::Language");
# load data
my %matrix = $Self->GetQueuesPerAgent();
# build output
my $Output =
$layoutObject->Header( Title => $languageObject->Translate("Queues per agent") );
$Output .= $layoutObject->NavigationBar();
my $id = 1;
# include each agent
foreach my $agent ( sort keys %matrix ) {
$layoutObject->Block(
Name => 'QueuesPerAgent',
Data => { ID => $id, Agent => $agent, Queues => $matrix{$agent}{"Manage"}, Paths => $matrix{$agent}{"Path"} },
);
$id += 1;
}
$Output .= $layoutObject->Output(
Data => \%Data,
TemplateFile => 'AgentsPerQueue',
);
$Output .= $layoutObject->Footer();
return $Output;
}
sub GetQueuesPerAgent {
my ( $Self, %Param ) = @_;
my %result = ();
my $dbObject = $Kernel::OM->Get("Kernel::System::DB");
my $SQL = "SELECT type, user, queue from vw_user_queues order by user,queue, type";
# get queues
$dbObject->Prepare(
SQL => $SQL,
Bind => [ ]
);
my $queues = "";
my $queuesPath = "";
my $lastAgent = "";
my $lastQueue = "";
my $lastType = "";
my $queue = "";
my $type = "";
my $agent = "";
# for each user/queue
while ( my @row = $dbObject->FetchrowArray() ) {
# current line data
$type = $row[0];
$agent = $row[1];
$queue = $row[2];
# if agent changed from last row (or is first line)
if ($agent ne $lastAgent) {
if ($lastAgent ne "") {
# if agent changed, save the previous agent data and reset the variables
$result{$lastAgent}{"Manage"} = $queues;
$result{$lastAgent}{"Path"} = $queuesPath;
$queues = "";
$queuesPath = "";
$lastQueue = "";
$lastType = "";
}
}
# if the same queue appears in manage and path, ignore the path clause
if (($lastQueue ne "") and ($type eq $lastType) and (index($queue, $lastQueue . "::") != -1)) {
next;
} elsif (($type eq "Path") and ($lastQueue eq $queue)) {
} elsif ($type eq "Manage") {
if ($lastQueue ne "") {
$queues = $queues . "<BR/>";
}
$queues = $queues . $queue;
} elsif ($type eq "Path") {
if ($lastQueue ne "") {
$queuesPath = $queuesPath . "<BR/>";
}
$queuesPath = $queuesPath . $queue;
}
# data for next loop
$lastType = $type;
$lastQueue = $queue;
$lastAgent = $agent;
}
if (($queues ne "") or ($queuesPath ne "")) {
$result{$agent}{"Manage"} = $queues;
$result{$agent}{"Path"} = $queuesPath;
}
return %result;
}
1;