Share » Forums » Developer » Add location to user with template...

Add location to user with template programming? [SOLVED]

Add location to user with template programming? [SOLVED]

Thursday 07 July 2005 3:12:36 am - 3 replies

Modified on Friday 08 July 2005 7:58:09 am by Mikael Johansson

Author Message

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

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu