在 oxwall 的用户仪表板中显示用户通知
Display user notifications in User dashboard in oxwall
我正在定制 Oxwall 通知插件。
我正在使用 Oxwall 1.7.0
我正在尝试在用户的仪表板页面中显示通知。
当前显示在右上角栏中的通知名称为 "Notifications"。
我找到了负责显示内容的文件。
ow_plugins/notifications/classes/console_bridge.php
我在这个文件中注释了下面的代码来隐藏右上角栏的通知。
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);
*/
}
但是当我们使用下面的代码调用用户仪表板中的组件时,它会报错。
$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);
错误截图:
如何在用户仪表板中显示通知?
要在用户的仪表板页面中显示用户的通知,请在 Widget 的构造中遵循以下代码。
$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);
在 Oxwall 小部件的视图中,添加以下代码
{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>
我正在定制 Oxwall 通知插件。
我正在使用 Oxwall 1.7.0
我正在尝试在用户的仪表板页面中显示通知。
当前显示在右上角栏中的通知名称为 "Notifications"。
我找到了负责显示内容的文件。
ow_plugins/notifications/classes/console_bridge.php
我在这个文件中注释了下面的代码来隐藏右上角栏的通知。
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);
*/
}
但是当我们使用下面的代码调用用户仪表板中的组件时,它会报错。
$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);
错误截图:
如何在用户仪表板中显示通知?
要在用户的仪表板页面中显示用户的通知,请在 Widget 的构造中遵循以下代码。
$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);
在 Oxwall 小部件的视图中,添加以下代码
{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>