New or Updated comment notification template for Requester
In the following example, we are going to configure an email template to notify a user that a comment has been added or updated where he is the Requester.
STEP 1 – TEMPLATE IDENTIFICATION FIELDS
As a first step, fill in the template identificative fields:
- Name (es: ‘REQUESTER – Comment Created or Updated ’)
- Code (es: ‘operation_comment_created_updated_requester’)
- Status: Enabled
STEP 2 – CONFIGURE THE EMAIL SUBJECT LINE
In the scripting area ‘Subject‘ insert the following PHP code
getModel()->isObjectNew()) : ?>
__('New Comment')?>
__('Comment Updated')?>
__('for Ticket ID')?>
getPrefix() ?>getModel()->getModelId() ?>
The resulting subject will look like: “New Comment for Ticket ID TICKET#101” or “Comment Updated for Ticket ID TICKET#”.
STEP 3 – CONFIGURE THE EMAIL BODY
In the Body scripting area enter the following PHP code
getModel() returns the main model oject instance, in this case Activity
$activity = $this->getModel();
//retreive user who created comment
$createdByUser = $activity->getCreatedBy() ?
Deep::getModel('deep_admin/user')->loadByUsername($activity->getCreatedBy()) : null;
//determine createdby user display username
$createdByDisplayUsername = $createdByUser && $createdByUser->getId() ?
$createdByUser->getDisplayUsername() : $activity->getCreatedBy();
//$activity->loadModelInstance() returns main model instance in this case operation object instance
$operation = $activity->loadModelInstance();
//getAssignedUser() returns assigned user object instance
$assignedUser = $operation ? $operation->getAssignedUser() : null;
//getDisplayUsername() returns "First Lastname" string
$assignedUsername = $assignedUser && $assignedUser->getId() ? $assignedUser->getDisplayUsername() : null;
//$operation->getRequesterUser() loads the requester user object if he is registered
$requesterUser = $operation ? $operation->getRequesterUser() : null;
//test if requester is a registered user
$requesterIsRegistered = $requesterUser && $requesterUser->getId();
//if requester is registered then use getDisplayUsername() that returns 'Firstname Lastname'
//if the requester is not a registered user use the value of the service operation field requester_username
$requesterUsername = $requesterIsRegistered ? $requesterUser->getDisplayUsername() : $operation->getRequesterUsername();
?>
includeTemplate("header") ?>
__('Dear') .' ' . $requesterUsername ?>,
__('A Comment has been') .' ' ?>
isObjectNew()) : ?>
__('created') . ' '?>
__('updated') . ' '?>
__('for Ticket ID') ?>:
getPortalUrl() ?>
getId()?>
getId()?>
__('Ticket Title')?>:
getTitle()?>
__('Comment')?>:
getDescription()?>
__('User who created the Comment')?>:
getId()):?>
getAvatar()):?>
__('Go to the Ticket')?>
includeTemplate("footer") ?>
The notification email body will look like the image below.