PKPNotificationOperationManager::createNotification PHP Method

createNotification() public method

Create a new notification with the specified arguments and insert into DB
public createNotification ( $request, $userId = null, $notificationType, $contextId = null, $assocType = null, $assocId = null, $level = NOTIFICATION_LEVEL_NORMAL, $params = null, $suppressEmail = false ) : Notification
$request PKPRequest
$userId int (optional)
$notificationType int
$contextId int
$assocType int
$assocId int
$level int
$params array
$suppressEmail boolean Whether or not to suppress the notification email.
return Notification object
    public function createNotification($request, $userId = null, $notificationType, $contextId = null, $assocType = null, $assocId = null, $level = NOTIFICATION_LEVEL_NORMAL, $params = null, $suppressEmail = false)
    {
        $blockedNotifications = $this->getUserBlockedNotifications($userId, $contextId);
        if (!in_array($notificationType, $blockedNotifications)) {
            $notificationDao = DAORegistry::getDAO('NotificationDAO');
            $notification = $notificationDao->newDataObject();
            /** @var $notification Notification */
            $notification->setUserId((int) $userId);
            $notification->setType((int) $notificationType);
            $notification->setContextId((int) $contextId);
            $notification->setAssocType((int) $assocType);
            $notification->setAssocId((int) $assocId);
            $notification->setLevel((int) $level);
            $notificationId = $notificationDao->insertObject($notification);
            // Send notification emails
            if ($notification->getLevel() != NOTIFICATION_LEVEL_TRIVIAL && !$suppressEmail) {
                $notificationEmailSettings = $this->getUserBlockedNotifications($userId, $contextId);
                if (!in_array($notificationType, $notificationEmailSettings)) {
                    $this->sendNotificationEmail($request, $notification);
                }
            }
            if ($params) {
                $notificationSettingsDao = DAORegistry::getDAO('NotificationSettingsDAO');
                foreach ($params as $name => $value) {
                    $notificationSettingsDao->updateNotificationSetting($notificationId, $name, $value);
                }
            }
            return $notification;
        }
    }

Usage Example

 /**
  * Check if this manager delegate can handle the 
  * creation of the passed notification type.
  * @copydoc PKPNotificationOperationManager::createNotification()
  */
 function createNotification($request, $userId = null, $notificationType, $contextId = null, $assocType = null, $assocId = null, $level = NOTIFICATION_LEVEL_NORMAL, $params = null, $suppressEmail = false)
 {
     assert($notificationType == $this->getNotificationType() || $this->multipleTypesUpdate());
     return parent::createNotification($request, $userId, $notificationType, $contextId, $assocType, $assocId, $level, $params, $suppressEmail);
 }