New module extension

Author Message

David Santiso

Wednesday 04 May 2011 2:28:28 pm

Hi,

I'm developing an extension that updates an attribute of an object. I read the tutorial and explains how to insert and query data from the database, but doesn't explain how to update.

I've created the module, function and class, but I'm blocked. In ezpersistentobject class ther is a function updateObjectList, but I have to pass a variable $parameters. My code is this:

exempleclass.php

class ExempleClass extends eZPersistentObject {
    
    function exempleclass( $row ) {
        
        $this->eZPersistenObject( $row );        
    }
    
    function definition() {
        
        return array( 'fields' => array( 'id' => array( 'name' => 'id', 
                                                        'datatype' => 'integer', 
                                                        'default' => 0, 
                                                        'required' => true ),
 
                                         'user_id' => array( 'name' => 'version', 
                                                             'datatype' => 'integer', 
                                                             'default' => 0, 
                                                             'required' => true ),
 
                                         'created' => array( 'name' => 'data_int', 
                                                             'datatype' => 'integer', 
                                                             'default' => 0, 
                                                             'required' => false ) ),  
                      'class_name' => 'exempleclass', 
                      'name' => 'ezcontentobject_attribute' ); 
    }
    
    function update( $attribute_id, $version, $value ) {
        
        $row = array( 'definition' => array( 'name' => 'ezcontentobject_attribute',
                                             'fields' => array( ),
                                             'key' ),
                      'update_fields' => array( 'data_int' => $value ),
                      'conditions' => array( 'id' => $attribute_id,
                                             'version' => $version ) );
        
        return new exempleclass( $row );
    }
}

exemplefunction.php

include_once 'extension/example/classes/exempleclass.php';

$Module = $Params['Module'];

$attributeId= $Params['AttributeId']; 
$version = $Params['Version'];

$ExampleClass= ExampleClass::update( $attributeId, $version, 23 );

How do I call the function to update?

Thanks,

David

Marko Žmak

Thursday 05 May 2011 12:28:42 am

For such a simple task as changing one attribute of an object, you don't need to extend the eZPersistentObject class. What you need is basically this:

  • get both object ID and attribute ID as a module parameter
  • fetch the object using the static fetch function of eZContentObject class
  • change the attribute and store it
  • sroe or publish the object

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

David Santiso

Thursday 05 May 2011 1:51:40 am

Ok, but if I call the store function I'll be making a new INSERT. I want to do an UPDATE.

Marko Žmak

Thursday 05 May 2011 2:20:41 am

"

Ok, but if I call the store function I'll be making a new INSERT. I want to do an UPDATE.

"

No it won't. The store method does an INSERT only if you create a new object of class eZContentObject. And since you will be fethcing an existing object it will do an UPDATE in your case.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

David Santiso

Thursday 05 May 2011 2:36:01 am

Ah!

Ok, thanks. I didn't understand it.

David Santiso

Thursday 05 May 2011 6:09:58 am

Ok. I've to do this in function.php:

includes...
 
$Module = $Params['Module'];

$objectId = $Params['ObjectId'];
$attributeId = $Params['AttributeId']; 
$version = $Params['Version'];
 
$contentObject= eZContentObject::fetchAttributesByIdentifier( $attributeId, $version, false, true );

... ?

But, how do I change the attribute?

Marko Žmak

Thursday 05 May 2011 6:32:27 am

You can find some usefull tips about it here:

  • http://share.ez.no/forums/developer/can-attribute-store-be-replaced-by-object-store
  • http://share.ez.no/forums/developer/how-to-edit-store-user-attributes-within-a-extension

The last comment in the first thread is the simplest, but I think it won't clear the cache.

As for the detailed docs about it I don't think there is any, you'll have to dig and try a little bit until you figure out what's the best for you.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

David Santiso

Thursday 05 May 2011 11:57:28 am

Thank you very much.

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

eZ debug

Timing: Jan 18 2025 10:27:47
Script start
Timing: Jan 18 2025 10:27:47
Module start 'layout'
Timing: Jan 18 2025 10:27:47
Module start 'content'
Timing: Jan 18 2025 10:27:48
Module end 'content'
Timing: Jan 18 2025 10:27:48
Script end

Main resources:

Total runtime0.6204 sec
Peak memory usage4,096.0000 KB
Database Queries73

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 589.2422152.6094
Module start 'layout' 0.00480.0025 741.851639.4219
Module start 'content' 0.00730.6120 781.2734615.0000
Module end 'content' 0.61930.0011 1,396.273420.1875
Script end 0.6204  1,416.4609 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.5247160.0002
Check MTime0.00130.2085160.0001
Mysql Total
Database connection0.00050.086410.0005
Mysqli_queries0.554289.3243730.0076
Looping result0.00090.1421710.0000
Template Total0.594095.720.2970
Template load0.00250.404720.0013
Template processing0.591495.328320.2957
Template load and register function0.00020.026910.0002
states
state_id_array0.00070.107710.0007
state_identifier_array0.00060.104820.0003
Override
Cache load0.00220.3588570.0000
Sytem overhead
Fetch class attribute can translate value0.00050.081920.0003
Fetch class attribute name0.00110.181790.0001
XML
Image XML parsing0.00080.132220.0004
class_abstraction
Instantiating content class attribute0.00000.0035110.0000
General
dbfile0.00210.3312180.0001
String conversion0.00000.001140.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
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
15content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
5content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
2content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
1content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 49
 Number of unique templates used: 12

Time used to render debug report: 0.0001 secs