Helper classes?

Author Message

Kristofer Pettersson

Wednesday 04 January 2006 1:21:33 pm

I just figured out that I need to fetch the ezcontentattributes even though I might have a correct instance of a ezcontentobject.

$attrs = $target_object->contentObjectAttributes();
foreach( $attrs as $attr ) {
  switch( $attr->contentClassAttributeIdentifier() ) {
    case 'first_name': $first_name = $attr->attribute( 'data_text' );
     break;
    case 'last_name': $last_name = $attr->attribute( 'data_text' );
     break;
    case 'approved_by': $approved_by = $attr->attribute( 'data_text' );
     break;
   }
}

This is a really bothersome way to do it, and I wonder if there exist a easier way to automatically stuff the attributes in a much more simple (untyped) structure like an array with the contentClassAttributeIdentifier mapped against relevant value?

Something like this would be nice:
$doc = getDocumentById( $id );
echo "Document title: ".$doc->getAttribute("title");

No meta data unless I request it! :^)

Kristofer Pettersson

Thursday 05 January 2006 5:07:35 am

It seems the above method isn't enough for the ezselection class. How do I load the selected value from the target document?

I've tried the following:

The obvious: $target_document->attribute( 'approved_by' )->content();
The less obvious: $attr->attribute( 'approved_by' )->content();
The bizare: $attr->dataType()->title();

with no success. :-(

Yelitza Jaramillo

Thursday 05 January 2006 7:07:28 am

Hei Kristofer,

To store data in an ezselection datatype
try this link
http://ez.no/community/forum/developer/storing_content_in_an_ezselection_attribute

To retrieve data


$object_data_map = $target_object->attribute( 'data_map' );
// this returns an array

$aproved_by = $object_data_map[ 'aproved_by' ]->content();
//this will return the option number if the datatype is an ezselection

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