Content object data access

Author Message

Dmytro Tomilovskiy

Friday 26 May 2006 7:57:47 am

Greetings everyone.
I am new to eZ Publish, so my question may sound a bit silly.

I have created a standard workflow event the purpose of which is to extract the data out of the content object and store it in some sort of XML.
This script has to be very generic i.e. nothing is hardcoded. Thus it would be very usefull to get the attributes of the content object is some form of array. And it would be helpfull if the index of an attribute in this array was consistent with the structure of the content class.
Any ideas how it is done?

Thank you for your time.

Łukasz Serwatka

Wednesday 31 May 2006 12:05:43 pm

You can get access to the content objects attributes like:

include_once( 'kernel/classes/ezcontentobject.php' );
$object =& eZContentObject::fetch( 1 );
$contentObjectAttributes =& $object->contentObjectAttributes();

foreach ($contentObjectAttributes as $contentObjectAttribute)
{
	var_dump( $contentObjectAttribute );
}

Check output from var_dump you will find there usefull info.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Dmytro Tomilovskiy

Thursday 01 June 2006 11:10:30 am

Greetings, Lukasz.
Thanks for your reply.

It looks like I did not provide enough information in the original post.

Say I have an article that is being published in eZ Publish. Lets say it contains a few attributes such as "Author", "Date", "Body" etc.
What I need is to get these and build an XML that resembles this particular article. I.e. this XML has to be of the form:

<author> ... </author>
<date> ...</date>
<body>...</body>

...

Such file has to be build at the time of a publish.

Another factor is that I have more than one content class that is supposed to be processed in this way. This makes my script a bit more complicated since the structure of the content class is not predefined.

The code that you have provided prints out a number of parameters that seem to be related to the main page.

This is what I am getting:

class ezcontentobjectattribute {
var $PersistentDataDirty = false;
var $HTTPValue = NULL;
var $Content = NULL;
var $DisplayInfo = NULL;
var $IsValid = NULL;
var $ContentClassAttributeID = '4';
var $ValidationError = NULL;
var $ValidationLog = NULL;
var $ContentClassAttributeIdentifier = 'name';
var $ContentClassAttributeCanTranslate = NULL;
var $ContentClassAttributeName = NULL;
var $ContentClassAttributeIsInformationCollector = NULL;
var $ContentClassAttributeIsRequired = NULL;
var $InputParameters = false;
var $HasValidationError = false;
var $DataTypeCustom = NULL;
var $ID = '1';
var $ContentObjectID = '1';
var $Version = '3';
var $LanguageCode = 'eng-CA';
var $AttributeOriginalID = '0';
var $SortKeyInt = '0';
var $SortKeyString = 'welcome to ez publish';
var $DataTypeString = 'ezstring';
var $DataText = 'Welcome to eZ publish';
var $DataInt = '0';
var $DataFloat = '0';
}class ezcontentobjectattribute {
var $PersistentDataDirty = false;
var $HTTPValue = NULL;
var $Content = NULL;
var $DisplayInfo = NULL;
var $IsValid = NULL;
var $ContentClassAttributeID = '155';
var $ValidationError = NULL;
var $ValidationLog = NULL;
var $ContentClassAttributeIdentifier = 'short_name';
var $ContentClassAttributeCanTranslate = NULL;
var $ContentClassAttributeName = NULL;
var $ContentClassAttributeIsInformationCollector = NULL;
var $ContentClassAttributeIsRequired = NULL;
var $InputParameters = false;
var $HasValidationError = false;
var $DataTypeCustom = NULL;
var $ID = '102';
var $ContentObjectID = '1';
var $Version = '3';
var $LanguageCode = 'eng-CA';
var $AttributeOriginalID = '0';
var $SortKeyInt = '0';
var $SortKeyString = 'ez publish';
var $DataTypeString = 'ezstring';
var $DataText = 'eZ publish';
var $DataInt = '0';
var $DataFloat = '0';
}class ezcontentobjectattribute {
var $PersistentDataDirty = false;
var $HTTPValue = NULL;
var $Content = NULL;
var $DisplayInfo = NULL;
var $IsValid = NULL;
var $ContentClassAttributeID = '119';
var $ValidationError = NULL;
var $ValidationLog = NULL;
var $ContentClassAttributeIdentifier = 'short_description';
var $ContentClassAttributeCanTranslate = NULL;
var $ContentClassAttributeName = NULL;
var $ContentClassAttributeIsInformationCollector = NULL;
var $ContentClassAttributeIsRequired = NULL;
var $InputParameters = false;
var $HasValidationError = false;
var $DataTypeCustom = NULL;
var $ID = '2';
var $ContentObjectID = '1';
var $Version = '3';
var $LanguageCode = 'eng-CA';
var $AttributeOriginalID = '0';
var $SortKeyInt = '0';
var $SortKeyString = '';
var $DataTypeString = 'ezxmltext';
var $DataText = '<?xml version="1.0" encoding="utf-8"?>
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">
<paragraph>eZ publish is a popular open source content management system and development framework. It allows the development of professional, customized and dynamic web solutions. It can be used to build anything from a personal homepage to a multinational corporate website with role based multiuser access, online shopping, discussion forums and other advanced functionality. In addition, because of its open nature, eZ publish can easily be plugged into, communicate and coexist with existing IT-solutions.</paragraph>
</section>';
var $DataInt = '1045487555';
var $DataFloat = '0';
}lineclass ezcontentobjectattribute {
var $PersistentDataDirty = false;
var $HTTPValue = NULL;
var $Content = NULL;
var $DisplayInfo = NULL;
var $IsValid = NULL;
var $ContentClassAttributeID = '156';
var $ValidationError = NULL;
var $ValidationLog = NULL;
var $ContentClassAttributeIdentifier = 'description';
var $ContentClassAttributeCanTranslate = NULL;
var $ContentClassAttributeName = NULL;
var $ContentClassAttributeIsInformationCollector = NULL;
var $ContentClassAttributeIsRequired = NULL;
var $InputParameters = false;
var $HasValidationError = false;
var $DataTypeCustom = NULL;
var $ID = '104';
var $ContentObjectID = '1';
var $Version = '3';
var $LanguageCode = 'eng-CA';
var $AttributeOriginalID = '0';
var $SortKeyInt = '0';
var $SortKeyString = '';
var $DataTypeString = 'ezxmltext';
var $DataText = '<?xml version="1.0" encoding="utf-8"?>
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">
<section>
<header>Documentation and guidance</header>
<paragraph>The
<link target="_blank"
url_id="1">eZ publish documentation</link> covers common topics related to the setup and daily use of the eZ publish content management system/framework. In addition, it also covers some advanced topics. People who are unfamiliar with eZ publish should at least read the &quot;eZ publish basics&quot; chapter.</paragraph>
<paragraph>If you&apos;re unable to find an answer/solution to a specific question/problem within the documentation pages, you should make use of the official
<link target="_blank"
url_id="4">eZ publish forum</link>. People who need professional help should purchase
<link target="_blank"
url_id="5">support</link> or
<link target="_blank"
url_id="6">consulting</link> services. It is also possible to sign up for various
<link target="_blank"
url_id="7">training sessions</link>.</paragraph>
<paragraph>
<line>For more information about eZ publish and other products/services from eZ systems, please visit
<link target="_blank"
url_id="8">ez.no</link>.</line>
</paragraph>
</section>
</section>';
var $DataInt = '1045487555';
var $DataFloat = '0';
}class ezcontentobjectattribute {
var $PersistentDataDirty = false;
var $HTTPValue = NULL;
var $Content = NULL;
var $DisplayInfo = NULL;
var $IsValid = NULL;
var $ContentClassAttributeID = '158';
var $ValidationError = NULL;
var $ValidationLog = NULL;
var $ContentClassAttributeIdentifier = 'show_children';
var $ContentClassAttributeCanTranslate = NULL;
var $ContentClassAttributeName = NULL;
var $ContentClassAttributeIsInformationCollector = NULL;
var $ContentClassAttributeIsRequired = NULL;
var $InputParameters = false;
var $HasValidationError = false;
var $DataTypeCustom = NULL;
var $ID = '108';
var $ContentObjectID = '1';
var $Version = '3';
var $LanguageCode = 'eng-CA';
var $AttributeOriginalID = '0';
var $SortKeyInt = '1';
var $SortKeyString = '';
var $DataTypeString = 'ezboolean';
var $DataText = '';
var $DataInt = '1';
var $DataFloat = '0';
}

Or have I done something wrong?

Thank you for your time.

Charly ...

Tuesday 06 June 2006 7:34:18 am

the code :

include_once( 'kernel/classes/ezcontentobject.php' );
$object =& eZContentObject::fetch( 1 );
$contentObjectAttributes =& $object->contentObjectAttributes();

foreach ($contentObjectAttributes as $contentObjectAttribute)
{
        var_dump( $contentObjectAttribute );
}

is not good with version 3.8.
In fact, I have the error message according to :
"Fatal error: Call to a member function on a non-object in..."

Somebody can it give me the good code for version 3.8 ?

Thank you in advance,

Dmytro Tomilovskiy

Tuesday 06 June 2006 8:31:17 am

Greetings, Charly.

I am currently working with 3.7, so things might be a little different for you. However this is the code that I am using to get the attributes of the content object that is being published:

include_once( 'kernel/classes/ezcontentobject.php' );

$processParams = unserialize( $process->Parameters );
$object_id = $processParams['object_id'];
$object = eZContentObject::fetch($object_id);

$contentObjectAttributes =& $object->contentObjectAttributes();

foreach ($contentObjectAttributes as $contentObjectAttribute)
{
var_export( $contentObjectAttribute, TRUE )
}

Notice that I am using $object_id variable instead of a fixed value 1. The error you are getting is probably caused by the fact that there is no object in your system with ID 1.

Thank you for your time.

Charly ...

Tuesday 06 June 2006 8:48:28 am

Greetings, Dmytro.

The ID 1 is the object_ID of the node n°2...
In fact, the fetch function need the object_id and not the node_id !

Your code is not good for my ez publish version... snif.

Notice: Undefined variable: process in ... on line 45
Notice: unserialize(): Argument is not a string in ... on line 45
Fatal error: Call to a member function on a non-object in ... on line 49

Thank you for your time.

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