XF 2.0 Send an alert to members of a particular user group

LPH

Well-known member
Currently, this code works for sending to the individual creating the thread. How can an alert be written so that the alert goes to everyone who belongs to a particular user group?

PHP:
/** @var \XF\Repository\UserAlert $alertRepo */
$alertRepo = \XF::app()->repository('XF:UserAlert');
$alertRepo->alertFromUser($user, $author, 'post', $thread->first_post_id, 'insert');
 
PHP:
$alertUsers = \XF::app()->finder('XF:User')->fetch();

foreach ( $alertUsers AS $alertUser ) {
   /** @var \XF\Repository\UserAlert $alertRepo */
   $alertRepo = \XF::app()->repository('XF:UserAlert');
   $alertRepo->alertFromUser($alertUser, $author, 'post', $thread->first_post_id, 'insert');
}

This is what appears to work. I'm not sure if there is a more efficient way.
 
The next question becomes, how can the message be changed? The insert action is being used.

@Chris D -- is there an example of where to write an action to replace the insert currently used in the code? I don't see anything in the developer manual.
 
To change the message based on new actions, you need to create a new template alert_post_newaction and include the new phrase there. See other alert templates for examples.
 
Back
Top Bottom