Example #1
0
 /**
  * Get service message from origin.
  *
  * @param \Sly\NotificationPusher\Model\DeviceInterface $device Device
  * @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
  *
  * @return \ZendService\Apple\Apns\Message
  */
 public function getServiceMessageFromOrigin(DeviceInterface $device, BaseOptionedModel $message)
 {
     $badge = $message->hasOption('badge') ? (int) ($message->getOption('badge') + $device->getParameter('badge', 0)) : 0;
     $sound = $message->getOption('sound', 'bingbong.aiff');
     $contentAvailable = $message->getOption('content-available');
     $alert = new ServiceAlert($message->getText(), $message->getOption('actionLocKey'), $message->getOption('locKey'), $message->getOption('locArgs'), $message->getOption('launchImage'));
     if ($actionLocKey = $message->getOption('actionLocKey')) {
         $alert->setActionLocKey($actionLocKey);
     }
     if ($locKey = $message->getOption('locKey')) {
         $alert->setLocKey($locKey);
     }
     if ($locArgs = $message->getOption('locArgs')) {
         $alert->setLocArgs($locArgs);
     }
     if ($launchImage = $message->getOption('launchImage')) {
         $alert->setLaunchImage($launchImage);
     }
     $serviceMessage = new ServiceMessage();
     $serviceMessage->setId(sha1($device->getToken() . $message->getText()));
     $serviceMessage->setAlert($alert);
     $serviceMessage->setToken($device->getToken());
     $serviceMessage->setBadge($badge);
     $serviceMessage->setCustom($message->getOption('custom', array()));
     if (null !== $sound) {
         $serviceMessage->setSound($sound);
     }
     if (null !== $contentAvailable) {
         $serviceMessage->setContentAvailable($contentAvailable);
     }
     return $serviceMessage;
 }
 /**
  * @param \Sly\NotificationPusher\Model\DeviceInterface $device Device
  */
 public function add(DeviceInterface $device)
 {
     $this->coll[$device->getToken()] = $device;
 }