コード例 #1
0
 public function addNotification(OW_Event $event)
 {
     $params = $event->getParams();
     $data = $event->getData();
     if (empty($params['entityType']) || empty($params['entityId']) || empty($params['userId']) || empty($params['pluginKey'])) {
         throw new InvalidArgumentException('`entityType`, `entityId`, `userId`, `pluginKey` are required');
     }
     if (!$this->service->isNotificationPermited($params['userId'], $params['action'])) {
         return;
     }
     $notification = $this->service->findNotification($params['entityType'], $params['entityId'], $params['userId']);
     if ($notification === null) {
         $notification = new NOTIFICATIONS_BOL_Notification();
         $notification->entityType = $params['entityType'];
         $notification->entityId = $params['entityId'];
         $notification->userId = $params['userId'];
         $notification->pluginKey = $params['pluginKey'];
         $notification->action = $params['action'];
     } else {
         $notification->viewed = 0;
         $dublicateParams = array('originalEvent' => $event, 'notificationDto' => $notification, 'oldData' => $notification->getData());
         $dublicateParams = array_merge($params, $dublicateParams);
         $dublicateEvent = new OW_Event('notifications.on_dublicate', $dublicateParams, $data);
         OW::getEventManager()->trigger($dublicateEvent);
         $data = $dublicateEvent->getData();
     }
     $notification->timeStamp = empty($params['time']) ? time() : $params['time'];
     $notification->active = isset($params['active']) ? (bool) $params['active'] : true;
     $notification->setData($data);
     $this->service->saveNotification($notification);
 }