Skip to content

Integrating with extensions

Ashwin Date edited this page Feb 17, 2017 · 20 revisions

Include the library in your code

To use TJ Notifications, you need to install the library along with your extension.. Include the library file jimport('techjoomla.tjnotifications.tjnotifications');

Install your notification templates

The magic method Tjnotifications::send()

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.

Example Usage

<?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);	 
}
Clone this wiki locally