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

<!-- 
    $this->getModel() returns the current model incance in this case the activity instance
    $this->getModel()->isObjectNew() returns true if object is new
    if object is new print "New Comment" else Comment Updated
    __ method (double underscore) check for available translations of the string passed as parameter
-->
<?php if ($this->getModel()->isObjectNew()) : ?>
    <?php echo Deep::helper('deep_email')->__('New Comment')?>
<?php else: ?>
    <?php echo Deep::helper('deep_email')->__('Comment Updated')?>
<?php endif; ?>
 <?php echo Deep::helper('deep_email')->__('for Ticket ID')?> 
<!--    
    $this->getPrefix() retrieve the prefix setted in current outgoing mailbox configuration 
    $this->getModel()->getModelId() retrive the main model ID to which the activity is associated
        in this case the operation ID
-->
 <?php echo $this->getPrefix() ?><?php echo $this->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

<?php
//$this->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();
?>

<!-- include header template -->
<?php $this->includeTemplate("header") ?>
<!-- Start of Main Content -->
<tr style="">
    <td bgcolor="#FFFFFF" align="center" style="">
        <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0" class="devicewidth"
            style="">
            <tbody style="">
            <!-- Start Spacer -->
            <tr>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="h26" height="36" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
            </tr>
            <!-- End Spacer -->
            <tr style="">
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="mktEditable content mktEditable content" id="edit_text_1" valign="middle"
                    style="font-family:Calibri, Helvetica, sans-serif; font-size:16px; color:#505050;
                    text-align:left; line-height:25.6px; font-weight:normal; text-transform:none;">
                    <p>
                        <br>
                        <?php echo Deep::helper('deep_email')->__('Dear') .' ' . $requesterUsername ?>,
                        <br>

                        <?php echo Deep::helper('deep_email')->__('A Comment has been') .' ' ?>
                        <b>
                        <?php if ($activity->isObjectNew()) : ?>
                            <?php echo Deep::helper('deep_email')->__('created') . ' '?>
                        <?php else: ?>
                            <?php echo Deep::helper('deep_email')->__('updated') . ' '?>
                        <?php endif; ?>
                        </b>
                        <?php echo Deep::helper('deep_email')->__('for Ticket ID') ?>:
                        <b style="font-weight: 700;">
                            <?php if($requesterIsRegistered):?>
                                <?php $url = $operation->getPortalUrl() ?>
                                <a href="<?php echo $url ?>">
                                    <?php echo $operation->getId()?>
                                </a>
                            <?php else:?>
                                <?php echo $operation->getId()?>
                            <?php endif;?>
                        </b>
                        <br><br>

                        <!-- Ticket Title -->
                        <strong><?php echo Deep::helper('deep_email')->__('Ticket Title')?></strong>:
                        <br>
                        <!-- print the operation Title -->
                        <?php echo $operation->getTitle()?>
                        <br><br><br>

                        <!-- Activity Description -->
                        <strong><?php echo Deep::helper('deep_email')->__('Comment')?></strong>:
                        <!-- print the activtity Description -->
                        <br><?php echo $activity->getDescription()?>
                        <br>

                        <!-- Created by -->
                        <strong><?php echo Deep::helper('deep_service')
                            ->__('User who created the Comment')?></strong>:
                        <?php if($createdByUser && $createdByUser->getId()):?>
                       <?php if($createdByUser->getAvatar()):?>
                           <br>
                           <!-- if created by user is regitered and has an avatar print it -->
                           <img src="<?php echo $createdByUser->getAvatarUrl() ?>" border="0"
                               style="-ms-interpolation-mode: bicubic;" width="16" />
                            <?php endif;?>
                        <?php endif;?>
                        <!-- print created by username or displayusername -->
                        &nbsp;&nbsp;&nbsp;<?php echo $createdByDisplayUsername ?>
                        <br><br>
                    </p>
                </td>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
            </tr>
            <!-- Start Spacer -->
            <tr>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td height="30" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
            </tr>
            <!-- End Spacer -->
            </tbody>
        </table>
    </td>
</tr>
<!-- End of Main Content -->

<?php if($requesterIsRegistered):?>
<!-- start of Button -->
<tr style="">
    <td bgcolor="#FFFFFF" align="center" class="mktEditable" id="edit_cta_button" style="">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tbody>
            <tr>
                <td class="w22" width="41" style="font-size: 1px; line-height: 1px;">&nbsp;</td>
                <td align="left">
                    <table class="button" cellpadding="0" cellspacing="0" border="0" align="left"
                        bgcolor="#0080ff" style="-webkit-border-radius: 4px; -moz-border-radius: 4px;
                        border-radius: 4px;">
                        <tbody>
                        <tr>
                            <td width="518" align="center" valign="middle" height="65">
                                <span style="color: #ffffff; text-decoration: none;">
                                    <!-- set the operation link as button link -->
                                    <a class="mobButton mktNoTok" href="<?php echo $url ?>"
                                        style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px;
                                        color: #ffffff; display: block; height: 65px;
                                        mso-line-height-rule: exactly; line-height: 65px;
                                        font-weight: normal; text-decoration: none;
                                        text-align: center!important;" target="_blank"
                                        title="Link to the ticket">
                                        <?php echo Deep::helper('deep_email')->__('Go to the Ticket')?>
                                    </a>
                        </span>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                   </td>
                <td class="w22" width="41" style="font-size: 1px; line-height: 1px;">&nbsp;</td>
            </tr>
            </tbody>
        </table>
    </td>
</tr>
<!-- end of Button -->
<?php endif;?>

<!-- include footer template -->
<?php $this->includeTemplate("footer") ?>

The notification email body will look like the image below.