# -- # Kernel/Modules/AgentsPerQueue.pm - frontend module for displaying the agents per queue matrix panel # # Copyright (C) 2014 SeTIC - UFSC - http://setic.ufsc.br/ # Version 01/15/2015 - Adjustments for OTRS 4 # # -- # 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"); # load data my %matrix = $Self->GetQueuesPerAgent(); # build output my $Output = $layoutObject->Header( Title => $layoutObject->{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 = ""; } } 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; } return %result; } 1;