The Techjoomla Blog

Stay updated with all the latest happenings at Techjoomla. From news about the developments in your favourite extensions to Tips & Tricks about the Joomla CMS, Framework & Development.
Font size: +
2 minutes reading time (350 words)

Avoid sending Emails while using JomSocial Notifications

Avoid-sending-Emails-while-using-Jomsocial-Notifications

This Blog is specially targeted for developers and people who use Jomsocial

b2ap3_thumbnail_download_20140710-115328_1.jpg

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


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.

b2ap3_thumbnail_js_notification.png 

Code: 

 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! :) 

1
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

3 ways to do RESTful APIs in Joomla
Avail 40% discount on Themexpert’s products on the...

Related Posts

 

Blog Topics