-
Notifications
You must be signed in to change notification settings - Fork 40
Integrating with extensions
To use TJ Notifications, you need to install the library along with your extension. Include the library file
jimport('techjoomla.tjnotifications.tjnotifications');
Each extension which has some default emails need to create default email templates. Extension developers can write on after install to script to save default emails. Extension developers can use the following code to save the email templates. All tjnotification email templates gets stored in #__tj_notification_templates database table.
<?php
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjnotifications/tables');
$notification = JTable::getInstance('notification');
$notification->id = null;
$notification->client = 'COM_JGIVE';
$notification->key = 'donation';
$notification->email_status = 1;
$notification->sms_status = 0;
$notification->push_status = 0;
$notification->web_status = 0;
$notification->email_body = 'Hi {donation.first_name},\r\nThe status of donation id {donation.order_id} has changed.\r\nThe new status is {donation.newStatus}.\r\n{donation.email}';
$notification->email_subject = 'Donation payment status change: Your donation id {subject.order_id}';
$notification->created_on = '2017-02-17';
$notification->updated_on = '2017-02-17';
if ($notification->check())
{
$notification->store()
}
Prepare the parameters for Tjnotifications::send()
$client
is the name of your extension, eg: com_jgive
$key
is the unique reference for the type of email within your extension. Eg: donation.thankyou, campaign.update, order.thankyou
$recipients
is an array of JUser objects
eg: $recipients = JAccess::getUsersByGroup(2);
$replacements
is an object of objects, containing all replacements. The object and their properties are mapped against the values in the template body. $replacements->order->id
maps to {order.id}
for example.
$options
is an instance of JParameter. Contains additional options that may be used by the notification provider. In case of email options may include cc, bcc, attachments, reply to, from, guestEmails etc
Finally, call Tjnotifications::send($client, $key, $recipients, $replacements, $options);
This will send the notifications based on user preferences. If the user has disabled any of the notifications or specific delivery preferences, those notifications will not be sent to the user. The 3rd party developer does not need to be aware of these settings.
This is the example of sending email from your extension. Every Extension has some methods to send an email in model file, Extension developer can refer following method to send an email from their extension.
<?php
public function save($data)
{
$client = "com_jcregister";
$key = "order";
$recipients[] = JFactory::getUser(488);
$recipients[] = JFactory::getUser(489);
$order_info->id = "236";
$order_info->amount = "500";
$order_info->status = "Pending";
$replacements->order = $order_info;
$customer_info->name = "hemant";
$customer_info->address = "";
$customer_info->zip = "411004";
$replacements->customer = $customer_info;
$options = new JParameter();
$options->set('cc', '[email protected]');
$options->set('attachment', '/var/www/html/joomla/media/attach.pdf');
$options->set('guestEmails', array("[email protected]"));
$options->set('from', "[email protected]");
$options->set('fromname', "pranoti");
Tjnotifications::send($client, $key, $recipients, $replacements, $options);
}