Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Api\Model\Events\Point;
- use Api\Model\Business\Payment\UserBO;
- use Api\Model\Entity\Geo\Agroclimapro\Point;
- use Api\Model\Entity\Payment\Subscription;
- use Api\Model\Repository\Tvs\UserRepository;
- use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
- class NotifyMobileUsersEvent
- {
- public function postUpdate(Point $point, LifecycleEventArgs $args, UserRepository $repository, FirebaseNotification $notification)
- {
- $subscription = $point->getSubscription();
- $user = $repository->find($subscription->getUserId());
- $user->getDeviceToken();
- if ($user->getDeviceToken()) {
- $notification->send($user->getDeviceToken(), 'POINT', $point);
- }
- }
- }
- class FirebaseNotification {
- public function send($deviceToken, $type, $data, $message = null) {
- $messaging = (new Firebase\Factory())->createMessaging();
- $message = CloudMessage::withTarget('token', $deviceToken)
- ->withNotification(Notification::create('Agroclima Pro',
- $message ?? 'Seus pontos foram atualizados. Toque aqui para abrir o app.'))
- ->withData([
- 'type' => $type,
- 'data' => $data
- ]);
- $messaging->send($message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement