Display user notifications in User dashboard in oxwall

687 Views Asked by At

I am customizing Oxwall notification plugin.

I am using Oxwall 1.7.0

I am trying to display notifications in User's dashboard page.

Currently the notification showing in top right bar with name as "Notifications".

I found out which file is responsible for displaying the content.

ow_plugins/notifications/classes/console_bridge.php

I commented the below code in this file to hide the notification from top right bar.

public function collectItems( BASE_CLASS_ConsoleItemCollector $event )
{
   if ( !OW::getUser()->isAuthenticated() )
   {
      return;
   }
   /* Commented this code to hide the notification. 
   $item = new NOTIFICATIONS_CMP_ConsoleItem(); 
   $event->addItem($item, 3);
   */
}

But when we call the component in user's dashboard using the below code, It gives me error.

$widgetService = BOL_ComponentAdminService::getInstance();
$widget = $widgetService->addWidget('NOTIFICATIONS_CMP_ConsoleItem', false);
$widgetPlace = $widgetService->addWidgetToPlace($widget, BOL_ComponentService::PLACE_DASHBOARD);
$widgetService->addWidgetToPosition($widgetPlace, BOL_ComponentService::SECTION_LEFT);

Error Screenshot:Component Error

How to display the notifications in user-dashboard?

1

There are 1 best solutions below

0
On BEST ANSWER

To display user's notification in user's dashboard page, follow the below code in Widget's construct.

$this->service = NOTIFICATIONS_BOL_Service::getInstance();

$userid = OW::getUser()->getId();

$allNotificationCount = $this->service->findNotificationCount($userid); // Get the notifications of currently logged in user

$notifications = $this->service->findNotificationList($userid, time(), null, $allNotificationCount);

$notify_array = array();

$i=0;

foreach ( $notifications as $notification )
{
    if(( $notification->entityType == "groups_wal" && $notification->entityId==$groupid ) || ( $notification->entityType == "status_comment" ) )
    {

        $itemEvent = new OW_Event('notifications.on_item_render', array(
                    'key' => 'notification_' . $notification->id,
                    'entityType' => $notification->entityType,
                    'entityId' => $notification->entityId,
                    'pluginKey' => $notification->pluginKey,
                    'userId' => $notification->userId,
                    'viewed' => (bool) $notification->viewed,
                    'data' => $notification->getData()
                ), $notification->getData());

        OW::getEventManager()->trigger($itemEvent);

        $notify_array[$i] = $itemEvent->getData();

        $i++;

        if ( empty($item) )
        {
            continue;
        }
    }
}

$this->assign('item', $notify_array);

On Oxwall widget's view, add the below code

{if !empty($item)}
<div class="ow_dashboard_content">
{foreach from=$item key='key' item='v'}
    {$v}
{/foreach}
</div>
{else}
    <div class="ow_content">No Items</div>
{/if}
<div class="clearfix"></div>