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.