Re: Needing a programmatic insertion of DD

[email protected] (mikespub) Tue, 26 Aug 2003 17:26:48 GMT
Newsgroups gmane.comp.cms.xaraya.knowledge-base
Organization not much
Message-ID <[email protected]>
In article <mailman.648.1061913800.8320.xaraya_knowledge-base-n5IRV0TL0hwRxVAL8JNkPw@public.gmane.org>, Xaraya Knowledge Base <[email protected]> wrote:
>Hello.
>I need an API or something-like in order to programmatically add DD attribu=
>tes to a "main" record.
>For example, 2 DD attributes are assigned to "roles":
>- TVAcode
>- firm
>What I need is a mechanism in order to add values contextually to a "role" =
>creation, for example passing an array
>array('TVAcode'=3D>'07987879987','firm'=3D>'My Firm')
>to an API, WITHOUT use of forms, templates etc: only APIs, and perhaps some=
> direct querying to the DB.
>
>Someone knows if it's possible ? Any idea?
>
>Thanks in advance
>Federico

The import script for PostNuke shows an example of that, for importing the
user information. See the tests/import/postnuke/import_pn_users.php file.

For importing many users, the most efficient way is as follows :

0) disable dynamicdata hooks before the import

    // Disable dynamicdata hooks for roles (to avoid create + update)
    if (xarModIsHooked('dynamicdata','roles')) {
        xarModAPIFunc('modules','admin','disablehooks',
                      array('callerModName' => 'roles', 'hookModName' => 
'dynamicdata'));
    }

1) get the dynamic object corresponding to "roles"

    // check if there's a dynamic object defined for users
    $myobject =& xarModAPIFunc('dynamicdata','user','getobject',
                               array('moduleid' => 
xarModGetIDFromName('roles'), // it's this module
                                     'itemtype' => 0));                        
  // with no item type

2) for each user $newuid, pass the dynamic values to ->createItem()

        // create the new user, or get its user id from somewhere
        // $newuid = xarModAPIFunc('roles', 'admin', 'create', ...);

        // fill in the dynamic properties - cfr. users.xml !
        $dynamicvalues = array(
                               'itemid'     => $newuid,
                               'website'    => empty($url) ? null : $url,
                               'timezone'   => $timezone == 0 ? null : 
$timezone, // GMT default
                               'avatar'     => empty($avatar) ? null : 
$avatar,
                               'icq'        => empty($icq) ? null : $icq,
                               'aim'        => empty($aim)  ? null : $aim,
                               'yim'        => empty($yim) ? null : $yim,
                               'msnm'       => empty($msnm) ? null : $msnm,
                               'location'   => empty($location) ? null : 
$location,
                               'occupation' => empty($occupation) ? null : 
$occupation,
                               'interests'  => empty($interests) ? null : 
$interests,
                               'signature'  => empty($signature) ? null : 
$signature,
                               'extra_info' => empty($extra_info) ? null : 
$extra_info,
                              );
        $myobject->createItem($dynamicvalues);

Note : you do need to specify the 'itemid' value here to "link" your
values to the user $newuid. The other values depend on your particular
DD object.

3) enable dynamicdata hooks again after the import

        // Enable dynamicdata hooks for roles
        xarModAPIFunc('modules','admin','enablehooks',
                      array('callerModName' => 'roles', 'hookModName' => 
'dynamicdata'));

=============================================

For a single user, it's probably easier to let the create hook
create the initial item, and then to update it :

// first create the user (this also calls the create hooks)
$uid = xarModAPIFunc('roles', 'admin', 'create', ...);

// now get the dynamic object for that user
$myobject =& xarModAPIFunc('dynamicdata', 'user', 'getobject',
                           array('module' => 'roles',
                                 'itemid' => $uid));

// and update it with the real values
$myobject->updateItem(array('tvacode' => ..., 'firm' => ...));


The syntax is a bit different compared to the "mass import" above,
but it's the same idea.

Mike.