/**
  * Given a NotificationMessage and a NotificationRule submit and process a notification
  * @param NotificationMessage $message
  * @param NotificationRules $rules
  * @throws NotSupportedException
  */
 public static function submit(NotificationMessage $message, NotificationRules $rules)
 {
     $users = $rules->getUsers();
     if (count($users) == 0) {
         throw new NotSupportedException();
     }
     static::processNotification($message, $rules->getType(), $users, $rules->allowDuplicates(), $rules->isCritical());
 }
 /**
  * Resolve and get notifications
  * @param NotificationMessage $message
  * @param $rules
  * @throws NotSupportedException
  * @return Notification
  */
 protected static function resolveAndGetNotifications(NotificationMessage $message, NotificationRules $rules)
 {
     $notifications = array();
     foreach ($rules->getUsers() as $user) {
         //todo: !!!process duplication check
         if ($rules->allowDuplicates() || Notification::getCountByTypeAndUser($rules->getType(), $user) == 0) {
             $notification = new Notification();
             $notification->owner = $user;
             $notification->type = $rules->getType();
             $notification->notificationMessage = $message;
             $notificationSettingName = static::resolveNotificationSettingNameFromType($rules->getType());
             if (static::resolveToSaveNotification() && UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($user, $notificationSettingName, 'inbox')) {
                 $saved = $notification->save();
                 if (!$saved) {
                     throw new NotSupportedException();
                 }
             }
             $notifications[] = $notification;
         }
     }
     return $notifications;
 }