/**
  * @param Request $request
  * @param Notification $notification
  * @return array
  *
  * @Route("/broadcast/copy/{id}", name="cto_notification_broadcastCopy")
  * @Method({"GET", "POST"})
  * @Template("@CTOApp/DashboardControllers/CTO/Notifications/broadcast.html.twig")
  */
 public function broadcastCopyAction(Request $request, Notification $notification)
 {
     /** @var CtoUser $admin */
     $admin = $this->getUser();
     $newNotification = new Notification();
     $newNotification->setStatus(Notification::STATUS_SEND_IN_PROGRESS)->setAdminCopy($notification->isAdminCopy())->setAutoSending($notification->isAutoSending())->setWhenSend($notification->getWhenSend())->setBroadcastTo($notification->getBroadcastTo())->setType(Notification::TYPE_BROADCAST)->setUserCto($admin)->setDescription($notification->getDescription());
     $form = $this->createForm(new BroadcastType(), $newNotification);
     if ($request->getMethod() == Request::METHOD_POST) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $now = Carbon::now();
             if ($notification->getWhenSend() < $now) {
                 if ($notification->isAutoSending() and $notification->isSendNow()) {
                     $notification->setAutoSending(true);
                 } else {
                     $notification->setAutoSending(false);
                 }
             }
             /** @var EntityManager $em */
             $em = $this->getDoctrine()->getManager();
             $em->persist($newNotification);
             $em->flush();
             if ($notification->isAutoSending()) {
                 $senderSrv = $this->get('cto.sms.sender');
                 if ($notification->isSendNow()) {
                     $senderSrv->getResqueManager()->put('cto.sms.sender', ['notificationId' => $newNotification->getId(), 'broadcast' => true]);
                 } else {
                     $jobDescription = $senderSrv->getResqueManager()->put('cto.sms.sender', ['notificationId' => $newNotification->getId(), 'broadcast' => true], $this->getParameter('queue_name'), $newNotification->getWhenSend());
                     $newNotification->setResqueJobDescription($jobDescription);
                 }
             }
             $em->flush();
             $this->addFlash('success', 'Нагадування успішно створено.');
             return $this->redirectToRoute('cto_notification_home');
         }
     }
     return ['form' => $form->createView(), 'method' => 'Копіювати'];
 }
Esempio n. 2
0
 public function sendNow(Notification $notification, CtoUser $admin, $broadcast = false)
 {
     if ($broadcast) {
         //   Broadcast
         $iDs = explode(',', $notification->getBroadcastTo());
         if (in_array('-1', $iDs)) {
             $admin = $notification->getUserCto();
             $users = $this->em->getRepository('CTOAppBundle:CtoClient')->clientFilter([], $admin);
             $notification->setBroadcastTo(-1);
         } else {
             $users = $this->em->getRepository('CTOAppBundle:CtoClient')->findBy(['id' => $iDs]);
         }
         /** @var CtoClient $user */
         foreach ($users as $user) {
             try {
                 $this->clientSMS->sendSMS($this->alfa_sms_name, '+38' . $user->getPhone(), $notification->getDescription());
                 $report = new NotificationReport($user);
                 $report->setPhone($user->getPhone())->setStatus(NotificationReport::REPORT_STATUS_SENDED);
                 $this->em->persist($report);
                 $notification->addReport($report);
                 $notification->setStatus(Notification::STATUS_SEND_OK);
             } catch (\Exception $e) {
                 $report = new NotificationReport($user);
                 $report->setPhone($user->getPhone())->setStatus(NotificationReport::REPORT_STATUS_FAILED);
                 $this->em->persist($report);
                 $notification->addReport($report);
                 $notification->setStatus(Notification::STATUS_SEND_FAIL);
             }
         }
         if ($notification->isAdminCopy()) {
             try {
                 $this->clientSMS->sendSMS($this->alfa_sms_name, '+38' . $admin->getPhone(), $notification->getDescription());
                 $report = new NotificationReport($notification->getClientCto());
                 $report->setPhone($admin->getPhone())->setStatus(NotificationReport::REPORT_STATUS_SENDED);
                 $this->em->persist($report);
                 $notification->addReport($report);
             } catch (\Exception $e) {
                 $report = new NotificationReport($notification->getClientCto());
                 $report->setPhone($admin->getPhone())->setSendToAdmin(true)->setStatus(NotificationReport::REPORT_STATUS_SENDED);
                 $this->em->persist($report);
             }
         }
         $this->em->flush();
     } else {
         //  Normal
         try {
             $this->clientSMS->sendSMS($this->alfa_sms_name, '+38' . $notification->getClientCto()->getPhone(), $notification->getDescription());
             $report = new NotificationReport($notification->getClientCto());
             $report->setPhone($notification->getClientCto()->getPhone())->setStatus(NotificationReport::REPORT_STATUS_SENDED);
             $this->em->persist($report);
             $notification->addReport($report);
             $notification->setStatus(Notification::STATUS_SEND_OK);
         } catch (\Exception $e) {
             $report = new NotificationReport($notification->getClientCto());
             $report->setPhone($notification->getClientCto()->getPhone())->setStatus(NotificationReport::REPORT_STATUS_FAILED);
             $this->em->persist($report);
             $notification->addReport($report);
             $notification->setStatus(Notification::STATUS_SEND_FAIL);
         }
         if ($notification->isAdminCopy()) {
             try {
                 $this->clientSMS->sendSMS($this->alfa_sms_name, '+38' . $admin->getPhone(), $notification->getDescription());
                 $report = new NotificationReport($notification->getClientCto());
                 $report->setPhone($admin->getPhone())->setSendToAdmin(true)->setStatus(NotificationReport::REPORT_STATUS_SENDED);
                 $this->em->persist($report);
                 $notification->addReport($report);
             } catch (\Exception $e) {
                 $report = new NotificationReport($notification->getClientCto());
                 $report->setPhone($admin->getPhone())->setSendToAdmin(true)->setStatus(NotificationReport::REPORT_STATUS_FAILED);
                 $this->em->persist($report);
             }
         }
         $this->em->flush();
     }
 }
Esempio n. 3
0
 /**
  * @param CarJob $carJob
  * @param Recommendation $recommendation
  * @param Request $request
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  *
  * @Route("/{jobId}/recommendation/{recommendId}", name="cto_jobs_addRecomendation", requirements={"jobId"="\d+"})
  * @Method({"GET", "POST"})
  * @ParamConverter("carJob", class="CTOAppBundle:CarJob", options={"id"="jobId"})
  * @ParamConverter("recommendation", class="CTOAppBundle:Recommendation", options={"id"="recommendId"})
  * @Template("@CTOApp/DashboardControllers/CTO/Jobs/addReminder.html.twig")
  */
 public function addRecommendationAction(CarJob $carJob, Recommendation $recommendation, Request $request)
 {
     /** @var CtoUser $admin */
     $admin = $this->getUser();
     $notification = new Notification();
     $notification->setType(Notification::TYPE_RECOMMENDATION)->setStatus(Notification::STATUS_SEND_IN_PROGRESS)->setDescription($recommendation->getTitle())->setCarJob($carJob)->setUserCto($admin)->setClientCto($carJob->getClient());
     $form = $this->createForm(new JobNotificationReminderType(), $notification);
     if ($request->getMethod() == Request::METHOD_POST) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $now = Carbon::now();
             if ($notification->getWhenSend() < $now) {
                 $notification->setAutoSending(false);
             }
             /** @var EntityManager $em */
             $em = $this->getDoctrine()->getManager();
             $em->persist($notification);
             $em->flush();
             if ($notification->isAutoSending()) {
                 $senderSrv = $this->get('cto.sms.sender');
                 if ($notification->isSendNow()) {
                     $senderSrv->sendNow($notification, $admin);
                 } else {
                     $jobDescription = $senderSrv->getResqueManager()->put('cto.sms.sender', ['notificationId' => $notification->getId(), 'broadcast' => false], $this->getParameter('queue_name'), $notification->getWhenSend());
                     $notification->setResqueJobDescription($jobDescription);
                 }
             }
             $em->flush();
             $this->addFlash('success', 'Рекомендація успішно створена.');
             return $this->redirectToRoute('cto_jobs_show', ['id' => $carJob->getId()]);
         }
     }
     return ['client' => $carJob->getClient()->getFullName(), 'jobId' => $carJob->getId(), 'type' => 'рекомендацію', 'form' => $form->createView()];
 }
Esempio n. 4
0
 /**
  * @param Notification $notification
  * @return CtoClient
  */
 public function addNotification(Notification $notification)
 {
     $notification->setClientCto($this);
     $this->notifications->add($notification);
     return $this;
 }
Esempio n. 5
0
 /**
  * @param Notification $notification
  * @return JsonResponse
  *
  * @Route("/cto/ajax/report/{id}/show", name="ajax_cto_getReports", options={"expose" = true})
  * @Method("POST")
  */
 public function showRepostAction(Notification $notification)
 {
     return new JsonResponse(["reports" => $notification->getReports()->getValues()]);
 }