I know about the user activate save etc system events, but my client wants to send an email to the user when they block them.... I look through the system events & did not see anything that fires when a user is blocked, but also the page says the list is not complete.
Does anyone know if there is an event triggered when a user is blocked or unblocked?
-thanks
-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
Hi - thanks,
Oh I can write the plugin, have one that does something similar on the user activation event, I just need to know if there is an event when a user is blocked or unblocked...
-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
Sorry - just managed to get back to this - thanks for the code & the pointers... working on a plugin for Revo based on your code there.
Though is a small problem right off the bat.
I don’t know how to detect if a user was previously blocked or not when the userFormSave event is triggered. I can grab 2 form fields from the post, but they both have the same name of "blocked"
i.e. if a user is currently UNblocked:
<input type="hidden" id="ext-gen184" value="0" name="blocked">
<input type="checkbox" autocomplete="off" id="modx-user-blocked" name="blocked" class=" x-form-checkbox x-form-field" value="1">
and is a user ISblocked:
<input type="hidden" id="ext-gen184" value="1" name="">
<input type="checkbox" autocomplete="off" id="modx-user-blocked" name="blocked" class=" x-form-checkbox x-form-field" value="1" checked="">
So you see from the form post I don’t see anyway to determine the state of the user...
-thoughts
-sean
*actually - I just had one, possibly a user variable is available that is storing the state - Investigating.
*** 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
Yes, I found that in Evolution, the ’was blocked’ value changes via JS on unchecking the ’blocked’ checkbox.
I added an extra field in manager/actions/mutate_web_user.dynamic.php to keep the original ’was blocked’ value so I then could compare.
Got it:
"blocked" is stored in the userProfile object:
$profile = $modx->user->getOne('Profile');
echo $profile ? $profile->get('blocked') : '';
if the user IS blocked that echos "1", if not it appears to be null.
-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
Hi David;
this is what I ended up doing - works quite nicely.
- thanks
-sean
<?php
// get the user's id from the form post
$uid = $_POST['id'];
// get/set the user's profile obj
$user = $modx->getObject('modUser',$uid);
$profile = $user->getOne('Profile');
// get some profile information
$email = $profile->get('email');
$fullname = $profile->get('fullname');
$isBlocked = $profile->get('blocked');
// get some system settings
$mailFrom = $modx->getObject('modSystemSetting', 'registration_reply_email');
$replyTo = $modx->getObject('modSystemSetting', 'emailNoReply');
// set some defaults
$mailFromName = 'Oncologyeducation.com Registration';
$message = '';
$mailChunk = '';
// set unblock message chunk & subject only if user is
// currently blocked and form post unblocks the user
if (($isBlocked == 1) && ($_POST['blocked'] == 0)){
$mailChunk = 'userUnBlocked';
$subject = 'You have been unblocked';
}
// set block message chunk & subject only if user is
// currently NOT blocked and form post blocks the user
if ($isBlocked == 0 && ($_POST['blocked'] == 1)){
$mailChunk = 'UserBlocked';
$subject = 'You have been blocked';
}
// send mail if there is a chunk defined
if ($mailChunk != ''){
$modx->setPlaceholder('fullname',$profile->get('email'));
$modx->setPlaceholder('email',$profile->get('fullname'));
$placeHolders = array('fullname' => $fullname, 'email' => $email);
$message .= $modx->parseChunk($mailChunk, $placeHolders, '[[+', '+]]');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,$mailFrom);
$modx->mail->set(modMail::MAIL_FROM_NAME,$mailFromName);
$modx->mail->set(modMail::MAIL_SENDER,$mailFrom);
$modx->mail->set(modMail::MAIL_SUBJECT,$subject);
$modx->mail->address('to',$email);
$modx->mail->address('reply-to',$replyTo);
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
}
$modx->mail->reset();
}
*** 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
I think if that user is saved again, they’ll get another email.
If you look at the ActivationEmail plugin, it detects when the user’s status changes from active to inactive (and vice versa) so it will only act once. You could adapt it to test for blocked status.
Hi Bob;
no it does not send multiple emails, I have tested it quite extensively.
The $isBlocked is grabbed from the user profile which is the user’s blocked status, Maybe it’s kinda funny to decide to send the email only if a mail template is defined.. but it works
-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