Getting Data from Session !!

English! place to talk about development, programming and coding
Post Reply
rapidboy
Znuny newbie
Posts: 25
Joined: 23 Apr 2013, 13:47
Znuny Version: 3.2.1
Real Name: John Almound
Company: Student

Getting Data from Session !!

Post by rapidboy »

I'm trying to get UserID in Array from Session but failed.... Can someone plz tell me the Right way of getting data in Array ..

Code: Select all

my $Count=0;
my @array;

for my $SessionID (@List) {
            my $List = '';
            my %Data = $Self->{SessionObject}->GetSessionIDData( SessionID => $SessionID );
            $MetaData{"$Data{UserType}Session"}++;
            if ( !$MetaData{"$Data{UserLogin}"} ) {
                $MetaData{"$Data{UserType}SessionUniq"}++;
                $MetaData{"$Data{UserLogin}"} = 1;
            }

            $array[$Count1] = $MetaData{"$Data{UserID}"};
            $Count1++;
            
            $Data{UserType} = 'Agent' if ( $Data{UserType} ne 'Customer' );
            # create blocks
            $Self->{LayoutObject}->Block(
                Name => 'Session',
                Data => {
                    SessionID     => $SessionID,
                    UserFirstname => $Data{UserFirstname},
                    UserLastname  => $Data{UserLastname},
                    UserType      => $Data{UserType},
                    UserID        => $Data{UserID},
                    
                   },
              
            );           


        }
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Getting Data from Session !!

Post by crythias »

rapidboy wrote:get UserID in Array from Session but failed
$Data{UserID} holds the value of UserID for given session, assuming everything else is correct.

What level of failure are you encountering? How would random viewer of your question understand what "it doesn't work" means and how to fix it?

I assume you want to push a list of UserIDs into an array on MetaData...

$MetaData{key} = $Data{UserID};

The right way of putting data in an array is the above. That answers your question.
or, to be more succinct...

$MetaData{$Count} = $Data{UserID};

(Assuming $Count increments something reasonable ... otherwise make your own increment)
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Getting Data from Session !!

Post by reneeb »

@crythias: you are using a hash...

@rapidboy: it should be

Code: Select all

push @array, $Data{UserID}
. Please learn the Perl basics first. URLs of perl tutorials can be found here: http://perl-tutorial.org/
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Getting Data from Session !!

Post by crythias »

@reneeb Thanks. I didn't see anything in the code that indicated an array being tried to be used so I was adjusting for what was presented. You are, of course, correct.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
rapidboy
Znuny newbie
Posts: 25
Joined: 23 Apr 2013, 13:47
Znuny Version: 3.2.1
Real Name: John Almound
Company: Student

Re: Getting Data from Session !!

Post by rapidboy »

thnxs Reneeb :) u r genius.
rapidboy
Znuny newbie
Posts: 25
Joined: 23 Apr 2013, 13:47
Znuny Version: 3.2.1
Real Name: John Almound
Company: Student

Re: Getting Data from Session !!

Post by rapidboy »

How can i use Variable instead of value as a index of Array.
use that one from internet but not really helpful, value as a index works but a variable not :?

$array[$random_number]

Code: Select all

 my $arraySize = @array;
        $arraySize = scalar (@array);
        $arraySize = $#array;

        my $range = $arraySize;
        my $random_number;
        $random_number = int(rand($range));
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Getting Data from Session !!

Post by reneeb »

Code: Select all

my $index = 3;
my @array = (1..10);
print $array[$index];

BTW: Please do not send private messages with such general questions. I'm not always online and others can help, too.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Post Reply