"Fossies" - the Fresh Open Source Software Archive

Member "otrs-5.0.40/Kernel/System/ProcessManagement/ActivityDialog.pm" (12 Dec 2019, 8263 Bytes) of package /linux/www/otrs-5.0.40.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ActivityDialog.pm" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: rel-6_0_25_vs_rel-6_0_26.

    1 # --
    2 # Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
    3 # --
    4 # This software comes with ABSOLUTELY NO WARRANTY. For details, see
    5 # the enclosed file COPYING for license information (GPL). If you
    6 # did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
    7 # --
    8 
    9 package Kernel::System::ProcessManagement::ActivityDialog;
   10 
   11 use strict;
   12 use warnings;
   13 
   14 use Kernel::System::VariableCheck qw(:all);
   15 
   16 our @ObjectDependencies = (
   17     'Kernel::Config',
   18     'Kernel::System::Log',
   19 );
   20 
   21 =head1 NAME
   22 
   23 Kernel::System::ProcessManagement::ActivityDialog - activity dialog lib
   24 
   25 =head1 SYNOPSIS
   26 
   27 All Process Management Activity Dialog functions.
   28 
   29 =head1 PUBLIC INTERFACE
   30 
   31 =over 4
   32 
   33 =cut
   34 
   35 =item new()
   36 
   37 create an object. Do not use it directly, instead use:
   38 
   39     use Kernel::System::ObjectManager;
   40     local $Kernel::OM = Kernel::System::ObjectManager->new();
   41     my $ActivityDialogObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::ActivityDialog');
   42 
   43 =cut
   44 
   45 sub new {
   46     my ( $Type, %Param ) = @_;
   47 
   48     # allocate new hash for object
   49     my $Self = {};
   50     bless( $Self, $Type );
   51 
   52     return $Self;
   53 }
   54 
   55 =item ActivityDialogGet()
   56 
   57     Get activity dialog info
   58 
   59     my $ActivityDialog = $ActivityDialogObject->ActivityDialogGet(
   60         ActivityDialogEntityID => 'AD1',
   61         Interface              => ['AgentInterface'],   # ['AgentInterface'] or ['CustomerInterface'] or ['AgentInterface', 'CustomerInterface'] or 'all'
   62         Silent                 => 1,    # 1 or 0, default 0, if set to 1, will not log errors about not matching interfaces
   63     );
   64 
   65     Returns:
   66 
   67     $ActivityDialog = {
   68         Name             => 'UnitTestActivity',
   69         Interface        => 'CustomerInterface',   # 'AgentInterface', 'CustomerInterface', ['AgentInterface'] or ['CustomerInterface'] or ['AgentInterface', 'CustomerInterface']
   70         DescriptionShort => 'AD1 Process Short',
   71         DescriptionLong  => 'AD1 Process Long description',
   72         CreateTime       => '07-02-2012 13:37:00',
   73         CreateBy         => '2',
   74         ChangeTime       => '08-02-2012 13:37:00',
   75         ChangeBy         => '3',
   76         Fields => {
   77             DynamicField_Make => {
   78                 Display          => 2,
   79                 DescriptionLong  => 'Make Long',
   80                 DescriptionShort => 'Make Short',
   81             },
   82             DynamicField_VWModel => {
   83                 Display          => 2,
   84                 DescriptionLong  => 'VWModel Long',
   85                 DescriptionShort => 'VWModel Short',
   86             },
   87             DynamicField_PeugeotModel => {
   88                 Display          => 0,
   89                 DescriptionLong  => 'PeugeotModel Long',
   90                 DescriptionShort => 'PeugeotModel Short',
   91             },
   92             StateID => {
   93                Display          => 1,
   94                DescriptionLong  => 'StateID Long',
   95                DescriptionShort => 'StateID Short',
   96             },
   97         },
   98         FieldOrder => [
   99             'StateID',
  100             'DynamicField_Make',
  101             'DynamicField_VWModelModel',
  102             'DynamicField_PeugeotModel'
  103         ],
  104         SubmitAdviceText => 'NOTE: If you submit the form ...',
  105         SubmitButtonText => 'Make an inquiry',
  106     };
  107 
  108 =cut
  109 
  110 sub ActivityDialogGet {
  111     my ( $Self, %Param ) = @_;
  112 
  113     for my $Needed (qw(ActivityDialogEntityID Interface)) {
  114         if ( !defined $Param{$Needed} ) {
  115             $Kernel::OM->Get('Kernel::System::Log')->Log(
  116                 Priority => 'error',
  117                 Message  => "Need $Needed!"
  118             );
  119             return;
  120         }
  121     }
  122 
  123     if ( $Param{Interface} ne 'all' && ref $Param{Interface} ne 'ARRAY' ) {
  124         $Param{Interface} = [ $Param{Interface} ];
  125     }
  126 
  127     my $ActivityDialog = $Kernel::OM->Get('Kernel::Config')->Get('Process::ActivityDialog');
  128 
  129     if ( !IsHashRefWithData($ActivityDialog) ) {
  130         $Kernel::OM->Get('Kernel::System::Log')->Log(
  131             Priority => 'error',
  132             Message  => 'Need ActivityDialog config!'
  133         );
  134         return;
  135     }
  136 
  137     if ( !IsHashRefWithData( $ActivityDialog->{ $Param{ActivityDialogEntityID} } ) ) {
  138         $Kernel::OM->Get('Kernel::System::Log')->Log(
  139             Priority => 'error',
  140             Message  => "No Data for ActivityDialog '$Param{ActivityDialogEntityID}' found!"
  141         );
  142         return;
  143     }
  144 
  145     if (
  146         $Param{Interface} ne 'all'
  147         && !IsArrayRefWithData(
  148             $ActivityDialog->{ $Param{ActivityDialogEntityID} }->{Interface}
  149         )
  150         )
  151     {
  152         $Kernel::OM->Get('Kernel::System::Log')->Log(
  153             Priority => 'error',
  154             Message  => "No Interface for ActivityDialog '$Param{ActivityDialogEntityID}' found!"
  155         );
  156     }
  157 
  158     if ( $Param{Interface} ne 'all' ) {
  159         my $Success;
  160         INTERFACE:
  161         for my $CurrentInterface ( @{ $Param{Interface} } ) {
  162             if (
  163                 grep { $CurrentInterface eq $_ }
  164                 @{ $ActivityDialog->{ $Param{ActivityDialogEntityID} }->{Interface} }
  165                 )
  166             {
  167                 $Success = 1;
  168                 last INTERFACE;
  169             }
  170         }
  171 
  172         if ( !$Success ) {
  173             if ( !$Param{Silent} ) {
  174                 $Kernel::OM->Get('Kernel::System::Log')->Log(
  175                     Priority => 'error',
  176                     Message =>
  177                         "Not permitted Interface(s) '"
  178                         . join( '\', \'', @{ $Param{Interface} } )
  179                         . "' for ActivityDialog '$Param{ActivityDialogEntityID}'!"
  180                 );
  181             }
  182             return;
  183         }
  184     }
  185 
  186     return $ActivityDialog->{ $Param{ActivityDialogEntityID} };
  187 }
  188 
  189 =item ActivityDialogCompletedCheck()
  190 
  191     Checks if an activity dialog is completed
  192 
  193     my $Completed = $ActivityDialogObject->ActivityDialogCompletedCheck(
  194         ActivityDialogEntityID => 'AD1',
  195         Data                   => {
  196             Queue         => 'Raw',
  197             DynamicField1 => 'Value',
  198             Subject       => 'Testsubject',
  199             # ...
  200         },
  201     );
  202 
  203     Returns:
  204 
  205     $Completed = 1; # 0
  206 
  207 =cut
  208 
  209 sub ActivityDialogCompletedCheck {
  210     my ( $Self, %Param ) = @_;
  211 
  212     for my $Needed (qw(ActivityDialogEntityID Data)) {
  213         if ( !defined $Param{$Needed} ) {
  214             $Kernel::OM->Get('Kernel::System::Log')->Log(
  215                 Priority => 'error',
  216                 Message  => "Need $Needed!"
  217             );
  218             return;
  219         }
  220     }
  221 
  222     if ( !IsHashRefWithData( $Param{Data} ) ) {
  223         $Kernel::OM->Get('Kernel::System::Log')->Log(
  224             Priority => 'error',
  225             Message  => "Data has no values!",
  226         );
  227         return;
  228     }
  229 
  230     my $ActivityDialog = $Self->ActivityDialogGet(
  231         ActivityDialogEntityID => $Param{ActivityDialogEntityID},
  232         Interface              => 'all',
  233     );
  234     if ( !$ActivityDialog ) {
  235         $Kernel::OM->Get('Kernel::System::Log')->Log(
  236             Priority => 'error',
  237             Message  => "Can't get ActivtyDialog '$Param{ActivityDialogEntityID}'!",
  238         );
  239         return;
  240     }
  241 
  242     if ( !$ActivityDialog->{Fields} || ref $ActivityDialog->{Fields} ne 'HASH' ) {
  243         $Kernel::OM->Get('Kernel::System::Log')->Log(
  244             Priority => 'error',
  245             Message  => "Can't get fields for ActivtyDialog '$Param{ActivityDialogEntityID}'!",
  246         );
  247         return;
  248     }
  249 
  250     # loop over the fields of the config activity dialog to check if the required fields are filled
  251     FIELDLOOP:
  252     for my $Field ( sort keys %{ $ActivityDialog->{Fields} } ) {
  253 
  254         # Checks if Field was invisible
  255         next FIELDLOOP if ( !$ActivityDialog->{Fields}{$Field}{Display} );
  256 
  257         # Checks if Field was visible but not required
  258         next FIELDLOOP if ( $ActivityDialog->{Fields}{$Field}{Display} == 1 );
  259 
  260         # checks if $Data->{Field} is defined and not an empty string
  261         return if ( !IsStringWithData( $Param{Data}->{$Field} ) );
  262     }
  263 
  264     return 1;
  265 }
  266 1;
  267 
  268 =back
  269 
  270 =head1 TERMS AND CONDITIONS
  271 
  272 This software is part of the OTRS project (L<https://otrs.org/>).
  273 
  274 This software comes with ABSOLUTELY NO WARRANTY. For details, see
  275 the enclosed file COPYING for license information (GPL). If you
  276 did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
  277 
  278 =cut