By accepting you will be accessing a service provided by a third-party external to https://techjoomla.com/
This Blog is specially targeted for developers and people who use Jomsocial
Jomsocial! Which turns Joomla CMS into a full-fledged social
networking website. While using your own component with Jomsocial you need to make sure that your component is tightly integrated with it and most important is you are notified of the activities happening.
In Jomsocial, notifications are shown on the notification bar and if you use the following code provided by Jomsocial you’ll get email notifications as well. Use Jomsocial’s Notifications API, to send notifications to users we write following code
require_once JPATH_ROOT .'/components/com_community/libraries/core.php'; $user = CFactory::getUser(); $cmd = 'system_messaging'; // first param, type of activity $actor = $user->id; //second param - get the id of $actor $target = '965'; // third param. Who receive notification? In our dev environment, its admin user with id 965. At your environment, you will most likely want to get the ID from your object or from array of users. $subject = 'Notification Subject'; // Subject of both, email and popup notifications $body = 'This is the notification body message'; //Body message in emails. $template = ''; // If you need to use specific jomsocial template file, you can define it here. $params = new CParameter(''); // We want to create an additional params object, and assign data to it, without having to formally define a class CNotificationLibrary::add( $cmd , $actor , $target , $subject , $body , $template , $params );
Using above code the target User receives both notification and Email about the activity.
However, in some cases, people only want notifications on the JomSocial notification bar and not in emails.
Jomsocial has given settings for Default User Email & Notifications where we can set if we want to send Emails or not. But this setting will affect all the Notifications and Emails of that specific type.
If you don't want this and avoid sending Email, you just have to use the following code using Jomsocial’s Notifications API which will stop sending email notifications.
require_once JPATH_ROOT .'/components/com_community/libraries/core.php'; $notification_subject= 'Notification Subject'; // Subject of notification $model = CFactory::getModel('Notification'); $model->add($actor->id ,$target ,$notification_subject,'notif_system_messaging','0','');
Hope this helps! :)