Skip to content

Instantly share code, notes, and snippets.

@hatimalam
Last active February 22, 2016 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatimalam/67106480e3460ef79c7b to your computer and use it in GitHub Desktop.
Save hatimalam/67106480e3460ef79c7b to your computer and use it in GitHub Desktop.
Logic hook action method to create new Sugar Notificaiton on post or comment in Activity Stream.
<?php
/**
* Desc: Before save logic hook to create Sugar Notification if new post or comment in Activity Stream
* Written by: Hatim Alam
* Dated: 21st Feb 2016
*/
class SugarNotifyUser {
function notify_user_on_post_comment($bean, $event, $arguments) {
//if activity type is a post
if($bean->activity_type=="post") {
//get the parent bean
$parent_bean = BeanFactory::getBean($bean->parent_type, $bean->parent_id);
//initialize notification bean
$notification_bean = BeanFactory::getBean("Notifications");
//check if comment or a post
$notification_bean->name = ($bean->activity_type=="post" && $bean->comment_count==0) ? "New post on {$bean->parent_type}" : "New comment on {$bean->parent_type}";
$notification_bean->description = "New update has been posted on <a href='#{$bean->parent_type}/{$parent_bean->id}'>{$parent_bean->name}</a>";
//assigned user should be record assigned user
$notification_bean->assigned_user_id = $parent_bean->assigned_user_id;
$notification_bean->parent_id = $bean->parent_id;
$notification_bean->parent_type = $bean->parent_type;
$notification_bean->created_by = $bean->created_by;
//set is_read to no
$notification_bean->is_read = 0;
//set the level of severity
$notification_bean->severity = "information";
$notification_bean->save();
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment