XF 2.0 Any guides on extending the alert system?

Jaxel

Well-known member
I've got my "events", and I want to send an alert to the event owner when someone "RSVPs" for that event. Whats the correct way to get this done?
 
You need to add an alert_handler_type field to your alert content type with a value which points to a class which extends our AbstractHandler alert class. Very similar to XF1 tbh.
 
Looking for something a bit more in-depth... there are a lot of options and functions here...
 
Well, there's not a lot more to say. You can look at the built in alert handlers for guidance, e.g. XF\Alert\Post.
 
I've got my Alert handler built... but how do I actually send alerts out? How can I retract an alert?
 
Look in the UserAlert repo (XF\Repository\UserAlert) specifically the alert and alertFromUser methods. There's also a bunch of fastDeleteX methods for deleting alerts.
 
So like this?
Code:
if ($occur->Event->user_id != $visitor->user_id)
{
    $alertRepo = \XF::repository('XF:UserAlert');
   
    if ($rsvp->rsvp_state == 'y')
    {
        $alertRepo->alertFromUser($occur->Event->User, $visitor, 'ewr_atendo_occur', $occur->occur_id, 'rsvp');
    }
    else
    {
        $alertRepo->fastDeleteAlertsFromUser($visitor->user_id, 'ewr_atendo_occur', $occur->occur_id, 'rsvp');
    }
}
 
Last edited:
Looks about right, though the first two arguments of alertFromUser expect user entities. It looks like the first argument of your alertFromUser line is just a user ID.
 
Final question... what is the difference between alert() and alertFromUser()?

I want to send out an alert that is from no user (like a trophy)...
 
Also, for alert preferences, it prefaces it with:
Receive an alert when someone…

For the alert I am doing, this doesn't make sense, since no one is sending this alert. Like a trophy, its just sent by the system.

In my cause, this alert would be for something along the lines of:
An event you are attending begins in less than 7 days

As you can see, this doesn't jive with "Receive an alert when someone...."

How can I add a special phrase just for this section?
 
Unfortunately not, it likely needs a bit of creativity. Something like...

Receive an alert when someone... is hosting an event you are attending in less than 7 days.
 
Unfortunately not, it likely needs a bit of creativity. Something like...

Receive an alert when someone... is hosting an event you are attending in less than 7 days.
That sounds awful...

I already spend all day trying to come up with variable names so that all my variables have the same length, to satisfy my OCD.
 
Top Bottom