This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » EzMatrix Attribute
expandshrink

EzMatrix Attribute

EzMatrix Attribute

Wednesday 20 February 2013 5:07:47 pm - 5 replies

Hi everyone,

I have a custom class with an attribute matrix in it. I'm trying to create a new object of this class in PHP, but I cannot figure out how should I pass the data for the matrix attribute. 

$params = array(

'creator_id'  => '2',                   

'class_identifier' => 'product',                   

'parent_node_id'   => 259,                   

'attributes' => array(

'name' => 'product1',

'color' => 'blue'

//MATRIX DATA?

     )

);

eZContentFunctions::createAndPublishObject($params);

Thank u for your help.

Wednesday 20 February 2013 6:46:57 pm

http://www.ezpedia.org/ez/simple_fromstring_and_tostring_interface_for_attributes happy.gif Emoticon

Thursday 21 February 2013 11:50:34 am

This is a bit of a pain... but if you look in the database for input in a matrix, you'll see an xml blob in the data_text field...

Something like this:

<?xml version="1.0" encoding="utf-8"?>
<ezmatrix><name></name><columns number="2"><column num="0" id="optieidentifier">Optieidentifier</column><column num="1" id="optietext">Optietext</column></columns><rows number="2"/><c>First_option</c><c>this is the option text</c><c>Second_option</c><c>This is the second option text</c></ezmatrix>

You're going to want to recreate that with your options and send that the the datatext field of the attribute, something like this:

$filter1 = $vraagDataMap['filter_1'];
$filter1->setAttribute('data_text','<?xml version="1.0" encoding="utf-8"?><ezmatrix><name></name><columns number="2"><column num="0" id="optieidentifier">Optieidentifier</column><column num="1" id="optietext">Optietext</column></columns><rows number="2"/><c>First_option</c><c>this is the option text</c><c>Second_option</c><c>This is the second option text</c></ezmatrix> ');
$filter1->sync();

Thursday 21 February 2013 3:27:05 pm

Steven, are you saying that the fromString() format won't work?

Thursday 21 February 2013 3:44:43 pm

Nope, not saying that.  Just giving a bare-bones alternative.  Depending on what you're doing it might be better.

Tuesday 22 July 2014 1:34:49 pm

$params = array(

'creator_id'  => '2',                   

'class_identifier' => 'product',                   

'parent_node_id'   => 259,                   

'attributes' => array(

'name' => 'product1',

'color' => 'blue'

     )

);

$object = eZContentFunctions::createAndPublishObject($params);              

//update the attribute directly after the creation of the object

$dateMap = $object->dataMap();

$contentObjectAttribute = $dateMap['your_matrix_attribute_identifieri'];

$matrix = $contentObjectAttribute->attribute( 'content' );

//if your matrix attributes Contains 2 columns in two lines for example

$cells = array('col1_ligne1','col2_ligne1','col1_ligne2','col2_ligne2');

$matrix->Cells = $cells;

$contentObjectAttribute->setAttribute( 'data_text', $matrix->xmlString() );

$matrix->decodeXML( $contentObjectAttribute->attribute( 'data_text' ) );

$contentObjectAttribute->setContent( $matrix );

$contentObjectAttribute->store();

Modified on Tuesday 22 July 2014 1:38:59 pm by mohammed l'arbi jebari

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from