Storing content in an ezselection attribute

Storing content in an ezselection attribute

Friday 02 September 2005 2:43:11 am - 6 replies

Author Message

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

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.