Ebenezer Obasi

Web Application and Software Developer

How do you send user site notification when an action is performed?

QuestionsCategory: Oxwall PluginsHow do you send user site notification when an action is performed?
Marcus asked 3 years ago

I’m developing a Job Oxwall plugin for my website and I want users to get a notification when their application for a job has been accepted. I’m aware there is a notification plugin but not sure how to hook my plugin to it. I would appreciate any help I can get.

Post Tags:

  • https://www eobasi com/questions/how-do-you-send-user-notification-when-an-action-is-performed/
1 Answers
Ebenezer Obasi Staff answered 3 years ago

The notifications.add event allows you to add notifications to the Oxwall Notification plugin. However, you might also have to queue your job notification for email notifications. Your job notification will be uniquely identified by your pluginKey and entityType.

Setup Email Notification Actions for Oxwall Notification plugin

Create a method in your event handler file or function in init.php file and bind it to notifications.collect_actions event. if you working with an object, your method should look like this:

    public function onNotifyActions( BASE_CLASS_EventCollector $event )
            ‘section’ => ‘custom_plugin_key’,
            ‘action’ => ‘custom_plugin_key_job_notification’,
            ‘description’ => OW::getLanguage()->text(‘custom_plugin_key’, ’email_notifications_setting_schedule’),
            ‘selected’ => true,
            ‘sectionLabel’ => OW::getLanguage()->text(‘custom_plugin_key’, ‘notification_section_label’),
            ‘sectionIcon’ => ‘ow_ic_add’

Where custom_plugin_key is your plugin key. You will need to bind the onNotifyActions method you just created to the notifications.collect_actions event.

OW::getEventManager()->bind(‘notifications.collect_actions’, array($this, ‘onNotifyActions’));

Add Notifications to Oxwall Notification Plugin

This will allow you to add notifications that can be accessed a recipient click the notification icon. Trigger the notifications.add event from your job controller action.

$event = new OW_Event(‘notifications.add’, array $params, array $data);

Arguments for $params includes:

  • pluginKey: Your plugin key.
  • entityType: Unique entity type
  • entityId: Item for which action is performed on
  • action: Notification action key.
  • userId: User who should receive notification.
  • time: Time

Arguments for $data includes:

  • avatar: Item picture or blank.
  • string: Language string for plugin.
    • key: Language key.
    • vars: Language key variables.
  • content: Notification content.
  • url: Notification URL. Direct user to a page when they click on the notification.

Plugin Example of Adding Notification to Oxwall Notification Plugin

$avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($item->owner_id));

$params = array(
        ‘pluginKey’ => ‘custom_plugin_key’,
        ‘entityType’ => ‘custom_plugin_key_job_application’,
        ‘entityId’ => $itemId,
        ‘action’ => ‘custom_plugin_key_job_notification’,
        ‘userId’ => $receipientUserId,
        ‘time’ => time()

$data = array(
        ‘avatar’ => $avatars[$item->owner_id],
        ‘string’ => array(
              ‘key’ => ‘custom_plugin_key+application_notifications_create’,
              ‘vars’ =>array(
                    ‘itemTitle’ => $item->title,
                    ‘itemUrl’ => OW::getRouter()->urlForRoute(‘custom_plugin_key_notify_item’, array(‘itemId’ =>$item->id)),
        ‘content’ => ”,
        ‘url’ => OW::getRouter()->urlForRoute(‘custom_plugin_key_notify_item’, array(‘itemId’ =>$item->id))
$event = newOW_Event(‘notifications.add’, $params, $data);