QueueService.pm
5.83 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# --
# 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);
}