/** * @param EventArgs|LifecycleEventArgs $args */ public function postPersist(LifecycleEventArgs $args) { $entity = $args->getObject(); $em = $args->getObjectManager(); if ($entity instanceof Comment) { if ($entity->getArticleId() != null) { if ($entity->getUserId()->getId() != $entity->getArticleId()->getUserId()->getId()) { $n = new Notification(); $n->setUser($entity->getUserId())->setArticle($entity->getArticleId()); $em->persist($n); $em->flush(); } } else { if ($entity->getVideoId() != null) { if ($entity->getUserId()->getId() != $entity->getVideoId()->getUserId()->getId()) { $n = new Notification(); $n->setUser($entity->getUserId())->setVideo($entity->getVideoId()); $em->persist($n); $em->flush(); } } else { if ($entity->getLinkId() != null) { if ($entity->getUserId()->getId() != $entity->getLinkId()->getUserId()->getId()) { $n = new Notification(); $n->setUser($entity->getUserId())->setLink($entity->getLinkId()); $em->persist($n); $em->flush(); } } } } } }
public function addNewNotification() { $manager = $this->em; $notification = new Notification(); $notification->setSubject($this->subject); $notification->setBody($this->body); $notification->setUser($this->user); $manager->persist($notification); $manager->flush(); return new Response('notification id ' . $notification->getId() . ' successfully created'); }
/** * @param Request $request * @param $webHook * * @return array */ private function handleNotification(Request $request, $webHook) { $em = $this->get('doctrine.orm.default_entity_manager'); $notification = new Notification(); $notification->setWebHook($webHook); $requestData = ['method' => $request->getMethod(), 'headers' => $request->headers->all(), 'query' => $request->query->all(), 'body' => $request->getContent()]; $notification->setContent(json_encode($requestData)); $em->persist($notification); $em->flush(); return $requestData; }
public function replay(Request $baseRequest, Notification $notification) { $webHook = $notification->getWebHook(); $endpoint = $webHook->getEndpoint(); $content = json_decode($notification->getContent(), true); $query = array_merge(['username' => $webHook->getUser()->getUsername(), 'endpoint' => $endpoint], $content['query']); $url = $this->router->generate('notifications', $query); $request = Request::create($url, $content['method'], [], [], [], $baseRequest->server->all(), $content['body']); $request->headers->replace($content['headers']); $response = $this->kernel->handle($request, HttpKernelInterface::SUB_REQUEST); return $response; }
public function createLivestreamNotifications(Series $series) { $notifications = []; $mails = []; foreach ($series->getAbonnements() as $abonnement) { if ($abonnement->getLivestream()) { $notification = new Notification(); $notification->setUser($abonnement->getUser()); $notification->setSeries($series); $notification->setType(Notification::LIVESTREAM); $notifications[] = $notification; if ($abonnement->getSendMails()) { $mails[] = $notification; } } } $this->sendMails(Notification::LIVESTREAM, $mails); $this->saveNotifications($notifications); }
/** * @Route("/sendEventsCurlPost", name="send_events_curl_post") * @Method("POST") */ public function sendEventsCurlAction(Request $request) { //$events = $request->request->get('event_check_list'); $em = $this->getDoctrine()->getManager(); $qb = $em->createQueryBuilder(); $qb->select('m'); $qb->from('AppBundle:Event', 'm'); //$qb->where($qb->expr()->in('m.id', $events)); //ArrayCollection $result = $qb->getQuery()->getResult(); $events = array(); //$serializer = $this->container->get('jms_serializer'); // $Devices = $em->getRepository('AppBundle:Device')->findAll(); $devicesTokens = ""; foreach ($Devices as $key => $value) { $devicesTokens = $devicesTokens . ',' . $Devices[$key]->getDeviceToken(); } $devicesTokens = substr($devicesTokens, 1); foreach ($result as $key => $value) { //$events [$key] =json_encode(array_values((array) $value),JSON_FORCE_OBJECT); $events[$key] = $value; //$events [$key] =json_encode($serializer->serialize($value, 'json'),JSON_FORCE_OBJECT); } $devicesTokens = str_replace(',', '","', $devicesTokens); $notification = new Notification(); $notification->setTitle($request->request->get('title')); $notification->setMessage($request->request->get('message')); $notification->setDate(); $em = $this->getDoctrine()->getManager(); $em->persist($notification); $em->flush(); $cmd = ' curl -u 485d490dd0720a823c518fb6d39d73623ddff1f0487764a4: -H "Content-Type: application/json" -H "X-Ionic-Application-Id: 9cea62b6" https://push.ionic.io/api/v1/push -d \'{"tokens": ["' . $devicesTokens . '"],"production": false, "notification":{ "alert":"' . $request->request->get('message') . '", "title": "' . $request->request->get('title') . '","android": {"payload":""}, "ios": {"payload": ""}}}\' '; exec($cmd); // echo $cmd; // die; $notifications = $em->getRepository('AppBundle:Notification')->find($notification->getId()); $serializer = $this->container->get('serializer'); $reports = $serializer->serialize($notifications, 'json'); return new Response($reports); }
/** * Sends a notification through socket.io * * @param Notification $notification * @param string $actionUrl * @return void */ private function sendNotification($notification, $actionUrl = null) { $data = array('id' => (string) $notification->getId(), 'title' => $notification->getTitle(), 'content' => $notification->getContent(), 'actionCaption' => $notification->getActionCaption(), 'actionUrl' => $actionUrl); $socketClient = $this->get('elephantio_client.ainotifier'); $socketClient->send('new', ['notification' => json_encode($data)]); }
public function sendEmail(Notification $notification) { $fromCircles = $this->dataService->getDataCircles($notification->getRevisionId()); $toCircles = array_unique(array_merge($fromCircles, $notification->getTemplateId()->getCirclesTo())); $fromUser = $this->usersToEmailAddresses([$this->userService->getUser($notification->getUsername())]); $toUsers = $this->usersToEmailAddresses($this->userService->getUsersForRoleAndCircles($notification->getTemplateId()->getRoleTo(), $toCircles)); $ccUsers = $this->usersToEmailAddresses($this->userService->getUsersForRoleAndCircles($notification->getTemplateId()->getRoleCc(), $toCircles)); $message = \Swift_Message::newInstance(); $params = ['notification' => $notification, 'source' => $notification->getRevisionId()->getRawData(), 'object' => $notification->getRevisionId()->buildObject(), 'status' => $notification->getStatus(), 'environment' => $notification->getEnvironmentId()]; if ($notification->getStatus() == 'pending') { //it's a notification try { $body = $this->twig->createTemplate($notification->getTemplateId()->getBody())->render($params); } catch (\Exception $e) { $body = "Error in body template: " . $e->getMessage(); } $message->setSubject($notification->getTemplateId() . ' for ' . $notification->getRevisionId())->setFrom($this->sender['address'], $this->sender['sender_name'])->setTo($toUsers)->setCc(array_unique(array_merge($ccUsers, $fromUser)))->setBody($body, empty($notification->getTemplateId()->getEmailContentType()) ? 'text/html' : $notification->getTemplateId()->getEmailContentType()); $notification->setEmailed(new \DateTime()); } else { //it's a notification try { $body = $this->twig->createTemplate($notification->getTemplateId()->getResponseTemplate())->render($params); } catch (\Exception $e) { $body = "Error in response template: " . $e->getMessage(); } //it's a reminder $message->setSubject($notification->getTemplateId() . ' for ' . $notification->getRevisionId() . ' has been ' . $notification->getStatus())->setFrom($this->sender['address'], $this->sender['sender_name'])->setTo($fromUser)->setCc(array_unique(array_merge($ccUsers, $toUsers)))->setBody($body, 'text/html'); $notification->setResponseEmailed(new \DateTime()); } if (!$this->dryRun) { $em = $this->doctrine->getManager(); try { /**@Swift_Mailer $mailer*/ $mailer = $this->container->get('mailer'); $mailer->send($message); $em->persist($notification); $em->flush(); } catch (\Swift_TransportException $e) { } } }
/** * @param Notification $notification */ public function seeNotification(Notification $notification) { $notification->setSeen(1); $this->_em->persist($notification); $this->_em->flush(); }
/** * Add notifications * * @param \AppBundle\Entity\Notification $notifications * @return User */ public function addNotification(Notification $notification) { $this->notifications[] = $notification; $notification->setUser($this); return $this; }