Forums / Developer / Getting selected Enum elements in php.

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

eZ debug

Timing: Jan 31 2025 01:32:22
Script start
Timing: Jan 31 2025 01:32:22
Module start 'content'
Timing: Jan 31 2025 01:32:22
Module end 'content'
Timing: Jan 31 2025 01:32:23
Script end

Main resources:

Total runtime0.2494 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0078 587.9531370.2891
Module start 'content' 0.00780.0138 958.24221,005.4219
Module end 'content' 0.02170.2277 1,963.66413,896.9922
Script end 0.2493  5,860.6563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00451.8117200.0002
Check MTime0.00140.5418200.0001
Mysql Total
Database connection0.00100.400910.0010
Mysqli_queries0.139956.11051410.0010
Looping result0.00160.64651390.0000
Template Total0.227291.110.2272
Template load0.00080.323610.0008
Template processing0.226390.750710.2263
Override
Cache load0.00060.225710.0006
Sytem overhead
Fetch class attribute can translate value0.00210.858810.0021
XML
Image XML parsing0.00050.211010.0005
General
dbfile0.00512.0388200.0003
String conversion0.00000.002030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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