# -- # Kernel/Modules/QueueService.pm - frontend module # Copyright (C) (2014) (Rodrigo Gonçalves) (rodrigo.g@ufsc.br) # -- # $Id: writing-otrs-application.xml,v 1.1 2010/08/13 08:59:28 mg Exp $ # -- # 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: Carlos Rebelato # Data.: 19/02/2014 - Versão inicial # package Kernel::Modules::QueueService; use strict; use warnings; use Data::Dumper; require Kernel::System::QueueService; require Kernel::System::Service; require Kernel::System::Queue; sub new { my ( $Type, %Param ) = @_; # allocate new hash for object my $Self = {%Param}; bless( $Self, $Type ); # check needed objects for ( qw(ParamObject DBObject TicketObject LayoutObject LogObject QueueObject ConfigObject EncodeObject MainObject) ) { if ( !$Self->{$_} ) { $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); } } # create needed objects $Self->{QueueServiceObject} = Kernel::System::QueueService->new(%Param); $Self->{ServiceObject} = Kernel::System::Service->new(%Param); return $Self; } sub Run { my ( $Self, %Param ) = @_; my $SubAction = $Self->{ParamObject}->GetParam( Param => "Subaction" ); if ( $SubAction eq "ServiceEdit" ) { return $Self->ShowChangeService( ID => $Self->{ParamObject}->GetParam( Param => "ID" ) ); } elsif ( $SubAction eq "QueueEdit" ) { return $Self->ShowChangeQueue( ID => $Self->{ParamObject}->GetParam( Param => "ID" ) ); } elsif ( $SubAction eq "ChangeService" ) { $Self->ChangeService(); return $Self->ShowOverview(); } elsif ( $SubAction eq "ChangeQueue" ) { $Self->ChangeQueue(); return $Self->ShowOverview(); } else { return $Self->ShowOverview(); } } sub ShowOverview() { my ( $Self, %Param ) = @_; my %Data = (); my %Queues = $Self->{QueueObject}->QueueList( Valid => 1 ); my %Services = $Self->{ServiceObject}->ServiceList( UserID => 1 ); foreach my $service ( sort { uc( $Services{$a} ) cmp uc( $Services{$b} ) } keys %Services ) { $Self->{LayoutObject}->Block( Name => 'ListService', Data => { ServiceID => $service, ServiceName => $Services{$service}, } ); } foreach my $queue ( sort { uc( $Queues{$a} ) cmp uc( $Queues{$b} ) } keys %Queues ) { $Self->{LayoutObject}->Block( Name => 'ListQueue', Data => { QueueID => $queue, QueueName => $Queues{$queue}, } ); } my $Output = $Self->{LayoutObject}->Header( Title => $Self->{LayoutObject}->{LanguageObject}->Get("Services per queue") ); $Output .= $Self->{LayoutObject}->NavigationBar(); $Output .= $Self->{LayoutObject}->Output( Data => \%Data, TemplateFile => 'QueueService' ); $Output .= $Self->{LayoutObject}->Footer(); return $Output; } sub ShowChangeService() { my ( $Self, %Param ) = @_; my %Data = (); my %Service = $Self->{ServiceObject}->ServiceGet( ServiceID => $Param{ID}, UserID => 1 ); my %QueuesService = $Self->{QueueServiceObject}->GetQueueList( ServiceID => $Param{ID} ); my %Queues = $Self->{QueueObject}->QueueList( Valid => 1 ); $Data{Type} = "Queue"; $Data{Filter} = "Service"; $Data{VisibleNeType} = "Service"; $Data{Name} = $Service{Name}; $Data{ID} = $Service{ServiceID}; $Self->{LayoutObject}->Block( Name => 'ChangeHeader', Data => \%Data ); foreach my $queue ( sort { uc( $Queues{$a} ) cmp uc( $Queues{$b} ) } keys %Queues ) { $Self->{LayoutObject}->Block( Name => 'ChangeRow', Data => { Type => "Queue", ID => $queue, Name => $Queues{$queue}, Selected => ( $QueuesService{$queue} ? 'checked="checked"' : '' ) } ); } my $Output = $Self->{LayoutObject}->Header( Title => $Self->{LayoutObject}->{LanguageObject}->Get("Services per queue") ); $Output .= $Self->{LayoutObject}->NavigationBar(); $Output .= $Self->{LayoutObject}->Output( Data => \%Data, TemplateFile => 'QueueServiceChange' ); $Output .= $Self->{LayoutObject}->Footer(); return $Output; } sub ShowChangeQueue() { my ( $Self, %Param ) = @_; my %Data = (); my %Queue = $Self->{QueueObject}->QueueGet( ID => $Param{ID} ); my %ServicesQueue = $Self->{QueueServiceObject}->GetServiceList( QueueID => $Param{ID} ); my %Services = $Self->{ServiceObject}->ServiceList( UserID => 1 ); $Data{Type} = "Service"; $Data{Filter} = "Queue"; $Data{VisibleNeType} = "Queue"; $Data{Name} = $Queue{Name}; $Data{ID} = $Queue{QueueID}; $Self->{LayoutObject}->Block( Name => 'ChangeHeader', Data => \%Data ); foreach my $service ( sort { uc( $Services{$a} ) cmp uc( $Services{$b} ) } keys %Services ) { $Self->{LayoutObject}->Block( Name => 'ChangeRow', Data => { Type => "Service", ID => $service, Name => $Services{$service}, Selected => ( $ServicesQueue{$service} ? 'checked="checked"' : '' ) } ); } my $Output = $Self->{LayoutObject}->Header( Title => $Self->{LayoutObject}->{LanguageObject}->Get("Services per queue") ); $Output .= $Self->{LayoutObject}->NavigationBar(); $Output .= $Self->{LayoutObject}->Output( Data => \%Data, TemplateFile => 'QueueServiceChange' ); $Output .= $Self->{LayoutObject}->Footer(); return $Output; } sub ChangeService() { my ( $Self, %Param ) = @_; my @queueIDs = $Self->{ParamObject}->GetArray( Param => 'Queue' ); my $id = $Self->{ParamObject}->GetParam( Param => 'ID' ); $Self->{QueueServiceObject}->SetServiceQueues(ServiceID => $id, Queues => \@queueIDs); } sub ChangeQueue() { my ( $Self, %Param ) = @_; my @serviceIDs = $Self->{ParamObject}->GetArray( Param => 'Service' ); my $id = $Self->{ParamObject}->GetParam( Param => 'ID' ); $Self->{QueueServiceObject}->SetQueueServices(QueueID => $id, Services => \@serviceIDs); }