Reputation: 33
The recently released SuiteCRM 7.3 has the ability to show desktop notifications and notifications on the site (in the header).
How can I add or trigger my own custom notifications through code?
Upvotes: 2
Views: 2365
Reputation: 21
You can create alert for user an example after save Leads record with the Logic Hooks
In file custom\modules\Leads\logic_hooks.php
add the following string:
$hook_array['after_save'][] = Array(2, 'send alert to user', 'custom/modules/Leads/LogicHooks/SendAlert.php','LeadHooks', 'sendAlert');
Next step, create a folder and file in it LogicHooks\SendAlert.php
in the custom\modules\Leads\LogicHooks\SendAlert.php
and add this class:
class LeadHooks{
public function sendAlert($bean,$events,$arguments){
$seedAlert = new Alert();
$seedAlert->name = "New Lead";
$seedAlert->description = "Lead assigned to yu";
$seedAlert->assigned_user_id = $bean->fetched_row['assigned_user_id'];
$seedAlert->is_read = 0 ;
$seedAlert->type = "info" ;
$seedAlert->target_module = "Leads";
$seedAlert->url_redirect = "index.php?action=DetailView&module=Leads&record=".$bean>fetched_row['id']."&return_module=Leads&return_action=DetailView";
$seedAlert->save();
}
}
Its all for the rest modules, you should do the same.
Upvotes: 2
Reputation: 22656
I haven't tested this but you should be able to simply save a new Alert bean.
I.e.
$alert = BeanFactory::newBean('Alerts');
$alert->name = 'My Alert';
$alert->description = 'This is my alert!';
$alert->url_redirect = 'index.php';
$alert->target_module = 'Accounts';
$alert->assigned_user_id = '1';
$alert->type = 'info';
$alert->is_read = 0;
$alert->save();
The action_add
method in modules/Alerts/controller.php
provides an example.
Upvotes: 4