Forums / Developer / Helper classes?

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

eZ debug

Timing: Jan 18 2025 11:04:58
Script start
Timing: Jan 18 2025 11:04:58
Module start 'content'
Timing: Jan 18 2025 11:04:59
Module end 'content'
Timing: Jan 18 2025 11:04:59
Script end

Main resources:

Total runtime1.1489 sec
Peak memory usage4,096.0000 KB
Database Queries58

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 587.5781180.8516
Module start 'content' 0.00601.1359 768.4297512.3750
Module end 'content' 1.14190.0070 1,280.804742.1484
Script end 1.1488  1,322.9531 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.2604140.0002
Check MTime0.00130.1151140.0001
Mysql Total
Database connection0.00080.067410.0008
Mysqli_queries1.105296.2011580.0191
Looping result0.00050.0442560.0000
Template Total1.117297.220.5586
Template load0.00200.177520.0010
Template processing1.115197.061620.5576
Template load and register function0.00020.019310.0002
states
state_id_array0.00110.098710.0011
state_identifier_array0.00170.152320.0009
Override
Cache load0.00170.1502250.0001
Sytem overhead
Fetch class attribute can translate value0.00060.052820.0003
Fetch class attribute name0.00130.114440.0003
XML
Image XML parsing0.00050.044120.0003
class_abstraction
Instantiating content class attribute0.00000.001340.0000
General
dbfile0.00340.2983170.0002
String conversion0.00000.000430.0000
Note: percentages do not add up to 100% because some accumulators overlap

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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/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: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs