<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># --
# Kernel/System/ProcessManagement/Process/State.pm - Process Management DB State backend
# Copyright (C) 2001-2014 OTRS AG, http://otrs.com/
# --
# 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::System::ProcessManagement::DB::Process::State;

use strict;
use warnings;

=head1 NAME

Kernel::System::ProcessManagement::DB::Process::State.pm

=head1 SYNOPSIS

Process Management DB State backend

=head1 PUBLIC INTERFACE

=over 4

=cut

=item new()

create a State object

    use Kernel::Config;
    use Kernel::System::Encode;
    use Kernel::System::Log;
    use Kernel::System::ProcessManagement::DB::Process::State;

    my $ConfigObject = Kernel::Config-&gt;new();
    my $EncodeObject = Kernel::System::Encode-&gt;new(
        ConfigObject =&gt; $ConfigObject,
    );
    my $LogObject = Kernel::System::Log-&gt;new(
        ConfigObject =&gt; $ConfigObject,
        EncodeObject =&gt; $EncodeObject,
    );
    my $StateObject = Kernel::System::ProcessManagement::DB::Process::State-&gt;new(
        ConfigObject        =&gt; $ConfigObject,
        EncodeObject        =&gt; $EncodeObject,
        LogObject           =&gt; $LogObject,
    );

=cut

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    # get needed objects
    for my $Needed (qw(ConfigObject EncodeObject LogObject)) {
        die "Got no $Needed!" if !$Param{$Needed};

        $Self-&gt;{$Needed} = $Param{$Needed};
    }

    # create States list
    $Self-&gt;{StateList} = {
        'S1' =&gt; 'Active',
        'S2' =&gt; 'Inactive',
        'S3' =&gt; 'FadeAway',
    };

    return $Self;
}

=item StateList()

get a State list

    my $List = $StateObject-&gt;StateList(
        UserID =&gt; 123,
    );

    Returns:

    $List = {
        'S1' =&gt; 'Active',
        'S2' =&gt; 'Inactive',
        'S3' =&gt; 'FadeAway',
    }
=cut

sub StateList {
    my ( $Self, %Param ) = @_;

    # check needed
    if ( !$Param{UserID} ) {
        $Self-&gt;{LogObject}-&gt;Log(
            Priority =&gt; 'error',
            Message  =&gt; "Need UserID!"
        );
        return;
    }

    return $Self-&gt;{StateList};
}

=item StateLookup()

get State name or State EntityID

    my $Name = $StateObject-&gt;StateLookup(
        EntityID =&gt; 'S1',
        UserID   =&gt; 123,
    );

    Returns:
    $Name = 'Active';

    my $EntityID = $StateObject-&gt;StateLookup(
        Name     =&gt; 'Active',
        UserID   =&gt; 123,
    );

    Returns:
    $EntityID = 'S1';
=cut

sub StateLookup {
    my ( $Self, %Param ) = @_;

    # check needed
    if ( !$Param{UserID} ) {
        $Self-&gt;{LogObject}-&gt;Log(
            Priority =&gt; 'error',
            Message  =&gt; "Need UserID!"
        );
        return;
    }

    if ( !$Param{EntityID} &amp;&amp; !$Param{Name} ) {
        $Self-&gt;{LogObject}-&gt;Log(
            Priority =&gt; 'error',
            Message  =&gt; "EntityID or Name is required!"
        );
        return;
    }

    my $Result;

    # return state name
    if ( $Param{EntityID} ) {
        $Result = $Self-&gt;{StateList}-&gt;{ $Param{EntityID} };
    }

    # return state entity ID
    else {
        my %ReversedStateList = reverse %{ $Self-&gt;{StateList} };
        $Result = $ReversedStateList{ $Param{Name} }
    }
    return $Result;
}

1;

=back

=head1 TERMS AND CONDITIONS

This software is part of the OTRS project (L&lt;http://otrs.org/&gt;).

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 L&lt;http://www.gnu.org/licenses/agpl.txt&gt;.

=cut
</pre></body></html>