Getting selected Enum elements in php.

Author Message

Dave Dykshoorn

Thursday 21 August 2003 2:07:03 pm

There has to be documentation on this somewhere but I can't find any so here it goes.

I have modified the User class and added an enum attribute to it.
(Multiple choice, option style, 2 elements with values)

Now my question is how can I retrieve the selected elements from the enum for the current user?

I've gotten as far as this:

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

foreach ($datamap as $key => $value)
{
if ($key == 'my_enum')
{
$contentClassAttribute = $value->attribute ( 'contentclass_attribute' );
$contentClassAttributeID = $contentClassAttribute->attribute('id' );
$contentClassAttributeVersion = $contentClassAttribute->attribute('version' );
$array_enumValue =
eZEnumValue::fetchAllElements( $contentClassAttributeID, $contentClassAttributeVersion );
}
}

(adapted from developer/ez_publish_3/documentation/development/importing_attribute_data)
I Know that this doesn't work because fetchAllElements fetches all elements (amazing). Is there a function that fetches selected elements from a Enum? Or am I approaching this all wrong?

I'm stumped, and I'm sure there's an easy way to do this, if there is anyone that could direct me to the appropriate documentation or give me a little guidance I would be most appreciative.

Thanks in advance!

Dave

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;
}

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

eZ debug

Timing: Jan 31 2025 03:43:55
Script start
Timing: Jan 31 2025 03:43:55
Module start 'layout'
Timing: Jan 31 2025 03:43:55
Module start 'content'
Timing: Jan 31 2025 03:43:55
Module end 'content'
Timing: Jan 31 2025 03:43:55
Script end

Main resources:

Total runtime0.0224 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 588.2344151.2109
Module start 'layout' 0.00480.0032 739.4453220.6875
Module start 'content' 0.00800.0127 960.13281,001.6953
Module end 'content' 0.02070.0015 1,961.828133.9922
Script end 0.0222  1,995.8203 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002611.3896140.0002
Check MTime0.00104.5135140.0001
Mysql Total
Database connection0.00073.127410.0007
Mysqli_queries0.002410.847130.0008
Looping result0.00000.044710.0000
Template Total0.00114.810.0011
Template load0.00083.649710.0008
Template processing0.00021.085010.0002
Override
Cache load0.00062.538110.0006
General
dbfile0.00125.392280.0002
String conversion0.00000.023440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs