Getting selected Enum elements in php.

Getting selected Enum elements in php.

Thursday 21 August 2003 2:07:03 pm - 4 replies

Modified on Thursday 21 August 2003 2:15:45 pm by Dave Dykshoorn

Author Message

Dave Dykshoorn

Thursday 21 August 2003 3:01:56 pm

I figured it out.

$user = &eZUser::currentUser();
$userObject = &$user->attribute( "contentobject" );
$datamap = &$userObject->attribute ( "data_map" );

foreach ($datamap as $key => $value)
{
if ($key == 'my_enum')
{
$enumObjectContent = $value->attribute('content');
$SelectedEnums = $enumObjectContent->ObjectEnumerations;
}
}

$SelectedEnums contains all of the enums that were selected.

print_r is a personal friend of mine. :)

Jerry Jalava

Thursday 21 August 2003 5:44:27 pm

Hi Dave,

Thanks for sharing this important piece of information. :)
I would just like to ask how do you use the $SelectedEnums variable?
Do you somehow parse the EnumValue to a variable?
How could this be done?

Thanks,
Jerry

Jerry Jalava

Thursday 21 August 2003 5:54:49 pm

Figured it out...

I used this kind of code:

$Max = count( $SelectedEnums );
$Max = $Max-1;
foreach ($SelectedEnums as $Ekey => $Evalue)
{
if ($Ekey <= $Max)
{
$EnumArray = get_object_vars( $Evalue );
$EnumValue[$Ekey] = $EnumArray["EnumValue"];
}
}

Just if someone needs same kind of implementation...

Regards,
Jerry

Dave Dykshoorn

Friday 22 August 2003 10:35:20 am

I'm glad it was useful. This is how I used $selectedEnums

I needed to figure out the values that were selected (EnumValue) and then put them into a comma seperated list. Here's how I did it, it's pretty basic.

$myList = "";
foreach( $SelectedEnums as $SelectedEnum )
{
if ($myList == "" )
$myList = $SelectedEnum->EnumValue;
else
$myList= $myList . ',' . $SelectedEnum->EnumValue;
}

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.