Any ideas how I can I find out what group a user was just added to in a plugin? [i.e. the plugin is attached to the OnUserAddToGroup event & needs to check which group the user was added before further processing]
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
The group should be available there as:
The $user object ($user) and the modUserGroupMember ($membership) object are also available .
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
-
☆ A M B ☆
- 2,475 Posts
There's gotta be a last-insert-id you can pull up for that somewhere.
Looking at the tables, it appears modx edits the group membership records rather than deleting & creating new ones when someone changes groups... so the last insert id thing does not look like it's going to work.
Is there a way to pass information from one plugin to another?
i.e. query the user's group membership during the OnUserBeforeAddToGroup then pass that to the plugin running during the OnUserAddToGroup event?
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
-
☆ A M B ☆
- 2,475 Posts
You could stash data inside the $modx object, since that persists throughout a single request. E.g. stash it as a placeholder.
Thanks guys, I got it working [or at least the test is working] It also gives me another avenue to work on for the onAfterGroupAdd action...
in the OnBeforeUserSave event I;
<?php
$ext = '';
$ext .= '<pre>';
$ext .= print_r(json_decode($user->get('groups'),true));
$ext .= '</pre>';
$modx->setPlaceholder('myPlaceholder', 'this is my placeholder data'.$ext);
$eventname = $modx->event->name;
$modx->log(modX::LOG_LEVEL_ERROR,'System event running = ' . $eventname);
then on the On AfterUserSave event:
$mydata = $modx->getPlaceholder('myPlaceholder');
$eventname = $modx->event->name;
$modx->log(modX::LOG_LEVEL_ERROR,'placeholder data = ' . $mydata);
$modx->log(modX::LOG_LEVEL_ERROR,'System event running = ' . $eventname);
And am rewarded with this in the logs:
[2012-07-22 17:23:28] (ERROR @ /connectors/security/user.php) System event running = OnUserBeforeSave
[2012-07-22 17:23:28] (ERROR @ /connectors/security/user.php) [OnUserBeforeSave]Array
(
[0] => Array
(
[usergroup] => 2
[name] => RegisteredUser
[member] => 69
[role] => 1
[rolename] => Member
[primary_group] =>
[rank] => 0
[menu] =>
)
[1] => Array
(
[usergroup] => 3
[name] => Artists
[member] => 69
[role] => 1
[rolename] => Member
[primary_group] => 1
[rank] => 0
[menu] =>
)
)
[2012-07-22 17:23:28] (ERROR @ /connectors/security/user.php) placeholder data = this is my placeholder data<pre>1</pre>
[2012-07-22 17:23:28] (ERROR @ /connectors/security/user.php) System event running = OnUserSave
Looks like the array itself isn't being passed, will have to tinker with it a bit [suggestions?]
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
What a giant pain in the a** ... addin/removing a user to a group in the manage user section is done before the beforeUserFormSave event, i.e. the group memberships are the same before and after the form is saved... whenever loading a users page in the manager you have. OnUserFormPrerender & OnUserFormRender - the $user object [and thus the groups] do not appear to be available during either event.
So now I'm back to square one, I don't see a way to compare the user's groups before and after they were modified!!
Is there a way to add a custom event?
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
Thanks, I'll pester some of the modx guys tomorrow to take a look at the threads & bug report and see what can/should be done from there... [ability to add a custom event sure would be nice!]
Unfortunately, I'm trying to make thing easier/less manual for the client, currently they have to review registered users who have applied for the next user/group level [allows them to fill in a more advanced profile] so it would have been handy to be able to promote the user to the new group, activate their advanced profile & send an activation notice with instructions etc. all in one go....
-sean
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525