Forums / Developer / Moving user under a group during activation [SOLVED]

Moving user under a group during activation [SOLVED]

Author Message

Lo' F.

Monday 30 May 2011 8:40:32 am

Hello everybody!

When new users register themselves, they have to wait for the administrator to activate their account (...removed the email activation feature).

But I would like to add a shortcut which will allow the administrator to move its website's users under a group he wants them to belong, directly from the user setting page.

For this I added a new block with a simple select field recalling the list of available users groups in the setting.tpl (design/admin2/templates/user/).

<div class="block">
<label>{'Move this user under a users group'|i18n( 'design/admin/user/setting' )}:</label>
{def $users_groups=fetch('content', 'list', hash('parent_node_id', 199))}
<select name="users_groups">
<option value="">{'Please select'|i18n( 'design/admin/user/setting' )}</option>
{foreach $users_groups as $group}
<option value="{$group.node_id}">{$group.name}</option>
{/foreach}
</select>
</div>

Technically when he ticks the checkbox, selects the desired group and clicks ok, the user will be active and located under its new group node.

I guess, in order to accomplish this, the file I would need to alter is kernel/user/activate.php, right?

Since I have had unpleasant experiences with kernel files, playing with it freaks me out a bit.

Found something on the subject http://ezpedia.org/snippet/php_snippet_moving_a_node. Do I need to integrate a functionality like that in that activate.php file?

Thanks a lot!

loredanaebook.it

Lo' F.

Monday 30 May 2011 10:15:31 am

Well, it's done! With or without reply, this forum turns to be always lucky to me!

First of all the right file wasn't activate.php (which is instead related to email activation, I suppose) but setting.php under kernel/user/.

In setting.tpl I also added an hidden field through which pass over the user node id needing to be moved.

<input type="hidden" name="user_node" value="{$user[contentobject][main_node_id]}" />

And in the setting.php file, the rest of the game..

if ( $http->hasPostVariable( "UpdateSettingButton" ) )
{
    ...
    if ( $http->hasPostVariable( 'user_node' ) )
    {
        $userNode = $http->postVariable( 'user_node' );
    }
    if ( $http->hasPostVariable( 'users_groups' ) )
    {
        $usersGroup = $http->postVariable( 'users_groups' );
    }
...

... within the eZOperationHandler else statement..

else
    {
        eZUserOperationCollection:: ...

        eZContentObjectTreeNodeOperations::move( $userNode, $usersGroup );
    }

 

loredanaebook.it

Nicolas Pastorino

Tuesday 31 May 2011 12:24:20 am

Hi Lo' F !

I like the fact that the eZ Community forums are your lucky charm :)

About your solution : it seems fully functional, but it kinda hacks the kernel files, making any future upgrade a bit boring. How about an ajax based solution ? You could keep the template you updated, but simply handle the action through Ajax. This will have you create your own backend, using ezjscore for instance, but will keep your install future-proof.

Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Marko Žmak

Tuesday 31 May 2011 2:08:21 am

Hi Lo, there's already a way in eZP to this and it's done like this:

<form action="{'content/action'|ezurl(no)}" method="post">
<input type="hidden" name="ContentNodeID" value="id_of_node_you_want_to_move">
<input type="hidden" name="NewParentNode" value="id_of_parent_node_where_you_want_to_move_it_to">
<input type="hidden" name="ViewMode" value="redirectback">
<input type="submit" name="MoveNodeAction" value="Move user to another group">
</form>

so you don't have to hack the kernel.

Does this help?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth