solved Custom notifications

alt=
DannyA
@dannya
9 years ago
584 posts
I haven't found anything in the documentation. Can you explain how the notification system works and how to create a new notification in integrate it into the profile notification options.

I am looking at how to send notification to the accounts linked to a specific profile AND to directly to specific accounts.
updated by @dannya: 04/18/15 08:51:52PM
brian
@brian
9 years ago
10,148 posts
First up, just to make sure you know that notifications are tied to USER accounts - not profiles, so just an FYI.

To integrate with User Notifications, in your module register for the feature:

$_tmp = array(
    'label' => 'notification section label',
    'help'  => 'help text for notification'
);
jrCore_register_module_feature('jrUser', 'notification', 'MyModule', 'module_action', $_tmp);

That goes in your module init function.

Then, in your code:

$sub = 'This is the Subject';
$msg = 'This is the body of the message';

// notify user_id "1" FROM "0" (which is "system") - set to a user_id to change the from user
jrUser_notify(1, 0, 'MyModule', 'module_action', $sub, $msg);

Let me know if that helps.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 03/18/15 11:18:34AM
alt=
DannyA
@dannya
9 years ago
584 posts
So is there no way to select a profile an send a notification to all linked accounts according to their preferences?

Incidentally, I noticed that notification preferences are not registered in the user table until a user saves them for the first time. Is this by design?
updated by @dannya: 03/18/15 12:18:16PM
brian
@brian
9 years ago
10,148 posts
DannyA:
So is there no way to select a profile an send a notification to all linked accounts according to their preferences?

Sure there is - you just need to get the users first, then loop over them and send the notification - i.e.

$profile_id = 5;  // whatever profile_id you want to send to
$_users = jrProfile_get_owner_info($profile_id);
if ($_users && is_array($_users)) {
    foreach ($_users as $_us) {
        jrUser_notify($_us['_user_id'], 0, 'MyModule', 'module_action', $sub, $msg);
    }
}

Quote:
Incidentally, I noticed that notification preferences are not registered in the user table until a user saves them for the first time. Is this by design?

yes - that is by design. The default is "email".

Let me know if that helps.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 03/18/15 12:46:07PM
alt=
DannyA
@dannya
9 years ago
584 posts
Great. Thanks.

Tags