Add location to user with template programming? [SOLVED]

Author Message

Mikael Johansson

Thursday 07 July 2005 3:12:36 am

I am trying to add a location to a user using template programming but haven't gotten very far.

I fetch the user object using

{def $userobject = fetch('content', 'object', hash('object_id', $userID))}

If I do a

{$userobject|attribute(show, 3)}

I get a list of the attributes of the user, so I now that it returns a valid user object.

The problem arises when I try to do

{$userobject->createNodeAssignment($groupNodeID, false)}

to add the user to a new group. I get this error:
parser error @ extension/chsuser/design/standard/templates/chsuser/add.tpl:40[12]
Extra characters found in expression, they will be ignored.
>createNodeAssignment($groupID, false)' ($userobject-)

Is the function createNodeAssignment not avaliable for user objects? The code works for my custom content objects.

Is it possible to do this another way?

Best regards
Mikael Johansson, Sweden

Mikael Johansson, Sweden

Mikael Johansson

Friday 08 July 2005 7:58:47 am

Solved it:

$object =& eZContentObject::fetch( $userID );

// Need to unpublish the user to be able to add it to the new location.
include_once('kernel/classes/ezcontentobject.php');
$object =& eZContentObject::fetch( $userID );
$version =& eZContentObjectVersion::fetchVersion(  $object->attribute('current_version'), $userID );
$version->unpublish();

// Add the location to the user
$object->createNodeAssignment($groupID, false);

// Finally, publish the user again.
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $userID,
                                                                             'version' => $object->attribute('current_version') ) );

Mikael Johansson, Sweden

Pål J Didriksen

Monday 11 July 2005 7:48:05 am

Great! I've been struggeling with this for a while too... But now it works!

Mikael Johansson

Tuesday 12 July 2005 2:23:47 am

I found a problem: I need to check for permissions in the php code. Now it is possible to add any user to any group as ling as you know the nodeid of the group.

How do I check permissions?
I have template code to do it, bit I need to do the check in the php code.

{* Check permissions *}
{def $groupobject = fetch('content', 'node', hash('node_id', $groupID))}
{if not($groupobject.can_edit)}
You do not have the proper permissions to add people to group {$groupID}.
{else}
User has been added. Thank you!
{/if}

Mikael Johansson, Sweden

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