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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
# --
# Copyright (C) 2001-2021 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::ProcessManagement::ActivityDialog;
use strict;
use warnings;
use Kernel::System::VariableCheck qw(:all);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Log',
);
=head1 NAME
Kernel::System::ProcessManagement::ActivityDialog - activity dialog lib
=head1 DESCRIPTION
All Process Management Activity Dialog functions.
=head1 PUBLIC INTERFACE
=head2 new()
Don't use the constructor directly, use the ObjectManager instead:
my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::ActivityDialog');
=cut
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
=head2 ActivityDialogGet()
Get activity dialog info
my $ActivityDialog = $ActivityDialogObject->ActivityDialogGet(
ActivityDialogEntityID => 'AD1',
Interface => ['AgentInterface'], # ['AgentInterface'] or ['CustomerInterface'] or ['AgentInterface', 'CustomerInterface'] or 'all'
Silent => 1, # 1 or 0, default 0, if set to 1, will not log errors about not matching interfaces
);
Returns:
$ActivityDialog = {
Name => 'UnitTestActivity',
Interface => 'CustomerInterface', # 'AgentInterface', 'CustomerInterface', ['AgentInterface'] or ['CustomerInterface'] or ['AgentInterface', 'CustomerInterface']
DescriptionShort => 'AD1 Process Short',
DescriptionLong => 'AD1 Process Long description',
CreateTime => '07-02-2012 13:37:00',
CreateBy => '2',
ChangeTime => '08-02-2012 13:37:00',
ChangeBy => '3',
Fields => {
DynamicField_Make => {
Display => 2,
DescriptionLong => 'Make Long',
DescriptionShort => 'Make Short',
},
DynamicField_VWModel => {
Display => 2,
DescriptionLong => 'VWModel Long',
DescriptionShort => 'VWModel Short',
},
DynamicField_PeugeotModel => {
Display => 0,
DescriptionLong => 'PeugeotModel Long',
DescriptionShort => 'PeugeotModel Short',
},
StateID => {
Display => 1,
DescriptionLong => 'StateID Long',
DescriptionShort => 'StateID Short',
},
},
FieldOrder => [
'StateID',
'DynamicField_Make',
'DynamicField_VWModelModel',
'DynamicField_PeugeotModel'
],
SubmitAdviceText => 'NOTE: If you submit the form ...',
SubmitButtonText => 'Make an inquiry',
};
=cut
sub ActivityDialogGet {
my ( $Self, %Param ) = @_;
for my $Needed (qw(ActivityDialogEntityID Interface)) {
if ( !defined $Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!"
);
return;
}
}
if ( $Param{Interface} ne 'all' && ref $Param{Interface} ne 'ARRAY' ) {
$Param{Interface} = [ $Param{Interface} ];
}
my $ActivityDialog = $Kernel::OM->Get('Kernel::Config')->Get('Process::ActivityDialog');
if ( !IsHashRefWithData($ActivityDialog) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need ActivityDialog config!'
);
return;
}
if ( !IsHashRefWithData( $ActivityDialog->{ $Param{ActivityDialogEntityID} } ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "No Data for ActivityDialog '$Param{ActivityDialogEntityID}' found!"
);
return;
}
if (
$Param{Interface} ne 'all'
&& !IsArrayRefWithData(
$ActivityDialog->{ $Param{ActivityDialogEntityID} }->{Interface}
)
)
{
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "No Interface for ActivityDialog '$Param{ActivityDialogEntityID}' found!"
);
}
if ( $Param{Interface} ne 'all' ) {
my $Success;
INTERFACE:
for my $CurrentInterface ( @{ $Param{Interface} } ) {
if (
grep { $CurrentInterface eq $_ }
@{ $ActivityDialog->{ $Param{ActivityDialogEntityID} }->{Interface} }
)
{
$Success = 1;
last INTERFACE;
}
}
if ( !$Success ) {
if ( !$Param{Silent} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message =>
"Not permitted Interface(s) '"
. join( '\', \'', @{ $Param{Interface} } )
. "' for ActivityDialog '$Param{ActivityDialogEntityID}'!"
);
}
return;
}
}
return $ActivityDialog->{ $Param{ActivityDialogEntityID} };
}
=head2 ActivityDialogCompletedCheck()
Checks if an activity dialog is completed
my $Completed = $ActivityDialogObject->ActivityDialogCompletedCheck(
ActivityDialogEntityID => 'AD1',
Data => {
Queue => 'Raw',
DynamicField1 => 'Value',
Subject => 'Testsubject',
# ...
},
);
Returns:
$Completed = 1; # 0
=cut
sub ActivityDialogCompletedCheck {
my ( $Self, %Param ) = @_;
for my $Needed (qw(ActivityDialogEntityID Data)) {
if ( !defined $Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!"
);
return;
}
}
if ( !IsHashRefWithData( $Param{Data} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Data has no values!",
);
return;
}
my $ActivityDialog = $Self->ActivityDialogGet(
ActivityDialogEntityID => $Param{ActivityDialogEntityID},
Interface => 'all',
);
if ( !$ActivityDialog ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Can't get ActivtyDialog '$Param{ActivityDialogEntityID}'!",
);
return;
}
if ( !$ActivityDialog->{Fields} || ref $ActivityDialog->{Fields} ne 'HASH' ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Can't get fields for ActivtyDialog '$Param{ActivityDialogEntityID}'!",
);
return;
}
# loop over the fields of the config activity dialog to check if the required fields are filled
FIELDLOOP:
for my $Field ( sort keys %{ $ActivityDialog->{Fields} } ) {
# Checks if Field was invisible
next FIELDLOOP if ( !$ActivityDialog->{Fields}->{$Field}->{Display} );
# Checks if Field was visible but not required
next FIELDLOOP if ( $ActivityDialog->{Fields}->{$Field}->{Display} == 1 );
# checks if $Data->{Field} is defined and not an empty string
return if ( !IsStringWithData( $Param{Data}->{$Field} ) );
}
return 1;
}
1;
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<https://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (GPL). If you
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut
|