Populate User Object

Author Message

Rob Pratt

Tuesday 29 August 2006 9:58:16 pm

Hello.

I'm trying to create, populate and store a custom user obect class in php for a custom registration module. Class definition has user account attribute, and I can create and save the object, but only the user account object seems to be stored, none of the other attributes. Here's an example snippet of what I'm doing:


// Create and instantiate user object

// Then ...

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

$contentObjectAttributes[0]->setAttribute('data_int', $attribute1);
$contentObjectAttributes[0]->store();

$contentObjectAttributes[1]->setAttribute('data_int', $attribute2);
$contentObjectAttributes[1]->store();

$userAccountObject = eZUser::fetch($contentObjectAttributes[2]->ContentObjectID);
$userAccountObject->setInformation($contentObject->attribute('id' ), $username, $email, $password, $confirmPassword);
$userAccountObject->store();

$contentObject->setAttribute('status', EZ_VERSION_STATUS_DRAFT);
$contentObject->store();

// Publish object and do some other stuff ...

How do I need to populate the user account and the other data attributes so that they're all stored?

Regards,
Rob Pratt
rpratt(at-sign)wordandsound.com

Kristof Coomans

Wednesday 30 August 2006 3:05:18 am

Hello Rob

Do you call the publish operation after <i>// Publish object and do some other stuff ...</i>?

Take a look at these topics:
http://ez.no/community/forum/setup_design/nodeassignment_and_treenode
http://ez.no/community/forum/developer/insert_objects_from_module_clear_cache_problem
http://ez.no/community/forum/general/publish_object_with_php
http://ez.no/community/forum/developer/importing_data

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Rob Pratt

Wednesday 30 August 2006 11:41:42 am

Hello.

Thanks for the info you sent. I reviewed the threads you referenced, and I'll try a few different things based on what I saw there. However, I don't think the problem is in the publish step (though I could be wrong). Here's the above code including the code I use to publish the object:


// Create and instantiate user object

// Then ...

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

$contentObjectAttributes[0]->setAttribute('data_int', $attribute1);
$contentObjectAttributes[0]->store();

$contentObjectAttributes[1]->setAttribute('data_int', $attribute2);
$contentObjectAttributes[1]->store();

$userAccountObject = eZUser::fetch($contentObjectAttributes[2]->ContentObjectID);
$userAccountObject->setInformation($contentObject->attribute('id' ), $username, $email, $password, $confirmPassword);
$userAccountObject->store();

$contentObject->setAttribute('status', EZ_VERSION_STATUS_DRAFT);
$contentObject->store();


// Publish it
include_once ('lib/ezutils/classes/ezoperationhandler.php');
$operationResult = eZOperationHandler :: execute('content', 'publish', array (
	'object_id' => $contentObject->attribute('id' ),
	'version' => 1
));

// Send notification emails and redirect

The object seems to be published correctly. What's not working correctly is that attribute data is not being saved correctly. The only attribute that is saved correctly is the user account. Do I need to get the user account by reference (same as the contentObjectAttributes array)? Like this:

$userAccountObject = & eZUser::fetch($contentObjectAttributes[2]->ContentObjectID);

Regards,
Rob Pratt
rpratt(at-sign)wordandsound.com

Claudia Kosny

Wednesday 30 August 2006 12:49:22 pm

Hello Rob,

For me it worked once I fetched the version of the contentobject and then changed the contentattributes of this version.
Something like thsis:

   //create and instantiate the object, assign a node

    $version =& $contentObject->version(1); //it is a new contentobject, thus version 1
    $version->setAttribute('created', $now);
    $version->setAttribute('modified', $now);
    $version->setAttribute('status', EZ_VERSION_STATUS_DRAFT);    
    $version->store();
    
    $contentObjectAttributes =& $version>contentObjectAttributes();

   //set and store the contentobjectattributes
  
  //publish the node

Hope it helps

Claudia

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 14:51:48
Script start
Timing: Jan 18 2025 14:51:48
Module start 'layout'
Timing: Jan 18 2025 14:51:48
Module start 'content'
Timing: Jan 18 2025 14:51:49
Module end 'content'
Timing: Jan 18 2025 14:51:49
Script end

Main resources:

Total runtime1.3891 sec
Peak memory usage4,096.0000 KB
Database Queries62

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 587.8125152.6094
Module start 'layout' 0.00610.0027 740.421939.4141
Module start 'content' 0.00881.3791 779.8359592.4141
Module end 'content' 1.38790.0011 1,372.250016.1875
Script end 1.3890  1,388.4375 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.2194160.0002
Check MTime0.00130.0953160.0001
Mysql Total
Database connection0.00140.097810.0014
Mysqli_queries1.337896.3088620.0216
Looping result0.00060.0441600.0000
Template Total1.354697.520.6773
Template load0.00190.138220.0010
Template processing1.352797.378320.6763
Template load and register function0.00010.009910.0001
states
state_id_array0.00150.108410.0015
state_identifier_array0.00130.092420.0006
Override
Cache load0.00160.1164350.0000
Sytem overhead
Fetch class attribute can translate value0.00070.049030.0002
Fetch class attribute name0.00070.053250.0001
XML
Image XML parsing0.00070.048330.0002
class_abstraction
Instantiating content class attribute0.00000.000650.0000
General
dbfile0.00160.1133160.0001
String conversion0.00000.000740.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
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/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
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs