This topic is locked

Notification API -- multiple users

2/28/2022 7:48:56 PM
Suggestions
Pete K author

I've been playing around with the new notification API. Very nice. I have a suggestion:

If the user parameter were an array, it would be so much more useful. As it is (if understand correctly) our only options are the notification is visible to only one user or to all users. This is not very useful to me. In most cases, I want a notification to show up for a selcted group of users who share a common role, such as all members of a user group or all users at a particular work location. If I could pass an array of users rather than just one I could easily accomplish this.

dageciDevClub member 3/15/2022

Why don't you create your function where you pass to it your usergroup and this function in a loop add notifications to all the users in this group, or function for locations, pass location to this function and in this function add notifications to users.

admin 3/15/2022

We only have an option to notify a single user at the time. You will need to loop through the list of users and add a notification individually.

D
druck281 3/22/2022

I actually ran into this same thing. I wanted to notify specific user groups. I figured out how to code it. This example notifies two different groups but you can write the WHERE statement however you want it. The 'if' statement skips the notification for the logged in user but you can omit that too if you want. Here is the link to the Facebook post...https://www.facebook.com/groups/121465711664/permalink/10159760327006665/

Good luck!

$currentUser=$_SESSION["UserName"]; //Setting current user to variable for use in the comparison for the "if" statement
$rs = DB::Query("SELECT * FROM trax_ugmembers WHERE GroupID=12 OR GroupID=3"); //Fetch an array of usernames from the given user groups
while($data = $rs->fetchAssoc() )
{
//The "If" statement serves to skip over creating a notification for the user that created the record
if ($data["UserName"] != $currentUser) {
//Calls the Notification API. At testing the makePageLink() function was not producing the $keys value so the URL was hardcoded
addNotification("New Crash Number: ".$values['CrashNumber'], "Crash Added", "glyphicon-send", "pat_CrashNumberAssign_edit.php?editid1=".$values['CAD_Number'], $expire=5, $data["UserName"]);
}
}