Help / insight needed: Write a custom user class's fields

Author Message

Massimiliano Bariola

Tuesday 19 July 2005 7:18:53 am

Hi,

I created my own User class by adding a simple Integer field to the default user class.
I need this because, at a later time (not at user registration / login) I will need to put a value into it which is integral to the user profile.

I cannot figure how to write into it, though.

I was able to access this custom field both via template and via PHP like this:

Template:

{def $user = fetch(user, 'current_user')}
{$user.contentobject.data_map.id_anagrafica.data_int}

PHP:

$user = &WTUser::currentUser();
$userCO = & $user->Attribute('contentobject');
$dm = &$userCO->DataMap();
$userIDAnag = $dm['id_anagrafica']->DataInt;

WTUser extends eZUser just like this :

class WTUser extends eZUser
{
    function WTUser( $row )
    {
        $this->eZUser( $row );
    }

    function &definition()
    {
$WTArr = array('fields' => 
array( 'id_anagrafica' => array(
'name' => 'IDAnagraphic',                                                       'datatype' => 'integer',                                                                      'default' => 0,                                                                      'required' => true )));

eZUserArray = &eZUser::definition();
$WTArr = array_merge_recursive($WTArr, $eZuserArray);
$WTArr['class_name'] = 'WTUser';
return $WTArr;
}



    /// \privatesection
    var $IDAnagraphic;
}

and here is the first hurdle .... eZ is clearly saving that field somewhere, because I can access it, and I can change its value via the admin interface. I thought I needed to specify a custom table into the definition() function but I want to avoid it as it makes sense to me that users must stay into their default table.

It seems to me that it saves the value in ezcontentobject_attribute table, but I do not know how to trigger this behavior, or how to save that value programmatically in a clean way.

$myOwnUserclass->Attributes does not show my attribute as available for retrieving or saving. What I want to do is to be able to update / save my extended user class with the same API as eZPersistentObject or similar.

Can anyone help in making sense of this problem and solve it in a clean way? I apologize in advance if it's not clear enough.

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 20 2025 09:57:58
Script start
Timing: Jan 20 2025 09:57:58
Module start 'layout'
Timing: Jan 20 2025 09:57:58
Module start 'content'
Timing: Jan 20 2025 09:57:58
Module end 'content'
Timing: Jan 20 2025 09:57:58
Script end

Main resources:

Total runtime0.0200 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 589.3984152.6563
Module start 'layout' 0.00560.0042 742.054739.4922
Module start 'content' 0.00980.0077 781.546989.5078
Module end 'content' 0.01750.0025 871.054730.3047
Script end 0.0200  901.3594 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002613.1180140.0002
Check MTime0.00115.4738140.0001
Mysql Total
Database connection0.00104.866910.0010
Mysqli_queries0.003417.088930.0011
Looping result0.00000.124910.0000
Template Total0.002010.010.0020
Template load0.00105.129910.0010
Template processing0.00104.815710.0010
Override
Cache load0.00063.170010.0006
General
dbfile0.003216.035880.0004
String conversion0.00000.048840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs