Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save betobaz/d3557ed54afb8851d285 to your computer and use it in GitHub Desktop.
Save betobaz/d3557ed54afb8851d285 to your computer and use it in GitHub Desktop.
SugarCRM Notifications like facebook
<?php
class ActivitiesLogicHookCustom{
public function notifyActivity($bean, $event, $arguments){
if($bean->module_name == 'Activities'){
global $current_user;
$data = json_decode($bean->data);
$message = preg_replace('/(\@)\[\w+\:[a-f0-9-]{36}\:([\w ]+)\]/u', '$1$2', $data->value);
foreach($data->tags as $tag){
if($tag->module == 'Users'){
$notification = BeanFactory::newBean('Notifications');
$notification->name = $current_user->user_name . ' mentioned you in an activity';
$notification->description = $message;
$notification->assigned_user_id = $tag->id;
$notification->save();
}
}
}
}
}
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1,'Notify activity','custom/modules/Activities/ActivitiesLogicHookCustom.php','ActivitiesLogicHookCustom','notifyActivity',);
@bickart
Copy link

bickart commented Mar 26, 2015

You should move your custom_modules_logic_hooks.php to
custom/Extension/modules/Activities/Ext/LogicHooks/notify.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment