diff --git a/.project b/.project new file mode 100644 index 0000000..7fb6e58 --- /dev/null +++ b/.project @@ -0,0 +1,18 @@ + + + otrs-agents-per-queue + + + otrs + + + + org.epic.perleditor.perlbuilder + + + + + + org.epic.perleditor.perlnature + + diff --git a/CreateOpm.sh b/CreateOpm.sh new file mode 100755 index 0000000..4d3c82e --- /dev/null +++ b/CreateOpm.sh @@ -0,0 +1,5 @@ +#!/bin/bash +LOCAL="$PWD" +cd /opt/otrs/bin +./otrs.PackageManager.pl -a build -p "$LOCAL"/AgentsPerQueue.sopm -o "$LOCAL"/ +cd $LOCAL diff --git a/Kernel/Config/Files/AgentsPerQueue.xml b/Kernel/Config/Files/AgentsPerQueue.xml new file mode 100644 index 0000000..7415bca --- /dev/null +++ b/Kernel/Config/Files/AgentsPerQueue.xml @@ -0,0 +1,28 @@ + + + + + + + FrontendModuleRegistration for AgentsPerQueue module. + Framework + Frontend::Agent::ModuleRegistration + + + Module for publishing agents per queue matrix + Service + + Agents per queue matrix + Agents per queue matrix + Action=AgentsPerQueue + Service + + 8200 + + + + + + + + diff --git a/Kernel/Language/pt_BR_AgentsPerQueue.pm b/Kernel/Language/pt_BR_AgentsPerQueue.pm new file mode 100644 index 0000000..3412865 --- /dev/null +++ b/Kernel/Language/pt_BR_AgentsPerQueue.pm @@ -0,0 +1,29 @@ +# -- +# Kernel/Modules/pt_BR_AgentsPerQueue.pm - frontend module for showing agents per queue matrix +# Translations +# +# Copyright (C) 2014 (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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::Language::pt_BR_AgentsPerQueue; + +use strict; +use warnings; + +sub Data { + my $Self = shift; + + $Self->{Translation}->{'Queues per agent'} = 'Filas por agente'; + $Self->{Translation}->{'Queues'} = 'Filas'; + $Self->{Translation}->{'Paths'} = 'Encaminhamentos'; + $Self->{Translation}->{'Agents per queue matrix'} = 'Agentes por fila'; + + + + + return 1; +} +1; \ No newline at end of file diff --git a/Kernel/Modules/AgentsPerQueue.pm b/Kernel/Modules/AgentsPerQueue.pm new file mode 100644 index 0000000..418a9bc --- /dev/null +++ b/Kernel/Modules/AgentsPerQueue.pm @@ -0,0 +1,146 @@ +# -- +# Kernel/Modules/AgentsPerQueue.pm - frontend module for displaying the agents per queue matrix panel +# Copyright (C) 2014 (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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); +use Data::Dumper; + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # check needed objects + for ( + qw(ParamObject DBObject LayoutObject LogObject ConfigObject) + ) + { + if ( !$Self->{$_} ) { + $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); + } + } + + # needed objects + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + my %Data = (); + + # load data + my %matrix = $Self->GetQueuesPerAgent(); + + # build output + my $Output = + $Self->{LayoutObject}->Header( Title => $Self->{LayoutObject}->{LanguageObject}->Get("Queues per agent") ); + $Output .= $Self->{LayoutObject}->NavigationBar(); + + my $id = 1; + + # include each agent + foreach my $agent ( sort keys %matrix ) { + $Self->{LayoutObject}->Block( + Name => 'QueuesPerAgent', + Data => { ID => $id, Agent => $agent, Queues => $matrix{$agent}{"Manage"}, Paths => $matrix{$agent}{"Path"} }, + ); + $id += 1; + } + + $Output .= $Self->{LayoutObject}->Output( + Data => \%Data, + TemplateFile => 'AgentsPerQueue', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + +} + +sub GetQueuesPerAgent { + my ( $Self, %Param ) = @_; + my %result = (); + + my $SQL = "SELECT type, user, queue from vw_user_queues order by user,queue, type"; + + # get queues + $Self->{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 = $Self->{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 = ""; + } + } else { + # same agent, add line break to the last queue type + if ($lastType eq "Manage") { + $queues = $queues . "
" + } else { + $queuesPath = $queuesPath . "
" + } + } + + # if the same queue appears in manage and path, ignore the path clause + if (($type eq "Path") and ($lastQueue eq $queue)) { + + } elsif ($type eq "Manage") { + $queues = $queues . $queue; + } elsif ($type eq "Path") { + $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; + } + + print STDERR Dumper(%result); + + return %result; +} + +1; diff --git a/Kernel/Output/HTML/Standard/AgentsPerQueue.dtl b/Kernel/Output/HTML/Standard/AgentsPerQueue.dtl new file mode 100644 index 0000000..86e2159 --- /dev/null +++ b/Kernel/Output/HTML/Standard/AgentsPerQueue.dtl @@ -0,0 +1,35 @@ +# -- +# ResponsibilityMatrix.dtl - provides HTML for ResponsibilityMatrix +# Copyright (C) 2014 Rodrigo Gonçalves (rodrigo.g@ufsc.br) +# +# 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. +# -- +# Autor: Rodrigo Gonçalves +# Data.: 04/08/2014 - versão inicial +# + +

$Text{"Queues per agent"}

+ + + + + + + + + + + + + + + + + +
$Text{"ID"}$Text{"Agent"}$Text{"Paths"}$Text{"Queues"}
$Data{"ID"}$Data{"Agent"} +
$Data{"Paths"}
+
+
$Data{"Queues"}
+
\ No newline at end of file diff --git a/unit_test.sh b/unit_test.sh new file mode 100755 index 0000000..a9a8bdd --- /dev/null +++ b/unit_test.sh @@ -0,0 +1,2 @@ +#!/bin/sh +#Nothing to do for now.... /opt/otrs/bin/otrs.UnitTest.pl -n Responsibility -- libgit2 0.21.2