Forums / Developer / Storing content in an ezselection attribute

Storing content in an ezselection attribute

Author Message

Roy Bøhmer

Friday 02 September 2005 2:43:11 am

Hi!
After reading a lot of code in ezcontentobject.php, ezcontentobjectattribute.php, ezselectiontype.php etc. I still can't figure out how to store content in an object attribute of datatype ezselection.

The attribute is set up to only store one selection (so I later can filter on it in the template).

I've tried with

$attribs =& $contentObject->contentObjectAttributes();
for($k=0;$k<count($attribs);$k++)
{
   switch($attribs[$k]->attribute("contentclass_attribute_identifier"))
   {
      case 'county':
      $attribs[$k]->setAttribute('data_int', $county);
      attribs[$k]->store();
      break;
    }
}

The $county variable conatins an integer, refering to the index in the selection datatype.
The data_int-value is stored, but I think the problem is that the value should be stored somewhere else.
But where and how?

Kristof Coomans

Friday 02 September 2005 3:30:59 am

eZSelection stores it's values in data_text, to support multiple selections.

For multiple selections, the different values will be seperated by -.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Roy Bøhmer

Friday 02 September 2005 3:36:34 am

Thank you, Kristof!
Works like a charm

Roy

Laurent DIBON

Wednesday 05 April 2006 12:24:32 pm

I try to import user with ezselection attributes. If we suppose that we have an attribute called 'genre' wich can take 'male' or 'female' as option values (only one can be selected), what will be ecactly the code to store this attribute in php ?

is it :

switch($attribs[$k]->attribute("contentclass_attribute_identifier"))
{
case 'county':
$attribs[$k]->setAttribute('data_int', $county);
$attribs[$k]->setAttribute('data_text', 'yes');
attribs[$k]->store();
break;
}

Roy Bøhmer

Wednesday 05 April 2006 12:50:38 pm

The value in 'data_text' should be an integer. If you have to options it would likely be 0 or 1. Whitch is 'male' and which is 'female' is controlled by you in the (content)classdefenition.

$attribs =& $contentObject->contentObjectAttributes();  

for($k=0;$k<count($attribs);$k++)  
{    
   switch($attribs[$k]->attribute("contentclass_attribute_identifier"))   
   {      
         case 'genre':       
            $attribs[$k]->setAttribute('data_text', 0|1);       
            $attribs[$k]->store();       
         break;     
    }  
} 

- Roy

Laurent DIBON

Wednesday 05 April 2006 11:40:28 pm

Thank you very much for your answer,

It was'nt clear for me that I had to put an integer value whith data_text.
Now I'm right. It works fine.

Kristof Coomans

Thursday 06 April 2006 1:42:45 am

This has been answered already, but Laurent mailed me about this subject and I've send him a mail. So I'll post my reply here too, just as a future reference:

eZSelection stores it's value in data_text. But it stores the internal id of the option, not the option's name as many people think. So you'll have to lookup the id corresponding to your option name in the attribute's class attribute's content.

$selectedGenre = 'female';

$classContent = $attribs[$k]->attribute( 'class_content' );
$optionId = false;
foreach ( $classContent['options'] as $option )
{
   if ( $option['name'] == $selectedGenre )
   {
         $optionId = $option['id'];
         break;
   }
}

if ( $optionId )
{
    $attribs[$k]->setAttribute('data_text', $optionId);
    $attribs[$k]->store();
} 

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

eZ debug

Timing: Jan 18 2025 11:16:42
Script start
Timing: Jan 18 2025 11:16:42
Module start 'content'
Timing: Jan 18 2025 11:16:44
Module end 'content'
Timing: Jan 18 2025 11:16:44
Script end

Main resources:

Total runtime2.1203 sec
Peak memory usage4,096.0000 KB
Database Queries208

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0074 587.8438180.8125
Module start 'content' 0.00741.9335 768.6563625.8203
Module end 'content' 1.94090.1793 1,394.4766341.0547
Script end 2.1202  1,735.5313 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.1971210.0002
Check MTime0.00160.0741210.0001
Mysql Total
Database connection0.00090.044010.0009
Mysqli_queries2.034895.96512080.0098
Looping result0.00230.10992060.0000
Template Total2.078098.021.0390
Template load0.00210.097320.0010
Template processing2.075997.906521.0380
Template load and register function0.00030.013510.0003
states
state_id_array0.00200.096110.0020
state_identifier_array0.00160.075420.0008
Override
Cache load0.00180.0854430.0000
Sytem overhead
Fetch class attribute can translate value0.00260.120940.0006
Fetch class attribute name0.00130.059780.0002
XML
Image XML parsing0.00100.046640.0002
class_abstraction
Instantiating content class attribute0.00000.000990.0000
General
dbfile0.00330.1560270.0001
String conversion0.00000.000330.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
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 30
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs