Created
March 8, 2012 14:11
-
-
Save Mark-H/2001155 to your computer and use it in GitHub Desktop.
Plugin to send email notifications to all members of a user group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Hi there!</p> | |
<p>The resource [[+pagetitle]] (ID: [[+id]]) has been [[+mode]].</p> | |
<p>You can login to the manager at www.mysite.com/manager/ to review and if needed publish the resource.</p> | |
<p>Thank you!</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// untested | |
// Update these if you have to | |
$usergroup = 1; // user group ID (1=admin) | |
$chunkname = 'notificationtpl'; // name of chunk for the email notification | |
$emailoptions = array( | |
'from' => $modx->getOption('emailsender'), | |
'fromName' => 'Resource Notification', | |
'subject' => 'Nofication of Created or Updated Resource', | |
'html' => true, | |
); | |
// No need to update below (unless I typo-ed) | |
$placeholders = $resource->toArray(); | |
$placeholders['mode'] = ($mode == 'upd') ? 'updated' : 'created'; | |
$message = $modx->getChunk($chunkname,$placeholders); | |
$userIds = $modx->getCollection('modUserGroupMember', array('user_group' => $usergroup)); | |
foreach ($userIds as $userId) { | |
$user = $modx->getObject('modUser',$userId->get('member')); | |
if ($user) { | |
$user->sendEmail($message, $emailoptions); | |
} | |
} |
tommls
commented
Mar 8, 2012
via email
It's **ALL** justified on your part. :)
By now you probably know how easy it is for people to do "feature creep" or "scope creep" on a project -- I made this mistake on you, sigh -- I don't know which word you use for when projects just "grow"...!!!
I found Bob Ray's guide to plugins/objects which pretty much explains what I must do to obtain the desired resource objects according to various criteria, but I have not yet started working on it.
I think the OnManagerLogout is a more suitable event despite the possibility of person not clicking logout
I also must figure some way to test/debug what I'm doing as I've never done a plugin. Haven't yet checked Bob's book for this. Wish it were digital then I could search on "debug" and make more progress.
I know what criteria I must filter the resources on (many!! in addition to created/updated) and your code for emailing it I will use when it's finished -- before that I will have it email ME!!
When I finish it I'll try to remember to put it into a forum thread somewhere for people to find
SO -- you were actually really helpful!!
Thank you, Tom
…-----Original Message-----
From: Mark Hamstra [mailto:[email protected]]
Sent: Thursday, March 08, 2012 3:33 PM
To: Tom Lyczko
Subject: Re: gist gist: 2001155
I thought I posted here, but looks like it didn't go through..
The frustration comes from you requesting a feature, me making time for it and handing it on a silver plate (well, almost) after which it doesn't even take you five minutes to put forward the next request, which takes an entirely different angle and makes me wonder if I shouldn't have spend time on something that apparently doesn't fit your needs anyway...
So, to answer your tweet, no I'm not mad. At time of my last post I was just frustrated for the above reason. I'm pretty sure someone else will find this gist some day (linked to it from my site) and see it's exactly what they needed.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2001155
Found your gist and it was exactly what I needed. Thanks!!!
This is exactly what I needed. Many thanks for this exceptional ground-work!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment