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

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

eZ debug

Timing: Jan 18 2025 04:26:57
Script start
Timing: Jan 18 2025 04:26:57
Module start 'layout'
Timing: Jan 18 2025 04:26:57
Module start 'content'
Timing: Jan 18 2025 04:26:58
Module end 'content'
Timing: Jan 18 2025 04:26:58
Script end

Main resources:

Total runtime0.7355 sec
Peak memory usage4,096.0000 KB
Database Queries64

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0067 588.0469152.6406
Module start 'layout' 0.00670.0036 740.687539.5000
Module start 'content' 0.01030.7239 780.1875619.8281
Module end 'content' 0.73420.0013 1,400.015616.1250
Script end 0.7355  1,416.1406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00450.6093160.0003
Check MTime0.00170.2261160.0001
Mysql Total
Database connection0.00110.153410.0011
Mysqli_queries0.665590.4817640.0104
Looping result0.00060.0876620.0000
Template Total0.698394.920.3491
Template load0.00240.322920.0012
Template processing0.695994.615520.3480
Template load and register function0.00010.013710.0001
states
state_id_array0.00070.099910.0007
state_identifier_array0.00120.163420.0006
Override
Cache load0.00210.2808390.0001
Sytem overhead
Fetch class attribute can translate value0.00040.057530.0001
Fetch class attribute name0.00110.155570.0002
XML
Image XML parsing0.00150.204730.0005
class_abstraction
Instantiating content class attribute0.00000.002580.0000
General
dbfile0.00110.1536300.0000
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs